我有两台运行 Keepalived 1.2.7 的服务器,主机名分别为left
和right
。配置如下:
# keepalived.conf on left
vrrp_instance VI_1 {
state MASTER
interface eth1
virtual_router_id 51
priority 160
advert_int 1
virtual_ipaddress {
10.10.10.200
}
}
# keepalived.conf on right
vrrp_instance VI_1 {
state MASTER
interface eth1
virtual_router_id 51
priority 100
advert_int 1
virtual_ipaddress {
10.10.10.200
}
}
现在我关闭电源并重新开机left
。系统日志如下所示,交错并带有注释:
>> started servers <<
Aug 15 19:07:32 left Keepalived[4041]: Starting VRRP child process, pid=4043
Aug 15 19:07:32 right Keepalived[4041]: Starting VRRP child process, pid=4043
Aug 15 19:07:33 left Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Transition to MASTER STATE
Aug 15 19:07:33 right Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Transition to MASTER STATE
Aug 15 19:07:33 right Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Received higher prio advert
Aug 15 19:07:33 right Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Entering BACKUP STATE
Aug 15 19:07:34 left Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Entering MASTER STATE
>> left has 10.10.10.200 <<
>> powered off left <<
Aug 15 19:08:25 right Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Transition to MASTER STATE
Aug 15 19:08:26 right Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Entering MASTER STATE
>> right has 10.10.10.200 <<
>> powered on left <<
Aug 15 19:08:58 left Keepalived[1027]: Starting VRRP child process, pid=1029
Aug 15 19:08:59 left Keepalived_vrrp[1029]: VRRP_Instance(VI_1) Transition to MASTER STATE
Aug 15 19:09:00 left Keepalived_vrrp[1029]: VRRP_Instance(VI_1) Entering MASTER STATE
Aug 15 19:09:00 right Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Received higher prio advert
Aug 15 19:09:00 right Keepalived_vrrp[4043]: VRRP_Instance(VI_1) Entering BACKUP STATE
>> neither has 10.10.10.200 <<
我原本希望left
在 10.10.10.200 恢复时将其收回。为什么没有?我该如何修改我的keepalived.conf
s 才能实现这一点?
答案1
您希望“右侧”的配置如下所示:
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
priority 100
advert_int 1
virtual_ipaddress {
10.10.10.200
}
这备份关键字告诉 keepalived 故障恢复到掌握有空的时候。
答案2
以下配置有效,但我仍然很好奇为什么我的问题中没有。
# keepalived.conf on left
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
priority 160
advert_int 1
preempt_delay 15
virtual_ipaddress {
10.10.10.200
}
}
# keepalived.conf on right
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
priority 100
advert_int 1
preempt_delay 15
virtual_ipaddress {
10.10.10.200
}
}
preempt_delay
此配置表示在优先级更高的机器上线后 15 秒重新选举新的主服务器。该选项的解释如下在邮件列表中。
这种配置有一个问题:如果两台机器都宕机了,当它们重新启动时,都不会声明 10.10.10.200。(这是由于 Vagrant 进行的网络自动配置。)