带有 vxlan 的双节点 Libvirt 集群

带有 vxlan 的双节点 Libvirt 集群

我有两个物理 Ubuntu 节点,NodeA 和 NodeB。

在每个节点上,我希望在它们自己的专用子网内托管 libvirt 客户端。NodeA 的客户端网络是 192.168.1.0/24,NodeB 的客户端网络是 192.168.2.0/24。

我需要 NodeA 中的客人能够 ping/联系 NodeB 中的客人,反之亦然。

我在每个节点上都有一个 vxlan 接口,172.16.1.1/24 分配给 NodeA 上的 vxlan 接口,172.16.1.2/24 分配给 NodeB 上的 vxlan 接口。NodeA 的 vxlan 地址可以从 NodeB ping 通,反之亦然。

我该如何配置路由,以便每个节点的访客可以互相 ping 通?是否可以在每个访客网络上使用 libvirt 的内置 dhcp 功能?

答案1

看起来,使用两侧的“路由”虚拟网络来容纳客户机接口是可行的简单配置。(如果它们当前处于 NAT 中,则必须添加一些端口转发,这通常是可行的,但如果使用许多端口,则可能会很复杂)。

假设网络接口位于“路由”网络上,您只需在两侧添加路由:

节点A:

  • ip route 通过 172.16.1.2/24 dev eth0 添加 192.168.2.0/24

    (将 nodeA 中的 eth0 替换为你的接口名称)

节点B:

  • ip route 通过 172.16.1.1/24 dev eth0 添加 192.168.1.0/24

    (将 nodeA 中的 eth0 替换为你的接口名称)

答案2

通过删除几个 iptables 规则,我能够实现我的需要。

我保留了 NAT 类型的客户网络,并向 libvirt 添加了一些钩子:

在 /etc/libvirt/hooks/网络:

#!/usr/bin/env bash

# /etc/libvirt/hooks/network
# https://www.libvirt.org/hooks.html
if [[ "$2" == "started" || "$2" == "plugged" || "$2" == "updated" ]] ; then
  /sbin/iptables -D FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable || true
  /sbin/iptables -D FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable || true
fi

在 /etc/libvirt/hooks/守护进程中:

#!/usr/bin/env bash

if [[ "${2}" == "start" ]] ; then
  # add interface
  ip link add vxlan0 type vxlan id 10 dev enp0s31f6 dstport 4789
  # remote peer
  bridge fdb append to 00:00:00:00:00:00 dst <remote ip> dev vxlan0
  # configure IP
  ip addr add 172.16.1.1/24 dev vxlan0
  # bring up interface
  ip link set up dev vxlan0
  # add route 
  ip route add 192.168.2.0/24 via 172.16.1.2
fi

if [[ "${2}" == "shutdown" ]] ; then
  # take down interface
  ip link set dev vxlan0 down
  # remove interface
  ip link del vxlan0
fi

相关内容