keepalived 主备切换造成服务中断以及MASTER主动宣告测试

文章描述了在测试环境中,服务器之间的VRRP协议导致的脑裂现象,以及通过调整gratuitousARP配置来解决master与backup角色切换时ARP缓存同步问题的过程。
摘要由CSDN通过智能技术生成

测试环境:

服务器: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 命令重新加载

参考文章
Keepalived中gratuitous arp的作用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值