keepalived 配置无法与 virtualbox vms 正确配合使用

keepalived 配置无法与 virtualbox vms 正确配合使用

我的 keepalived 配置无法正常工作。

我有两台虚拟测试机 (virtualbox),用于尝试使用 keepalived/vrrp。Bot 可以完美地互相 ping 通(内部 virtualbox 网络)。

虚拟机 1 (主服务器):

eth0: Management
eth1: 192.168.2.1/24
eth2: 192.168.2.2/24

keepalived.conf:

vrrp_instance test {
state MASTER
interface eth1
track_interface {
        eth2
}
virtual_router_id 1
priority 101
advert_int 1
authentication {
        auth_type PASS
        auth_pass 1111
}
virtual_ipaddress {
        192.168.3.1/24 dev eth1
        192.168.3.2/24 dev eth2
}
}

tcpdump on eth1:

12:44:54.720119 IP 192.168.2.1 > vrrp.mcast.net: VRRPv2, Advertisement, vrid 1, prio 101, authtype simple, intvl 1s, length 24
12:44:55.049465 IP 192.168.2.3 > vrrp.mcast.net: VRRPv2, Advertisement, vrid 1, prio 100, authtype simple, intvl 1s, length 24

tcpdump on eth2:

12:46:21.082264 IP 192.168.2.1 > vrrp.mcast.net: VRRPv2, Advertisement, vrid 1, prio 101, authtype simple, intvl 1s, length 24
12:46:21.494239 IP 192.168.2.3 > vrrp.mcast.net: VRRPv2, Advertisement, vrid 1, prio 100, authtype simple, intvl 1s, length 24

VM 2(备份):

eth0: Management
eth1: 192.168.2.3/24
eth2: 192.168.2.4/24

keepalived.conf:

vrrp_instance test {
state BACKUP
interface eth1
track_interface {
        eth2
}
virtual_router_id 1
priority 100
advert_int 1
authentication {
        auth_type PASS
        auth_pass 1111
}
virtual_ipaddress {
        192.168.3.1/24 dev eth1
        192.168.3.2/24 dev eth2
}
}

tcpdump on eth1:

12:53:12.265456 IP 192.168.2.1 > vrrp.mcast.net: VRRPv2, Advertisement, vrid 1, prio 101, authtype simple, intvl 1s, length 24
12:53:12.670635 IP 192.168.2.3 > vrrp.mcast.net: VRRPv2, Advertisement, vrid 1, prio 100, authtype simple, intvl 1s, length 24

tcpdump on eth2:

12:53:34.397374 IP 192.168.2.1 > vrrp.mcast.net: VRRPv2, Advertisement, vrid 1, prio 101, authtype simple, intvl 1s, length 24
12:53:34.787327 IP 192.168.2.3 > vrrp.mcast.net: VRRPv2, Advertisement, vrid 1, prio 100, authtype simple, intvl 1s, length 24

在 VM 2 上启动 keepalived 后,它会立即转换到主状态,但事实并非如此。

为什么会发生这种情况?

答案1

eth1和是否eth2在同一个物理(虚拟物理)子网上?如果不是,那么每台主机上有两个不同的接口,IP 位于同一个子网上,并且你为位于同一个子网上的每个接口分配 IP,这似乎有点奇怪。我建议尝试:

VM 1: eth1 - 192.168.101.2/24, eth2 - 192.168.102.2/24
VM 2: eth1 - 192.168.101.3/24, eth2 - 192.168.102.3/24
VRRP: eth1 - 192.168.101.1/24, eth2 - 192.168.103.1/24

这会将每个接口上的地址放在相同的子网上,但与同一主机上的其他接口放在不同的子网上。我不确定这是否会导致问题,但似乎可能会,因为您的主机将有两个不同的设备路由到同一个子网,这可能会造成混淆keepalived和/或 VRRP。我认为这通常是您看到 VRRP 在 Cisco 路由器等设备上的工作方式 - 您会看到一个虚拟 IP 地址,然后是两个设备的物理 IP,所有这些都在同一个子网上。

文档中似乎推荐的另一件事keepalived是将优先级 50 左右的点分开 - 因此,将 MASTER 设置为 150,将 BACKUP 设置为 100。

相关内容