我有一组服务器登陆到局域网.我能够在机器上安装和使用LXD容器,但是对于我来说,我无法在网络上看到容器.我试图关注这些网址,但无济于事:
我的服务器设置如下:
如果我尝试通过lxdbr0在eth1设备上设置网桥,则容器在LAN上不可见.如果我尝试br0手动设置桥接设备,桥接到eth1并使用DHCP,则设备无法启动.
我的/ etc/network/interfaces看起来像这样:
iface lo inet loopback
# The primary network interface
iface eth0 inet static
address x.x.x.x
netmask 255.255.255.224
gateway x.x.x.x
iface eth1 inet static
address 192.168.0.61/23
iface br0 inet dhcp
bridge_ports eth1
bridge-ifaces eth1
bridge_stp off
bridge_fd 0
bridge_maxwait 0
auto lo eth0 eth1 br0
Run Code Online (Sandbox Code Playgroud)
是否可以创建在LAN上可见的容器并可以连接到Internet?
UXntu 16.04上的LXD v2.7
是的,这很有可能.我没有玩过LXD 2.3中引入的所有新网络功能,所以我不能说任何一个,但看起来你想要一个非常简单的网络布局,所以这些功能甚至可能都没有发挥作用.我做了一些类似于你的网络布局的事情.我的所有服务器都有4个NIC.前两个我放入一个债券并放在我的管理网络上,后两个我放入一个LAG(另一个债券)并用于所有LXD流量.我有多个VLAN,所以我的LAG设置为中继端口,我为每个想要连接的VLAN创建VLAN设备.然后我将这些VLAN设备放入实际容器使用的桥接器中.
取消所有绑定和原始VLAN设备,您基本上具有相同的设置:一个用于管理LXD主机的NIC,一个用于LXD容器流量的桥接器.我不使用默认的lxcbr0设备,但所有概念都应该相同.
首先定义将成为网桥一部分的NIC或NIC.在您的情况下,您似乎只使用一个NIC(eth1).您需要将NIC设置为手动.不要为其分配地址.
auto eth1
iface eth1 inet manual
Run Code Online (Sandbox Code Playgroud)
接下来定义你的桥,我不会在这里定义一个IP地址.我更喜欢将所有容器IP分配到容器内.将桥接设置为手动.当容器启动时,它将启动设备.
auto br0
iface br0 inet manual
bridge_ports eth1
bridge_stp off
bridge_fd 0
bridge_maxwait 0
Run Code Online (Sandbox Code Playgroud)
现在,您只需在容器的配置文件中使用此桥.
lxduser@lxdhost:~$ lxc profile show default
name: default
config: {}
description: ""
devices:
eth0:
name: eth0
nictype: bridged
parent: br0
Run Code Online (Sandbox Code Playgroud)
现在启动容器并编辑网络配置.例如,在基于Debian的系统中,您可以编辑/ etc/network/interfaces(在容器中).在基于Red Hat的系统中,您可以编辑/ etc/sysconfig/network-scripts/ifcfg-eth0(在容器中).这是Debian的例子.
auto eth0
iface eth0 inet dhcp
Run Code Online (Sandbox Code Playgroud)
只要DHCP在网络上工作,即插入了eth1(在您的LXD主机上),那么容器应该获得一个地址并可在该网络上路由.为了获得互联网访问,必须将eth1插入具有Internet访问权限的子网,它不依赖于容器.
如果您想将容器放在不同的VLAN上,想要在主机上或两者都容错,那么这需要更多的设置.我在LXD主机上使用下面的配置文件.
############################
# PHYSICAL NETWORK DEVICES #
############################
# Management network interface
auto enp2s0f0
iface enp2s0f0 inet static
address 10.1.31.36/24
gateway 10.1.31.1
dns-nameserver 10.1.30.2 10.1.30.3 75.75.75.75
dns-search harmonywave.com
#iface enp2s0f0 inet6 dhcp
# Second network interface
auto enp2s0f1
iface enp2s0f1 inet manual
# LXD slave interface (1)
auto enp3s0f0
iface enp3s0f0 inet manual
bond-master bond1
# LXD slave interface (2)
auto enp3s0f1
iface enp3s0f1 inet manual
bond-master bond1
##########################
# BONDED NETWORK DEVICES #
##########################
# Bond network device
auto bond1
iface bond1 inet manual
bond-mode 4
bond-miimon 100
bond-lacp-rate 1
bond-slaves enp3s0f0 enp3s0f1
bond-downdelay 400
bond-updelay 800
####################
# RAW VLAN DEVICES #
####################
# Tagged traffic on bond1 for VLAN 10
iface bond1.10 inet manual
vlan-raw-device bond1
# Tagged traffic on bond1 for VLAN 20
iface bond1.20 inet manual
vlan-raw-device bond1
# Tagged traffic on bond1 for VLAN 30
iface bond1.30 inet manual
vlan-raw-device bond1
# Tagged traffic on bond1 for VLAN 31
iface bond1.31 inet manual
vlan-raw-device bond1
# Tagged traffic on bond1 for VLAN 42
iface bond1.42 inet manual
vlan-raw-device bond1
# Tagged traffic on bond1 for VLAN 50
iface bond1.50 inet manual
vlan-raw-device bond1
# Tagged traffic on bond1 for VLAN 90
iface bond1.90 inet manual
vlan-raw-device bond1
##########################
# BRIDGE NETWORK DEVICES #
##########################
# Bridged interface for VLAN 10
auto br0-10
iface br0-10 inet manual
bridge_ports bond1.10
bridge_stp off
bridge_fd 0
bridge_maxwait 0
# Bridged interface for VLAN 20
auto br0-20
iface br0-20 inet manual
bridge_ports bond1.20
bridge_stp off
bridge_fd 0
bridge_maxwait 0
# Bridged interface for VLAN 30
auto br0-30
iface br0-30 inet manual
bridge_ports bond1.30
bridge_stp off
bridge_fd 0
bridge_maxwait 0
# Bridged interface for VLAN 31
auto br0-31
iface br0-31 inet manual
bridge_ports bond1.31
bridge_stp off
bridge_fd 0
bridge_maxwait 0
# Bridged interface for VLAN 42
auto br0-42
iface br0-42 inet manual
bridge_ports bond1.42
bridge_stp off
bridge_fd 0
bridge_maxwait 0
# Bridged interface for VLAN 50
auto br0-50
iface br0-50 inet manual
bridge_ports bond1.50
bridge_stp off
bridge_fd 0
bridge_maxwait 0
# Bridged interface for VLAN 90
auto br0-90
iface br0-90 inet manual
bridge_ports bond1.90
bridge_stp off
bridge_fd 0
bridge_maxwait 0
Run Code Online (Sandbox Code Playgroud)
让我们打破这个.首先,我定义了物理网卡.这是一PHYSICAL NETWORK DEVICES节.我和你的第一个NIC没有什么不同(eth0对你来说是enp2s0f0).我只是静态地定义它并给它一个地址.我在管理网络上为此NIC分配了一个地址.第三个和第四个NIC用于容器流量.我想在LAG中使用LACP,因此我将设备定义为手动并使它们成为"bond1"的从属设备.
接下来我定义我的绑定设备.这是一BONDED NETWORK DEVICES节.在这种情况下,只是容器流量的一个债券.再次,我将其设置为手动并将绑定模式定义为4(LACP).可以轻松设置不同类型的键(主动 - 被动,主动 - 主动等).
接下来,因为我将第三个和第四个NIC物理连接到交换机上的中继端口,所以我必须指定dot1Q以便实际标记流量.我为容器可能处于的每个VLAN创建一个原始VLAN设备.我附加.XX,其中"XX"是VLAN ID.这不再是必要了,我这样做是为了便于识别.然后使用"vlan-raw-device"节标记设备.这是一RAW VLAN DEVICES节.
最后,在本BRIDGE NETWORK DEVICES节中,我为每个VLAN设备创建了网桥.这就是容器实际使用的内容.同样,我将其设置为手动,并且不定义在容器内定义的IP地址.
现在,我所要做的就是将所需的VLAN分配给容器.为简单起见并避免配置每个容器,我只为每个网桥/ VLAN创建一个配置文件.例如,这是我的VLAN 31的配置文件.
lxduser@lxdhost:~$ lxc profile show 31_vlan_int_server
name: 31_vlan_int_server
config: {}
description: ""
devices:
eth0:
name: eth0
nictype: bridged
parent: br0-31
type: nic
Run Code Online (Sandbox Code Playgroud)
然后我只是将此配置文件分配给我想要在VLAN 31上的任何容器.此时我可以将容器的/ etc/network/interfaces文件设置为dhcp(如果在该VLAN上启用了DHCP)或者为其提供一个静态IP地址是该VLAN的一部分.
整个网络布局看起来像这样.
容器使用桥内的veth设备(LXD创建).主机也将原始vlan设备添加到网桥,它们都使用实际的绑定设备,后者又使用物理网卡.
最后,关于您无法连接到互联网的问题,请确保您的容器所使用的网桥具有互联网访问权限.我喜欢采取逐步的故障排除方法.
ping 8.8.8.8)吗?
ping www.google.com吗(试试)?
如果一切正常,那么您应该能够连接容器(将网桥设置为手动并删除静态IP后).如果没有,则获取容器上的地址(静态或DHCP)并重复步骤1中的子步骤.
| 归档时间: |
|
| 查看次数: |
6095 次 |
| 最近记录: |