连接两个OpenVZ内部networking,以便容器可以互相看到

我有两个OpenVZ主机上有容器。 这是目前的布局:

主机-A 🙁 eth0(连接到互联网),eth1(连接到主机-B))

Host-B:(eth0(连接到互联网),eth1(连接到主机-A))

Host-A和Host-B上都有OpenVZ容器。 Host-A和Host-B有一个公有IPv4地址(每个),容器没有公有IP,它们需要位于内部专用networking上。

如何configurationnetworking,使两台主机上的容器可以互相通信并访问互联网。

在SF上得到绝大多数的反应之后,我做了自己的研究,发现了它。 我就是这么做的

组态

-SSH到主机A并更新/ etc / network / interfaces如下:

auto lo iface lo inet loopback iface eth1 inet manual auto vmbr1 iface vmbr1 inet static address 10.0.2.99 netmask 255.255.255.0 bridge_ports eth1 bridge_stp off bridge_fd 0 auto eth0 iface eth0 inet static address public_ip_here netmask 255.255.255.0 gateway public_ip_gateway_here auto vmbr0 iface vmbr0 inet static address 10.0.1.1 netmask 255.255.255.0 bridge_ports none bridge_stp off bridge_fd 0 post-up echo 1 > /proc/sys/net/ipv4/ip_forward post-up iptables -t nat -A POSTROUTING -s '10.0.1.0/24' -o eth0 -j MASQUERADE post-down iptables -t nat -D POSTROUTING -s '10.0.1.0/24' -o eth0 -j MASQUERADE 

-SSH到主机B和更新/ etc / network / interfaces如下:

 auto lo iface lo inet loopback iface eth1 inet manual auto vmbr1 iface vmbr1 inet static address 10.0.2.199 netmask 255.255.255.0 bridge_ports eth1 bridge_stp off bridge_fd 0 auto eth0 iface eth0 inet static address public_ip_here netmask 255.255.255.0 gateway public_ip_gateway_here auto vmbr0 iface vmbr0 inet static address 10.0.1.1 netmask 255.255.255.0 bridge_ports none bridge_stp off bridge_fd 0 post-up echo 1 > /proc/sys/net/ipv4/ip_forward post-up iptables -t nat -A POSTROUTING -s '10.0.1.0/24' -o eth0 -j MASQUERADE post-down iptables -t nat -D POSTROUTING -s '10.0.1.0/24' -o eth0 -j MASQUERADE 

在所有新容器中,创buildeth0( – > vmbr0)和eth1( – > vmbr1),并为每个eth接口分配一个来自相应块的静态IP。

– 在所有新容器中,确保默认路由指向10.0.1.1,否则,相应地更新容器中的networkingconfiguration文件。

服务器networking拓扑:

  • 主机A(eth0:公网IP,vmbr0:10.0.1.0/24)(eth1 / vmbr1:10.0.2.99/24)

  • 主机B(eth0:公网IP,vmbr0:10.0.1.0/24)(eth1 / vmbr1:10.0.2.199/24)

  • 容器(eth0-mapped-to-vmbr0:10.0.1。[CT#] / 24)(eth1-mapped-to-vmbr1:10.0.2。[CT#if host-a,else CT#+ 100 ] / 24)

  • 两台主机上的容器在10.0.1.x IP块中可以具有相同的IP,但不在10.0.2.x IP块中

示例容器configuration:

  • 主机A上的容器#100(eth0-> vmbr0:10.0.1.100/24,网关:10.0.1.1)(eth1-> vmbr1:10.0.2.100/24,网关:10.0.2.99)

  • 主机B上的容器#100(eth0-> vmbr0:10.0.1.100/24,网关:10.0.1.1)(eth1-> vmbr1:10.0.2.200/24,网关:10.0.2.199)

  • 主机A上的容器#101(eth0-> vmbr0:10.0.1.101/24,网关:10.0.1.1)(eth1-> vmbr1:10.0.2.101/24,网关:10.0.2.99)

  • 主机B上的容器#101(eth0-> vmbr0:10.0.1.101/24,网关:10.0.1.1)(eth1-> vmbr1:10.0.2.201/24,网关:10.0.2.199)