![Keepalived 在主服务器电源循环时丢失 VIP](https://linux22.com/image/639735/Keepalived%20%E5%9C%A8%E4%B8%BB%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%94%B5%E6%BA%90%E5%BE%AA%E7%8E%AF%E6%97%B6%E4%B8%A2%E5%A4%B1%20VIP.png)
我有两台运行 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 进行的网络自动配置。)