测试环境:
服务器:10.3.247.120(master) fa:16:3e:97:21:e5
服务器:10.3.247.118(backtup) fa:16:3e:02:9c:d2
vip:10.3.247.239
服务器:10.3.247.121 arp缓存查看
本次测试不涉及交换机配置修改
//断开命令
iptables -I INPUT 1 -p vrrp -j DROP && iptables -I INPUT 1 -p vrrp -j DROP
//恢复命令
iptables -D INPUT 1 && iptables -D INPUT 1
//arp缓存查看命令
while true; do echo $(date) ; arp -v |grep 10.3.247.239; sleep 1 ;done
断开时,keepalived 出现脑裂现象:
master 上 /var/log/messages 没有接收到日志,backup日志如下:
//tserver118(backup)
Nov 11 11:00:06 tserver118 Keepalived_vrrp[22554]: VRRP_Instance(VI_mknginx1) Transition to MASTER STATE
Nov 11 11:00:07 tserver118 Keepalived_vrrp[22554]: VRRP_Instance(VI_mknginx1) Entering MASTER STATE
Nov 11 11:00:07 tserver118 Keepalived_vrrp[22554]: VRRP_Instance(VI_mknginx1) setting protocol VIPs.
Nov 11 11:00:07 tserver118 Keepalived_vrrp[22554]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:00:07 tserver118 Keepalived_vrrp[22554]: VRRP_Instance(VI_mknginx1) Sending/queueing gratuitous ARPs on eth0 for 10.3.247.239
Nov 11 11:00:07 tserver118 Keepalived_vrrp[22554]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:00:07 tserver118 Keepalived_vrrp[22554]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:00:07 tserver118 Keepalived_vrrp[22554]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:00:07 tserver118 Keepalived_vrrp[22554]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:00:12 tserver118 Keepalived_vrrp[22554]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:00:12 tserver118 Keepalived_vrrp[22554]: VRRP_Instance(VI_mknginx1) Sending/queueing gratuitous ARPs on eth0 for 10.3.247.239
Nov 11 11:00:12 tserver118 Keepalived_vrrp[22554]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:00:12 tserver118 Keepalived_vrrp[22554]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:00:12 tserver118 Keepalived_vrrp[22554]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:00:12 tserver118 Keepalived_vrrp[22554]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:00:14 tserver118 Keepalived_vrrp[22554]: VRRP_Instance(VI_mknginx1) Received advert with higher priority 100, ours 96
Nov 11 11:00:14 tserver118 Keepalived_vrrp[22554]: VRRP_Instance(VI_mknginx1) Entering BACKUP STATE
Nov 11 11:00:14 tserver118 Keepalived_vrrp[22554]: VRRP_Instance(VI_mknginx1) removing protocol VIPs.
从日志中可看到tserver118(backup)成为MASTER,发送ARP on eth0 for 10.3.247.239
//ARP缓存
10.3.247.239 ether fa:16:3e:97:21:e5 C eth0
Thu Nov 11 11:00:06 CST 2021
10.3.247.239 ether fa:16:3e:97:21:e5 C eth0
Thu Nov 11 11:00:07 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
Thu Nov 11 11:00:08 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
······
Thu Nov 11 11:07:22 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
Thu Nov 11 11:07:23 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
Thu Nov 11 11:07:24 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
网络恢复后 tserver120(master)没有再次宣告。11:00:15~11:07:22 10.3.247.239 HWaddress 仍然绑定在server118(backup)网卡上,
如何解决
添加master主动宣告
//添加配置
vrrp_garp_master_refresh 60 #成为master后,刷新免费arp最小时间间隔
vrrp_garp_master_refresh_repeat 1 #成为master后,每次发送1个arp
//断开命令
iptables -I INPUT 1 -p vrrp -j DROP && iptables -I INPUT 1 -p vrrp -j DROP
//恢复命令
iptables -D INPUT 1 && iptables -D INPUT 1
//arp缓存查看命令
while true; do echo $(date) ; arp -v |grep 10.3.247.239; sleep 1 ;done
断开时,keepalived 出现脑裂现象,查看/var/log/messages
//tserver118(backup)
Nov 11 11:23:28 tserver118 Keepalived_vrrp[18429]: VRRP_Instance(VI_mknginx1) Transition to MASTER STATE
Nov 11 11:23:29 tserver118 Keepalived_vrrp[18429]: VRRP_Instance(VI_mknginx1) Entering MASTER STATE
Nov 11 11:23:29 tserver118 Keepalived_vrrp[18429]: VRRP_Instance(VI_mknginx1) setting protocol VIPs.
Nov 11 11:23:29 tserver118 Keepalived_vrrp[18429]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:23:29 tserver118 Keepalived_vrrp[18429]: VRRP_Instance(VI_mknginx1) Sending/queueing gratuitous ARPs on eth0 for 10.3.247.239
Nov 11 11:23:29 tserver118 Keepalived_vrrp[18429]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:23:29 tserver118 Keepalived_vrrp[18429]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:23:29 tserver118 Keepalived_vrrp[18429]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:23:29 tserver118 Keepalived_vrrp[18429]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:23:34 tserver118 Keepalived_vrrp[18429]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:23:34 tserver118 Keepalived_vrrp[18429]: VRRP_Instance(VI_mknginx1) Sending/queueing gratuitous ARPs on eth0 for 10.3.247.239
Nov 11 11:23:34 tserver118 Keepalived_vrrp[18429]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:23:34 tserver118 Keepalived_vrrp[18429]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:23:34 tserver118 Keepalived_vrrp[18429]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:23:34 tserver118 Keepalived_vrrp[18429]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:23:43 tserver118 Keepalived_vrrp[18429]: VRRP_Instance(VI_mknginx1) Received advert with higher priority 100, ours 96
Nov 11 11:23:43 tserver118 Keepalived_vrrp[18429]: VRRP_Instance(VI_mknginx1) Entering BACKUP STATE
Nov 11 11:23:43 tserver118 Keepalived_vrrp[18429]: VRRP_Instance(VI_mknginx1) removing protocol VIPs.
从日志中可看到tserver118(backup)成为MASTER,发送ARP on eth0 for 10.3.247.239
//tserver120(master)
Nov 11 11:23:32 tserver120 Keepalived_vrrp[3396]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:23:32 tserver120 Keepalived_vrrp[3396]: VRRP_Instance(VI_mknginx1) Sending/queueing gratuitous ARPs on eth0 for 10.3.247.239
Nov 11 11:24:32 tserver120 Keepalived_vrrp[3396]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:24:32 tserver120 Keepalived_vrrp[3396]: VRRP_Instance(VI_mknginx1) Sending/queueing gratuitous ARPs on eth0 for 10.3.247.239
Nov 11 11:25:33 tserver120 Keepalived_vrrp[3396]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:25:33 tserver120 Keepalived_vrrp[3396]: VRRP_Instance(VI_mknginx1) Sending/queueing gratuitous ARPs on eth0 for 10.3.247.239
Nov 11 11:26:33 tserver120 Keepalived_vrrp[3396]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:26:33 tserver120 Keepalived_vrrp[3396]: VRRP_Instance(VI_mknginx1) Sending/queueing gratuitous ARPs on eth0 for 10.3.247.239
Nov 11 11:27:33 tserver120 Keepalived_vrrp[3396]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:27:33 tserver120 Keepalived_vrrp[3396]: VRRP_Instance(VI_mknginx1) Sending/queueing gratuitous ARPs on eth0 for 10.3.247.239
Nov 11 11:28:33 tserver120 Keepalived_vrrp[3396]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:28:33 tserver120 Keepalived_vrrp[3396]: VRRP_Instance(VI_mknginx1) Sending/queueing gratuitous ARPs on eth0 for 10.3.247.239
Nov 11 11:29:33 tserver120 Keepalived_vrrp[3396]: Sending gratuitous ARP on eth0 for 10.3.247.239
Nov 11 11:29:33 tserver120 Keepalived_vrrp[3396]: VRRP_Instance(VI_mknginx1) Sending/queueing gratuitous ARPs on eth0 for 10.3.247.239
tserver120(master)会每隔一分钟发送 gratuitous ARP 宣告,从ARP缓存中可以看到,1分钟后 10.3.247.239 的HWaddress 已经绑在tserver120(master)网卡上
//ARP缓存
Thu Nov 11 11:23:28 CST 2021
10.3.247.239 ether fa:16:3e:97:21:e5 C eth0
Thu Nov 11 11:23:29 CST 2021
10.3.247.239 ether fa:16:3e:97:21:e5 C eth0
Thu Nov 11 11:23:30 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
Thu Nov 11 11:23:31 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
Thu Nov 11 11:23:32 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
Thu Nov 11 11:23:33 CST 2021
10.3.247.239 ether fa:16:3e:97:21:e5 C eth0
Thu Nov 11 11:23:34 CST 2021
10.3.247.239 ether fa:16:3e:97:21:e5 C eth0
Thu Nov 11 11:23:35 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
Thu Nov 11 11:23:36 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
Thu Nov 11 11:23:37 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
Thu Nov 11 11:23:38 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
······
Thu Nov 11 11:24:29 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
Thu Nov 11 11:24:30 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
Thu Nov 11 11:24:31 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
Thu Nov 11 11:24:32 CST 2021
10.3.247.239 ether fa:16:3e:02:9c:d2 C eth0
Thu Nov 11 11:24:33 CST 2021
10.3.247.239 ether fa:16:3e:97:21:e5 C eth0
Thu Nov 11 11:24:34 CST 2021
10.3.247.239 ether fa:16:3e:97:21:e5 C eth0
Thu Nov 11 11:24:35 CST 2021
10.3.247.239 ether fa:16:3e:97:21:e5 C eth0
Thu Nov 11 11:24:36 CST 2021
10.3.247.239 ether fa:16:3e:97:21:e5 C eth0
Thu Nov 11 11:24:37 CST 2021
10.3.247.239 ether fa:16:3e:97:21:e5 C eth0
线上服务器修改配置文件后可以通过systemctl reload keepalived 命令重新加载