keepalived 和两个活动服务器
keepalived and two active servers
我正在尝试使用 keepalived 配置两个主动负载平衡器服务器。
它与标准配置略有不同,我们有两台服务器和一个虚拟 IP。
我想要的只是当 loadbalancer_1 关闭时,然后 loadbalancer_2 获取他的 IP 地址,反之亦然。
loadbalancer_1 IP 地址:xx.237.193.132/27
loadbalancer_2 IP 地址:xx.237.193.134/27
当我第一次启动loadbalancer_1时,它也需要loadbalancer_2 IP地址,因为在那个特定时刻 keepalived 尚未在 loadbalancer_2 上启动。
但是当我开始 loadbalancer_2 时,他的 IP 地址仍然在 loadbalancer_1 上。所以,loadbalancer_1。是两个 IP 地址的主机。
同样的情况,当我先启动loadbalancer_2时,所以那些较早启动的服务器将成为两个IP地址的主服务器。
登录loadbalancer_1:
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Registering Kernel netlink reflector
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Registering Kernel netlink command channel
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Registering gratuitous ARP shared channel
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Opening file '/etc/keepalived/keepalived.conf'.
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Registering Kernel netlink reflector
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Registering Kernel netlink command channel
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Opening file '/etc/keepalived/keepalived.conf'.
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Configuration is using : 71869 Bytes
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Using LinkWatch kernel netlink reflector...
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_2) Entering BACKUP STATE
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Configuration is using : 12587 Bytes
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Using LinkWatch kernel netlink reflector...
Jul 19 19:18:01 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_1) Transition to MASTER STATE
Jul 19 19:18:02 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_1) Entering MASTER STATE
Jul 19 19:18:04 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_2) Transition to MASTER STATE
Jul 19 19:18:05 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_2) Entering MASTER STATE
登录loadbalancer_2:
Jul 19 19:18:08 002 Keepalived_vrrp[468]: Registering Kernel netlink reflector
Jul 19 19:18:08 002 Keepalived_vrrp[468]: Registering Kernel netlink command channel
Jul 19 19:18:08 002 Keepalived_vrrp[468]: Registering gratuitous ARP shared channel
Jul 19 19:18:08 002 Keepalived_vrrp[468]: Opening file '/etc/keepalived/keepalived.conf'.
Jul 19 19:18:08 022 Keepalived_vrrp[468]: Configuration is using : 71869 Bytes
Jul 19 19:18:08 002 Keepalived_vrrp[468]: Using LinkWatch kernel netlink reflector...
Jul 19 19:18:08 002 Keepalived_vrrp[468]: VRRP_Instance(web_loadbalancer_1) Entering BACKUP STATE
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Registering Kernel netlink reflector
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Registering Kernel netlink command channel
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Opening file '/etc/keepalived/keepalived.conf'.
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Configuration is using : 12587 Bytes
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Using LinkWatch kernel netlink reflector...
Jul 19 19:18:09 002 Keepalived_vrrp[468]: VRRP_Instance(web_loadbalancer_2) Transition to MASTER STATE
Jul 19 19:18:10 002 Keepalived_vrrp[468]: VRRP_Instance(web_loadbalancer_2) Entering MASTER STATE
Jul 19 19:18:11 002 Keepalived_vrrp[468]: VRRP_Instance(web_loadbalancer_2) Received lower prio advert, forcing new election
loadbalancer_1的配置:
global_defs {
router_id loadbalancer_1
lvs_id loadbalancer_1
}
vrrp_instance web_loadbalancer_1 {
state MASTER
interface eth0
virtual_router_id 10
priority 110
advert_int 1
virtual_ipaddress {
xx.237.193.132/27 dev eth0
}
authentication {
auth_type PASS
auth_pass 45f3fgv1
}
}
vrrp_instance web_loadbalancer_2 {
state BACKUP
interface eth0
virtual_router_id 20
priority 200
smtp_alert
advert_int 1
virtual_ipaddress {
xx.237.193.134/27 dev eth0
}
authentication {
auth_type PASS
auth_pass 45f3fgv2
}
}
loadbalancer_2的配置:
global_defs {
router_id loadbalancer_2
lvs_id loadbalancer_2
}
vrrp_instance web_loadbalancer_1 {
state BACKUP
interface eth0
virtual_router_id 10
priority 100
advert_int 1
virtual_ipaddress {
xx.237.193.132/27 dev eth0
}
authentication {
auth_type PASS
auth_pass 45f3fgv1
}
}
vrrp_instance web_loadbalancer_2 {
state MASTER
interface eth0
virtual_router_id 20
priority 210
advert_int 1
virtual_ipaddress {
xx.237.193.134/27 dev eth0
}
authentication {
auth_type PASS
auth_pass 45f3fgv2
}
}
我建议在两个 MASTER 部分添加 preempt_delay 10。
查看服务器 2 的最后一个日志条目
Jul 19 19:18:11 002 Keepalived_vrrp[468]: VRRP_Instance(web_loadbalancer_2) Received lower prio advert, forcing new election
好像它刚刚意识到它可以接管VRRP master。如果这没有发生,也许稍后会查看日志。
第一台服务器启动是正常的,因为没有其他服务器,假设主服务器,然后当第二台服务器激活时,vrrp 重新选举应该选择配置最高优先级的服务器。
问题被我解决了。
最初在 eth0 接口上有一个主 IP 地址(lb_1 和 lb_2),我在 keepalived 配置中使用了它们。
On loadbalancer_1 : xx.237.193.132/27
On loadbalancer_2 : xx.237.193.134/27
然后我刚刚编辑了一个 keepalived 配置并将这些 IP 地址替换为同一子网中的其他 IP 地址:
For loadbalancer_1 : xx.237.193.150/27
For loadbalancer_2 : xx.237.193.151/27
因此,当系统启动时,eth0 将使用旧的主 IP 地址进行初始化,但 keepalived 将使用其他虚拟 IP-来自同一子网的地址。
我不知道为什么第一个解决方案不起作用,我没有在任何地方找到解释或要求。
有谁能解释问题出在哪里,以及为什么我不能在 keepalived[=28= 中使用在 OS 启动时分配给接口的主 IP 地址]配置?
我正在尝试使用 keepalived 配置两个主动负载平衡器服务器。
它与标准配置略有不同,我们有两台服务器和一个虚拟 IP。
我想要的只是当 loadbalancer_1 关闭时,然后 loadbalancer_2 获取他的 IP 地址,反之亦然。
loadbalancer_1 IP 地址:xx.237.193.132/27 loadbalancer_2 IP 地址:xx.237.193.134/27
当我第一次启动loadbalancer_1时,它也需要loadbalancer_2 IP地址,因为在那个特定时刻 keepalived 尚未在 loadbalancer_2 上启动。 但是当我开始 loadbalancer_2 时,他的 IP 地址仍然在 loadbalancer_1 上。所以,loadbalancer_1。是两个 IP 地址的主机。
同样的情况,当我先启动loadbalancer_2时,所以那些较早启动的服务器将成为两个IP地址的主服务器。
登录loadbalancer_1:
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Registering Kernel netlink reflector
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Registering Kernel netlink command channel
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Registering gratuitous ARP shared channel
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Opening file '/etc/keepalived/keepalived.conf'.
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Registering Kernel netlink reflector
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Registering Kernel netlink command channel
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Opening file '/etc/keepalived/keepalived.conf'.
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Configuration is using : 71869 Bytes
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: Using LinkWatch kernel netlink reflector...
Jul 19 19:18:00 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_2) Entering BACKUP STATE
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Configuration is using : 12587 Bytes
Jul 19 19:18:00 001 Keepalived_healthcheckers[9750]: Using LinkWatch kernel netlink reflector...
Jul 19 19:18:01 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_1) Transition to MASTER STATE
Jul 19 19:18:02 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_1) Entering MASTER STATE
Jul 19 19:18:04 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_2) Transition to MASTER STATE
Jul 19 19:18:05 001 Keepalived_vrrp[9751]: VRRP_Instance(web_loadbalancer_2) Entering MASTER STATE
登录loadbalancer_2:
Jul 19 19:18:08 002 Keepalived_vrrp[468]: Registering Kernel netlink reflector
Jul 19 19:18:08 002 Keepalived_vrrp[468]: Registering Kernel netlink command channel
Jul 19 19:18:08 002 Keepalived_vrrp[468]: Registering gratuitous ARP shared channel
Jul 19 19:18:08 002 Keepalived_vrrp[468]: Opening file '/etc/keepalived/keepalived.conf'.
Jul 19 19:18:08 022 Keepalived_vrrp[468]: Configuration is using : 71869 Bytes
Jul 19 19:18:08 002 Keepalived_vrrp[468]: Using LinkWatch kernel netlink reflector...
Jul 19 19:18:08 002 Keepalived_vrrp[468]: VRRP_Instance(web_loadbalancer_1) Entering BACKUP STATE
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Registering Kernel netlink reflector
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Registering Kernel netlink command channel
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Opening file '/etc/keepalived/keepalived.conf'.
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Configuration is using : 12587 Bytes
Jul 19 19:18:08 002 Keepalived_healthcheckers[467]: Using LinkWatch kernel netlink reflector...
Jul 19 19:18:09 002 Keepalived_vrrp[468]: VRRP_Instance(web_loadbalancer_2) Transition to MASTER STATE
Jul 19 19:18:10 002 Keepalived_vrrp[468]: VRRP_Instance(web_loadbalancer_2) Entering MASTER STATE
Jul 19 19:18:11 002 Keepalived_vrrp[468]: VRRP_Instance(web_loadbalancer_2) Received lower prio advert, forcing new election
loadbalancer_1的配置:
global_defs {
router_id loadbalancer_1
lvs_id loadbalancer_1
}
vrrp_instance web_loadbalancer_1 {
state MASTER
interface eth0
virtual_router_id 10
priority 110
advert_int 1
virtual_ipaddress {
xx.237.193.132/27 dev eth0
}
authentication {
auth_type PASS
auth_pass 45f3fgv1
}
}
vrrp_instance web_loadbalancer_2 {
state BACKUP
interface eth0
virtual_router_id 20
priority 200
smtp_alert
advert_int 1
virtual_ipaddress {
xx.237.193.134/27 dev eth0
}
authentication {
auth_type PASS
auth_pass 45f3fgv2
}
}
loadbalancer_2的配置:
global_defs {
router_id loadbalancer_2
lvs_id loadbalancer_2
}
vrrp_instance web_loadbalancer_1 {
state BACKUP
interface eth0
virtual_router_id 10
priority 100
advert_int 1
virtual_ipaddress {
xx.237.193.132/27 dev eth0
}
authentication {
auth_type PASS
auth_pass 45f3fgv1
}
}
vrrp_instance web_loadbalancer_2 {
state MASTER
interface eth0
virtual_router_id 20
priority 210
advert_int 1
virtual_ipaddress {
xx.237.193.134/27 dev eth0
}
authentication {
auth_type PASS
auth_pass 45f3fgv2
}
}
我建议在两个 MASTER 部分添加 preempt_delay 10。
查看服务器 2 的最后一个日志条目
Jul 19 19:18:11 002 Keepalived_vrrp[468]: VRRP_Instance(web_loadbalancer_2) Received lower prio advert, forcing new election
好像它刚刚意识到它可以接管VRRP master。如果这没有发生,也许稍后会查看日志。
第一台服务器启动是正常的,因为没有其他服务器,假设主服务器,然后当第二台服务器激活时,vrrp 重新选举应该选择配置最高优先级的服务器。
问题被我解决了。 最初在 eth0 接口上有一个主 IP 地址(lb_1 和 lb_2),我在 keepalived 配置中使用了它们。
On loadbalancer_1 : xx.237.193.132/27
On loadbalancer_2 : xx.237.193.134/27
然后我刚刚编辑了一个 keepalived 配置并将这些 IP 地址替换为同一子网中的其他 IP 地址:
For loadbalancer_1 : xx.237.193.150/27
For loadbalancer_2 : xx.237.193.151/27
因此,当系统启动时,eth0 将使用旧的主 IP 地址进行初始化,但 keepalived 将使用其他虚拟 IP-来自同一子网的地址。 我不知道为什么第一个解决方案不起作用,我没有在任何地方找到解释或要求。
有谁能解释问题出在哪里,以及为什么我不能在 keepalived[=28= 中使用在 OS 启动时分配给接口的主 IP 地址]配置?