为了测试目的,我启动了 2 个 Debian jessie VM(使用 vagrant 和 virtualbox),并让它们都运行一个小型 Web 服务器并使用 keepalived 进行配置。
问题是,BACKUP 服务器在几秒钟后service keepalived restart
毫无原因地转换为 MASTER。
我还看到 VRRP 多播数据包到达两台服务器,它们看起来符合预期。(这似乎意味着Keepalived 不需要转换为 master不相关)
配置文件如下:
主服务器:
global_defs {
lvs_id tom_lvs
}
vrrp_instance tom_lvs {
state MASTER
interface eth1
virtual_router_id 1
lvs_sync_daemon_interface eth1
priority 100
preempt
authentication {
auth_type PASS
auth_pass 1234
}
advert_int 1
virtual_ipaddress {
172.28.128.10/24
}
virtual_server 172.28.128.10 3000 {
delay_loop 10
lb_algo wlc
lb_kind DR
protocol TCP
persistence_timeout 1800
sorry_server 172.28.128.3 3000
real_server 172.28.128.4 3000 {
weight 5
HTTP_GET {
url {
path /index.html
}
}
}
}
}
备份服务器:
global_defs {
lvs_id tom_lvs
}
vrrp_instance tom_lvs {
state BACKUP
interface eth1
virtual_router_id 2
lvs_sync_daemon_interface eth1
priority 96
preempt
authentication {
auth_type PASS
auth_pass 1234
}
advert_int 1
virtual_ipaddress {
172.28.128.10/24
}
virtual_server 172.28.128.10 3000 {
delay_loop 10
lb_algo wlc
lb_kind DR
protocol TCP
persistence_timeout 1800
sorry_server 172.28.128.3 3000
real_server 172.28.128.3 3000 {
weight 5
HTTP_GET {
url {
path /index.html
}
}
}
}
}
备份服务器上的日志显示从 BACKUP 到 MASTER 的转换:
Feb 14 13:22:44 jessie Keepalived_vrrp[1145]: VRRP_Instance(tom_lvs) sending 0 priority
Feb 14 13:22:44 jessie Keepalived_vrrp[1176]: Registering Kernel netlink reflector
Feb 14 13:22:44 jessie Keepalived_vrrp[1176]: Registering Kernel netlink command channel
Feb 14 13:22:44 jessie Keepalived_vrrp[1176]: Registering gratuitous ARP shared channel
Feb 14 13:22:44 jessie Keepalived_vrrp[1176]: Opening file '/etc/keepalived/keepalived.conf'.
Feb 14 13:22:44 jessie Keepalived_healthcheckers[1175]: Registering Kernel netlink reflector
Feb 14 13:22:44 jessie Keepalived_vrrp[1176]: Configuration is using : 62104 Bytes
Feb 14 13:22:44 jessie Keepalived_vrrp[1176]: Using LinkWatch kernel netlink reflector...
Feb 14 13:22:44 jessie Keepalived_healthcheckers[1175]: Registering Kernel netlink command channel
Feb 14 13:22:44 jessie Keepalived_healthcheckers[1175]: Opening file '/etc/keepalived/keepalived.conf'.
Feb 14 13:22:44 jessie Keepalived_healthcheckers[1175]: Configuration is using : 12103 Bytes
Feb 14 13:22:44 jessie Keepalived_vrrp[1176]: VRRP_Instance(tom_lvs) Entering BACKUP STATE
Feb 14 13:22:44 jessie Keepalived_healthcheckers[1175]: Using LinkWatch kernel netlink reflector...
Feb 14 13:22:44 jessie Keepalived_healthcheckers[1175]: Activating healthchecker for service [172.28.128.3]:3000
Feb 14 13:22:48 jessie Keepalived_vrrp[1176]: VRRP_Instance(tom_lvs) Transition to MASTER STATE
Feb 14 13:22:49 jessie Keepalived_vrrp[1176]: VRRP_Instance(tom_lvs) Entering MASTER STATE
这是我在两台机器上看到的tshark
Capturing on 'eth1'
1 0.000000 172.28.128.4 -> 224.0.0.18 VRRP 60 Announcement (v2)
2 0.001404 172.28.128.3 -> 224.0.0.18 VRRP 54 Announcement (v2)
3 1.002283 172.28.128.4 -> 224.0.0.18 VRRP 60 Announcement (v2)
4 1.004130 172.28.128.3 -> 224.0.0.18 VRRP 54 Announcement (v2)
5 2.004466 172.28.128.4 -> 224.0.0.18 VRRP 60 Announcement (v2)
6 2.006260 172.28.128.3 -> 224.0.0.18 VRRP 54 Announcement (v2)
答案1
我在研究类似行为时遇到了这个问题,所以我想发布答案,以便让其他同样困惑的人受益。
两个配置文件都需要对 virtual_router_id 使用相同的值,因为这样 keepalived 才能知道状态消息是针对同一个虚拟路由器的。
在上面的配置中,它们具有不同的值,因此独立运行。