-
於是開始查看主從keepalived的配置文件是否有誤,vrid是否一致;最后發現配置文件是正常的;
-
接着開始排查是否是網絡問題:
tcpdump -i eth0|grep VRRP tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes 21:00:53.202437 IP 192.168.8.123 > vrrp.mcast.net: VRRPv2, Advertisement, vrid 50, prio 100, authtype simple, intvl 1s, length 20 21:00:53.202964 IP 192.168.8.126 > vrrp.mcast.net: VRRPv2, Advertisement, vrid 51, prio 100, authtype simple, intvl 1s, length 20 21:00:53.204638 IP keepalived-slave > vrrp.mcast.net: VRRPv2, Advertisement, vrid 66, prio 80, authtype simple, intvl 1s, length 20 發現keepalived從服務器也能正常接收到vrrp包;
-
最后考慮到,該主機啟用了firewalld防火牆;於是開始從防火牆開始着手解決問題
Keepalived是一個輕量級的HA集群解決方案,但開啟防火牆后各節點無法感知其它節點的狀態,各自都綁定了虛擬IP。網上很多文章講要配置防火牆放過tcp/112,在CentOS7下是無效的,正確的做法是配置放過vrrp協議,方法如下:
firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 --destination 224.0.0.18 --protocol vrrp -j ACCEPT
firewall-cmd --direct --permanent --add-rule ipv4 filter OUTPUT 0 --destination 224.0.0.18 --protocol vrrp -j ACCEPT
firewall-cmd --reload
Keepalived使用vrrp組播,默認地址是224.0.0.18,因此要配置防火牆放過。