原始出處:http://bbs.chinaunix.net/thread-4174822-1-1.html html
(出處: http://bbs.chinaunix.net/)nginx
keepalived 主(192.168.1.3)
! Configuration File for keepalived
global_defs {
notification_email {
#admin@demo.com
}
#notification_email_from admin@demo.com
#smtp_server 127.0.0.1
#smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_nginx.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.2
}
track_script {
chk_nginx
}
}
keepalived 備(192.168.1.4)
! Configuration File for keepalived
global_defs {
notification_email {
#admin@michael-demo.com
}
#notification_email_from admin@michael-demo.com
#smtp_server 127.0.0.1
#smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_nginx.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 98
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
221.1.220.206
}
track_script {
chk_nginx
}
}
如今問題是兩臺機器都有VIP .可是一臺重啓或宕機。另一臺能接管。備機state改成BACKUP模式也白搭!
keepalived 主日誌:
Apr 17 07:30:04 localhost kernel: Bluetooth: RFCOMM socket layer initialized
Apr 17 07:30:04 localhost kernel: Bluetooth: RFCOMM TTY layer initialized
Apr 17 07:30:04 localhost kernel: Bluetooth: RFCOMM ver 1.8
Apr 17 07:30:04 localhost kernel: Bluetooth: HIDP (Human Interface Emulation) ver 1.1
Apr 17 07:36:39 localhost Keepalived_vrrp[2520]: VRRP_Script(chk_nginx) timed out
Apr 17 07:36:39 localhost Keepalived_vrrp[2520]: VRRP_Script(chk_nginx) succeeded
Apr 17 07:36:55 localhost Keepalived_vrrp[2520]: VRRP_Script(chk_nginx) timed out
Apr 17 07:36:55 localhost Keepalived_vrrp[2520]: VRRP_Script(chk_nginx) succeeded
Apr 17 07:54:13 localhost Keepalived_vrrp[2520]: VRRP_Script(chk_nginx) timed out
Apr 17 07:54:13 localhost Keepalived_vrrp[2520]: VRRP_Script(chk_nginx) succeeded
keepalived 備日誌:
Apr 16 23:51:29 Keepalived_vrrp[4733]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Apr 16 23:51:29 Keepalived_vrrp[4733]: VRRP_Script(chk_nginx) succeeded
Apr 16 23:51:30 Keepalived_vrrp[4733]: VRRP_Instance(VI_1) Transition to MASTER STATE
Apr 16 23:51:31 Keepalived_vrrp[4733]: VRRP_Instance(VI_1) Entering MASTER STATE
Apr 16 23:51:31 Keepalived_vrrp[4733]: VRRP_Instance(VI_1) setting protocol VIPs.
Apr 16 23:51:31 Keepalived_healthcheckers[4732]: Netlink reflector reports IP 192.168.1.2 added
Apr 16 23:51:31 Keepalived_vrrp[4733]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.2
Apr 16 23:51:31 avahi-daemon[3246]: Registering new address record for 192.168.1.2 on eth0.
Apr 16 23:51:31 Keepalived_vrrp[4733]: Netlink reflector reports IP 19.168.1.2 added
Apr 16 23:51:36 Keepalived_vrrp[4733]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.2
解決方法吧,出現這問題的場景是在阿里VPS雲服務器網絡環境中,由於路由交換層禁用了ARP的廣播限制,形成KEEPALIVE主備協議沒法經過廣播的方式進行通訊,形成主備兩臺服務器都強佔HAVIP地址,出現同時兩臺服務器都有VIP地址的狀況出現,必須經過配置來指定IP的兩臺服務器間進行通信(阿里說明文檔中解釋只能支持兩臺使用同一個HAVIP地址),基於如下方法能夠的狀況下,多備方式用一樣的方式也應該可行 ,有須要的兄弟能夠測試下多IP備的方式(正常狀況須要主備一對主備就夠了)。
在網卡配置後面須要加上如下配置:
priority 100 ##主服務100 備服務90只要小於100就能夠
unicast_src_ip 192.168.1.21##(本地IP地址)
unicast_peer {
192.168.1.22##(對端IP地址)此地址必定不能忘記
}
(對端IP地址)問題一直沒注意。服務器