! Configuration File for keepalived global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server smtp.qq.com smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER interface eth5 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.56.2 } }102(backup)的配置為
! Configuration File for keepalived global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server smtp.qq.com smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state BACKUP interface eth5 virtual_router_id 51 priority 99 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.56.2 } }PS:因為我只需要VIP浮動,負載均衡交給了HAProxy,所以KeepAlived的負載均衡功能沒有使用。
分別在101和102上啟動KeepAlived ---
啟動之前,看看如下:
daemon_mode默認值為0,而賦值的語句如下:
因為我們不需要 start_check_child(); 所以啟動參數加上-P即可,前台打日志,則加上 -ln
./bin/keepalived -f ./keepalived/etc/keepalived/keepalived.conf -P -ln然後看VIP是否可以ping
估計是iptables未容許vrrp協議.
iptables -A INPUT -p vrrp -j ACCEPT 需要保存? iptables -L 是列舉出當前的規則 ( )
再嘗試看看,還是不行,百度了半天,原來配置文件需要絕對路徑。
./bin/keepalived -f /root/keepalived-1.2.8/keepalived/etc/keepalived/keepalived.conf -P -ln
這下可以了
ping的結果:
接下來啟動2個redis.
啟動101->啟動102->啟動測試程序->掛掉101->啟動101
結果: