keepalived 配置无法与 virtualbox 虚拟机一起正常工作

car*_*rot 5 networking linux virtualbox vrrp keepalived

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

我有两台虚拟测试机(virtualbox)来尝试使用 keepalived/vrrp 进行一些操作。机器人可以完美地互相 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
Run Code Online (Sandbox Code Playgroud)

虚拟机 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
Run Code Online (Sandbox Code Playgroud)

在虚拟机 2 上启动 keepalived 后,它会立即转换到主状态,而这是不应该的。

为什么会发生这种情况?

小智 0

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
Run Code Online (Sandbox Code Playgroud)

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

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