Keepalived VIP自动切换



Keepalived VIP切换的两种情况:

1.keepalived 进程被停止。

2.keepalived中track_script检测失败。 


haproxy 检测:

vrrp_script chk_haproxy {

   script "killall -0 haproxy"     # cheaper than pidof

   interval 2                # check every 2 seconds

   weight -2

}


切换相关日志:tail -f /var/log/messages

Keepalived_vrrp[32408]: VRRP_Script(chk_haproxy) failed
Keepalived_vrrp[32408]: VRRP_Instance(VI_1) Received higher prio advert
Keepalived_vrrp[32408]: VRRP_Instance(VI_1) Entering BACKUP STATE
Keepalived_vrrp[32408]: VRRP_Instance(VI_1) removing protocol VIPs.
Keepalived_vrrp[32408]: VRRP_Script(chk_haproxy) succeeded
Keepalived_vrrp[32408]: VRRP_Instance(VI_1) forcing a new MASTER election
Keepalived_vrrp[32408]: VRRP_Instance(VI_1) forcing a new MASTER election
Keepalived_vrrp[32408]: VRRP_Instance(VI_1) Transition to MASTER STATE
Keepalived_vrrp[32408]: VRRP_Instance(VI_1) Entering MASTER STATE
Keepalived_vrrp[32408]: VRRP_Instance(VI_1) setting protocol VIPs.
Keepalived_vrrp[32408]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 10.1.1.56
Keepalived_vrrp[32408]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 10.1.1.56


切换失败的情况:

keepalived 进程被停止时VIP可以正常切换,keepalived 进程运行状态下,haproxy相关服务停止后,VIP未如期进行切换。


分析:

停止haproxy服务,手动执行killall -0 haproxy && echo "success" || echo "fail",返回结果是success。

停止haproxy服务后,ps aux |grep haproxy发现还有一个正常启动的haproxy,killall -9 haproxy后发现 tail -f /var/log/messages 出现VIP正常切换的日志。