keepalivedでVIPを設定してVRRPを試してみる
サーバを2台用意します。
SV1:192.168.10.201
SV2:192.168.10.202
VIP:192.168.10.200
SV1
$ sudo vi /etc/keepalived/keepalived.conf $ sudo /etc/init.d/keepalived start
SV1のkeepalived.conf
※メール通知を省略してます。
! Configuration File for keepalived global_defs { notification_email { } } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass passworddayo } virtual_ipaddress { 192.168.10.200 } }
SV2
$ sudo vi /etc/keepalived/keepalived.conf $ sudo /etc/init.d/keepalived start
SV2のkeepalived.conf
※メール通知を省略してます。
! Configuration File for keepalived global_defs { notification_email { } } vrrp_instance VI_1 { state BACKUP interface eth0 lvs_sync_daemon_interface eth0 virtual_router_id 51 priority 50 advert_int 1 authentication { auth_type PASS auth_pass passworddayo } virtual_ipaddress { 192.168.10.200 } }
ここまででSV1のVIPが192.168.10.200に設定されて
SV2が待機状態で起動している事になります。
SV1のkeepalivedが停止するとマルチキャストされていた
アドバタイズメントメッセージが受信できなくなるので
SV2のkeepalivedがVIPを引き継ぎます。
この流れを確認してみましょう。
SV2
$ ping 192.168.10.200 PING 192.168.10.200 (192.168.10.200) 56(84) bytes of data. 64 bytes from 192.168.10.200: icmp_seq=1 ttl=64 time=0.037 ms 64 bytes from 192.168.10.200: icmp_seq=2 ttl=64 time=0.042 ms 64 bytes from 192.168.10.200: icmp_seq=3 ttl=64 time=0.057 ms 64 bytes from 192.168.10.200: icmp_seq=4 ttl=64 time=0.057 ms 64 bytes from 192.168.10.200: icmp_seq=5 ttl=64 time=0.059 ms 64 bytes from 192.168.10.200: icmp_seq=6 ttl=64 time=0.057 ms 64 bytes from 192.168.10.200: icmp_seq=7 ttl=64 time=0.060 ms 64 bytes from 192.168.10.200: icmp_seq=8 ttl=64 time=0.058 ms 64 bytes from 192.168.10.200: icmp_seq=9 ttl=64 time=0.051 ms 64 bytes from 192.168.10.200: icmp_seq=10 ttl=64 time=0.058 ms 64 bytes from 192.168.10.200: icmp_seq=11 ttl=64 time=0.054 ms 64 bytes from 192.168.10.200: icmp_seq=12 ttl=64 time=0.050 ms 64 bytes from 192.168.10.200: icmp_seq=13 ttl=64 time=0.052 ms 64 bytes from 192.168.10.200: icmp_seq=14 ttl=64 time=0.042 ms 64 bytes from 192.168.10.200: icmp_seq=15 ttl=64 time=0.056 ms 64 bytes from 192.168.10.200: icmp_seq=16 ttl=64 time=0.051 ms 64 bytes from 192.168.10.200: icmp_seq=17 ttl=64 time=0.048 ms 64 bytes from 192.168.10.200: icmp_seq=18 ttl=64 time=0.048 ms 64 bytes from 192.168.10.200: icmp_seq=19 ttl=64 time=0.051 ms 64 bytes from 192.168.10.200: icmp_seq=20 ttl=64 time=0.061 ms 64 bytes from 192.168.10.200: icmp_seq=21 ttl=64 time=0.060 ms 64 bytes from 192.168.10.200: icmp_seq=22 ttl=64 time=0.059 ms 64 bytes from 192.168.10.200: icmp_seq=23 ttl=64 time=0.050 ms 64 bytes from 192.168.10.200: icmp_seq=24 ttl=64 time=0.062 ms 64 bytes from 192.168.10.200: icmp_seq=25 ttl=64 time=0.058 ms 64 bytes from 192.168.10.200: icmp_seq=26 ttl=64 time=0.058 ms 64 bytes from 192.168.10.200: icmp_seq=27 ttl=64 time=0.062 ms 64 bytes from 192.168.10.200: icmp_seq=28 ttl=64 time=0.059 ms 64 bytes from 192.168.10.200: icmp_seq=29 ttl=64 time=0.064 ms 64 bytes from 192.168.10.200: icmp_seq=30 ttl=64 time=0.063 ms 64 bytes from 192.168.10.200: icmp_seq=31 ttl=64 time=0.061 ms 64 bytes from 192.168.10.200: icmp_seq=32 ttl=64 time=0.060 ms 64 bytes from 192.168.10.200: icmp_seq=33 ttl=64 time=0.063 ms
SV1
$ /sbin/ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 100 link/ether 6c:f0:49:c8:ef:ce brd ff:ff:ff:ff:ff:ff inet 192.168.10.201/24 brd 192.168.10.255 scope global eth0 inet 192.168.10.200/32 scope global eth0 inet6 fe80::6ef0:49ff:fec8:efce/64 scope link valid_lft forever preferred_lft forever $ sudo /etc/init.d/keepalived stop keepalived を停止中: [ OK ] $ /sbin/ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 100 link/ether 6c:f0:49:c8:ef:ce brd ff:ff:ff:ff:ff:ff inet 192.168.10.201/24 brd 192.168.10.255 scope global eth0 inet6 fe80::6ef0:49ff:fec8:efce/64 scope link valid_lft forever preferred_lft forever $ sudo /etc/init.d/keepalived start keepalived を起動中: [ OK ] $ /sbin/ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 100 link/ether 6c:f0:49:c8:ef:ce brd ff:ff:ff:ff:ff:ff inet 192.168.10.201/24 brd 192.168.10.255 scope global eth0 inet 192.168.10.200/32 scope global eth0 inet6 fe80::6ef0:49ff:fec8:efce/64 scope link valid_lft forever preferred_lft forever
上記のようにpingコマンドの実行の途中でSV1のkeepalivedを停止したり
再起動したりしてますがVIPは無事引き継がれています。