Cent0S + LVS x 1 + keepalived on VirtualBox

前回の続き。
冗長化なしてkeepalivedを使ってみる。


とりあえず、cthulhuの仮想IP(eth0:0)はInactiveにする。


[root@cthulhu ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:6A:33:F0
inet addr:192.168.11.13 Bcast:192.168.11.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe6a:33f0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:234 errors:0 dropped:0 overruns:0 frame:0
TX packets:223 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:264535 (258.3 KiB) TX bytes:23898 (23.3 KiB)
Interrupt:11 Base address:0xd020

eth1 Link encap:Ethernet HWaddr 08:00:27:5A:59:05
inet addr:192.168.21.13 Bcast:192.168.21.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe5a:5905/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6 errors:0 dropped:0 overruns:0 frame:0
TX packets:47 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:360 (360.0 b) TX bytes:8225 (8.0 KiB)
Interrupt:10 Base address:0xd240

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:3388 errors:0 dropped:0 overruns:0 frame:0
TX packets:3388 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5433548 (5.1 MiB) TX bytes:5433548 (5.1 MiB)


ipvsadmの設定もクリア。


[root@cthulhu ~]# ipvsadm -C
[root@cthulhu ~]# /etc/init.d/ipvsadm save
Saving IPVS table to /etc/sysconfig/ipvsadm: [ OK ]
[root@cthulhu ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
[root@cthulhu ~]# cat /etc/sysconfig/ipvsadm
[root@cthulhu ~]#


こちらのページを参考にして、keepalivedをビルド。


[root@cthulhu ~]# cd /usr/src/redhat/SOURCES/
[root@cthulhu SOURCES]# wget http://www.keepalived.org/software/keepalived-1.1.18.tar.gz
[root@cthulhu SOURCES]# tar xf keepalived-1.1.18.tar.gz
[root@cthulhu SOURCES]# cd keepalived-1.1.18
[root@cthulhu keepalived-1.1.18]# ./configure --with-kernel-dir=/lib/modules/2.6.18-164.el5/build
[root@cthulhu keepalived-1.1.18]# make rpm
[root@cthulhu keepalived-1.1.18]# rpm -ihv /usr/src/redhat/RPMS/i386/keepalived-1.1.18-5.i386.rpm
1.1.18ではlink_watch.cは不要になったのかも。


hasterにヘルスチェック用のページを用意する。


[root@hastur ~]# echo OK > /var/www/html/test

[root@cthulhu ~]# curl http://192.168.21.15/test
OK


/etc/keepalived/keepalived.conf を修正。


! Configuration File for keepalived

global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
! smtp_server 192.168.200.1
! smtp_connect_timeout 30
router_id LVS_DEVEL
}

vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.11.100/24
}
}

virtual_server 192.168.11.100 80 {
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 50
protocol TCP

! sorry_server 192.168.200.200 1358

real_server 192.168.21.15 80 {
weight 1
HTTP_GET {
url {
path /test
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}


keepalivedを起動すると、仮想IPと振り分けが設定される。


[root@cthulhu ~]# /etc/init.d/keepalived start
Starting keepalived: [ OK ]
[root@cthulhu ~]# ip addr show
1: lo: mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 08:00:27:6a:33:f0 brd ff:ff:ff:ff:ff:ff
inet 192.168.11.13/24 brd 192.168.11.255 scope global eth0
inet 192.168.11.100/24 scope global secondary eth0
inet6 fe80::a00:27ff:fe6a:33f0/64 scope link
valid_lft forever preferred_lft forever
3: eth1: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 08:00:27:5a:59:05 brd ff:ff:ff:ff:ff:ff
inet 192.168.21.13/24 brd 192.168.21.255 scope global eth1
inet6 fe80::a00:27ff:fe5a:5905/64 scope link
valid_lft forever preferred_lft forever
4: sit0: mtu 1480 qdisc noop
link/sit 0.0.0.0 brd 0.0.0.0
[root@cthulhu ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.11.100:80 rr persistent 50
-> 192.168.21.15:80 Masq 1 0 0


で、クライアントから curl http://192.168.11.100/ を実行。


hasterでhttpdを落としてクライアントからアクセスすると、振り分け設定が変更される。


[root@hastur ~]# service httpd stop
Stopping httpd: [ OK ]

[root@cthulhu ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.11.100:80 rr persistent 50
[root@cthulhu ~]# tail -n 5 /var/log/messages
Sep 27 14:13:05 cthulhu Keepalived_healthcheckers: Error connecting server [192.168.21.15:80].
Sep 27 14:13:05 cthulhu Keepalived_healthcheckers: Removing service [192.168.21.15:80] from VS [192.168.11.100:80]
Sep 27 14:13:05 cthulhu Keepalived_healthcheckers: Lost quorum 1-0=1 > 0 for VS [192.168.11.100:80]
Sep 27 14:13:05 cthulhu Keepalived_healthcheckers: Remote SMTP server [127.0.0.1:25] connected.
Sep 27 14:13:06 cthulhu Keepalived_healthcheckers: SMTP alert successfully sent.