LVS + Ultra Monkey で負荷分散 (設定編)

ライブドアテクノロジーセミナーに行ってきましたよ。

id:naoyaさんは LVS++という話 でしたが、自分も 1年ほど前に、某サイトの負荷分散を LVS + Ultra Monkey (heartbeat + ldrectord) でやったので、社内 Wiki に書いてたメモを晒しておきます。
# 今なら heartbeat じゃなくて keepalived が普通なのかも知れず、情報が古めの可能性はあります

  • LVS の Director を 2台で HA 兼 Real Server (httpd)
  • + Real Server 1台 (httpd)
  • DB Server 1台

という構成。
LVS と Real Server を別にするのはちょっとコスト的にもったいなかったため、Director と Real Server を同一マシンに乗せる形に。http://ultramonkey.jp/2.0.1/topologies/sl-ha-lb-eg.html の形態。

帰りのパケットは Director を経由せず、直接クライアントに帰るいわゆる DSR です。

# 以下、IPアドレス、ホスト名は実際とは変えてあります。

                        www   
                   192.168.0.10(VIP)
          www1      |           |   www2                   www3  
 +----192.168.0.7-----+   +-----192.168.0.8----+  +-----192.168.0.9----+
 |  Director (active) |   | Director (standby) |  |        httpd       |
 |      httpd         |   |      httpd         |  +--------------------+
 +--------------------+   +--------------------+

               +-----192.168.0.11-----+
               |       PostgreSQL     |
               +----------------------+

OS は CentOS-4 (kernel-2.6.9)。
Heartbeat, ipvsadm は www1 と www2 のみにインストール / 設定。arptables の設定は3台共通。

[追記] 現在は、CentOS-4 extras に heartbeat, ipvsadm のパッケージがあります。

インストールされた RPM

  • heartbeat-1.2.3.cvs.20050927-1.centos.um.1
  • heartbeat-pils-1.2.3.cvs.20050927-1.centos.um.1
  • heartbeat-ldirectord-1.2.3.cvs.20050927-1.centos.um.1
  • heartbeat-stonith-1.2.3.cvs.20050927-1.centos.um.1
  • ipvsadm-1.24-6
  • arptables-noarp-addr-0.99.1-1.rh.el.um.1
  • arptables_jf-0.0.8-2
# /etc/ha.d/haresources
www1.example.com 192.168.0.10 \
        ldirectord::ldirectord.cf \
        IPaddr::192.168.0.10/24/eth0

ldirectord で、VIP で公開するサービスと Real Server の設定。

# /etc/ha.d/ldirectord.cf
# Global Directives
checktimeout=10
checkinterval=5
autoreload=no
logfile="local0"
quiescent=yes

# Virtual Server for HTTP
virtual=192.168.0.10:80
       real=192.168.0.7:80 gate
       real=192.168.0.8:80 gate
       real=192.168.0.9:80 gate
       service=http
       request="ping.cgi"
       receive="ok"
       scheduler=rr
       #persistent=600
       protocol=tcp
       checktype=negotiate
virtual=192.168.0.10:443
       real=192.168.0.7:443 gate
       real=192.168.0.8:443 gate
       real=192.168.0.9:443 gate
       service=https
       request="ping.cgi"
       receive="ok"
       scheduler=rr
       #persistent=600
       protocol=tcp
       checktype=negotiate

Directorの死活監視 (heartbeat) 設定。

# /etc/ha.d/ha.cf
logfacility     local0
# bcast         eth0
ucast           eth0    192.168.0.8    <-- 相手の IP addr
auto_failback   off
node            www1.example.com
node            www2.example.com
respawn hacluster /usr/lib/heartbeat/ipfail

heartbeat の認証情報。

# /etc/ha.d/authkeys
auth 2
2 sha1 xxxxxxxx

arptables は、Virtual IP addr に対する arp に、リアルサーバが反応しないようにするために使う。

# /etc/sysconfig/arptables
*filter
:IN ACCEPT [10:280]
:OUT ACCEPT [1:28]
:FORWARD ACCEPT [0:0]
[6:168] -A IN -d 192.168.0.10 -j DROP
[0:0] -A OUT -s 192.168.0.10 -o eth0 -j mangle --mangle-ip-s 192.168.0.7 <-- 自分の real IP addr
COMMIT

Director が Active / Standby になったタイミングで、arptables の設定を変更するために

 # ( cd /etc/ha.d/rc.d && ln -s arptables-noarp-addr_takeip local_takeip; )
 # ( cd /etc/ha.d/rc.d && ln -s arptables-noarp-addr_giveip local_giveip; )

を実行。

あとは、起動時に heartbeat, arptables_jf が起動するように設定。ldirectord は heartbeat 経由で起動されるので、自動起動させない。

 # chkconfig --level 345 heartbeat on
 # chkconfig --level 345 arptables_jf on
 # chkconfig --level 345 ldirectord off
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy