tail /var/log/messages
Aug 19 19:12:16 localhost Keepalived_vrrp[27587]: VRRP_Script(chk_nginx) succeeded
Aug 19 19:12:16 localhost Keepalived_vrrp[27587]: VRRP_Script(chk_mantaince_down) succeeded
Aug 19 19:12:17 localhost Keepalived_vrrp[27587]: VRRP_Instance(VI_1) Transition to MASTER STATE
Aug 19 19:12:18 localhost Keepalived_vrrp[27587]: VRRP_Instance(VI_1) Entering MASTER STATE
Aug 19 19:12:18 localhost Keepalived_vrrp[27587]: VRRP_Instance(VI_1) setting protocol VIPs.
Aug 19 19:12:18 localhost Keepalived_healthcheckers[27586]: Netlink reflector reports IP 192.168.1.90 added
Aug 19 19:12:18 localhost avahi-daemon[3327]: Registering new address record for 192.168.1.90 on eth0.
Aug 19 19:12:18 localhost Keepalived_vrrp[27587]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.90
Aug 19 19:12:18 localhost Keepalived_vrrp[27587]: Netlink reflector reports IP 192.168.1.90 added
Aug 19 19:12:23 localhost Keepalived_vrrp[27587]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.90
可以看到node1被选举为master,vip配置在node1上
使用ip addr 查看
1
2
3
4
5
...
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:a3:12:75 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.85/24 brd 192.168.1.255 scope global eth0
inet 192.168.1.90/32 scope global eth0
查看node2上日志信息
1
2
3
4
5
6
7
8
9
10
Aug 19 19:12:17 localhost Keepalived_vrrp[16800]: Registering Kernel netlink reflector
Aug 19 19:12:17 localhost Keepalived_vrrp[16800]: Registering Kernel netlink command channel
Aug 19 19:12:17 localhost Keepalived_vrrp[16800]: Registering gratuitous ARP shared channel
Aug 19 19:12:17 localhost Keepalived_vrrp[16800]: Opening file '/etc/keepalived/keepalived.conf'.
Aug 19 19:12:17 localhost Keepalived_vrrp[16800]: Configuration is using : 40529 Bytes
Aug 19 19:12:17 localhost Keepalived_vrrp[16800]: Using LinkWatch kernel netlink reflector...
Aug 19 19:12:17 localhost Keepalived_vrrp[16800]: VRRP_Instance(VI_1) Entering BACKUP STATE
Aug 19 19:12:17 localhost Keepalived_vrrp[16800]: VRRP sockpool: [ifindex(2), proto(112), fd(11,12)]
Aug 19 19:12:17 localhost Keepalived_vrrp[16800]: VRRP_Script(chk_nginx) succeeded
Aug 19 19:12:17 localhost Keepalived_vrrp[16800]: VRRP_Script(chk_mantaince_down) succeeded
为backup状态
此时打开浏览器访问vip 192.168.1.90 提供页面的是node1
将node1上的nginx服务down掉
1
service nginx stop
再次查看node1 上的日志
1
2
3
4
5
6
7
8
Aug 19 19:18:15 localhost Keepalived_vrrp[27587]: VRRP_Script(chk_nginx) failed
Aug 19 19:18:16 localhost Keepalived_vrrp[27587]: VRRP_Instance(VI_1) Received higher prio advert
Aug 19 19:18:16 localhost Keepalived_vrrp[27587]: VRRP_Instance(VI_1) Entering BACKUP STATE
Aug 19 19:18:16 localhost Keepalived_vrrp[27587]: VRRP_Instance(VI_1) removing protocol VIPs.
Aug 19 19:18:16 localhost Keepalived_healthcheckers[27586]: Netlink reflector reports IP 192.168.1.90 removed
Aug 19 19:18:16 localhost avahi-daemon[3327]: Withdrawing address record for 192.168.1.90 on eth0.
Aug 19 19:18:16 localhost Keepalived_vrrp[27587]: Netlink reflector reports IP 192.168.1.90 removed
Aug 19 19:18:17 localhost Keepalived_vrrp[27587]: VRRP_Script(chk_nginx) succeeded
此时,node1已经变为backup状态,vip也已经被移除
查看node2的日志信息
1
2
3
4
5
6
7
Aug 19 19:12:17 localhost Keepalived_vrrp[16800]: VRRP_Script(chk_nginx) succeeded
Aug 19 19:12:17 localhost Keepalived_vrrp[16800]: VRRP_Script(chk_mantaince_down) succeeded
Aug 19 19:18:16 localhost Keepalived_vrrp[16800]: VRRP_Instance(VI_1) forcing a new MASTER election
Aug 19 19:18:17 localhost Keepalived_vrrp[16800]: VRRP_Instance(VI_1) Transition to MASTER STATE
Aug 19 19:18:18 localhost Keepalived_vrrp[16800]: VRRP_Instance(VI_1) Entering MASTER STATE
Aug 19 19:18:18 localhost Keepalived_vrrp[16800]: VRRP_Instance(VI_1) setting protocol VIPs.
Aug 19 19:18:18 localhost Keepalived_vrrp[16800]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.90