原始出处:http://bbs.chinaunix.net/thread-4174822-1-1.html
(出处: http://bbs.chinaunix.net/)
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地址)问题一直没注意。