在 Ubuntu 18.04 上使用 netplan 配置绑定的 802.3ad 网络

在 Ubuntu 18.04 上使用 netplan 配置绑定的 802.3ad 网络

我在 Ubuntu 18.04 服务器上配置 netplan 以绑定使用 802.3ad 协议命名的四个硬件以太网端口时遇到了一些问题eno1, eno2, eno3, eno4。我咨询了 netplan手册页并整理以下配置文件/etc/netplan/50-cloud-init.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    eports:
      match: 
        name: eno*
  bonds:
    bond0:
      interfaces: [eports]
      addresses: [192.168.1.101/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]          
      parameters:
        mode: 802.3ad            
        lacp-rate: fast            
        mii-monitor-interval: 100

运行命令后sudo netplan --debug apply我收到以下信息:

** (generate:6473): DEBUG: 00:39:14.911: Processing input file //etc/netplan/50-cloud-init.yaml..
** (generate:6473): DEBUG: 00:39:14.911: starting new processing pass
** (generate:6473): DEBUG: 00:39:14.911: eports: setting default backend to 1
** (generate:6473): DEBUG: 00:39:14.911: bond0: setting default backend to 1
** (generate:6473): DEBUG: 00:39:14.912: Generating output files..
** (generate:6473): DEBUG: 00:39:14.912: NetworkManager: definition eports is not for us (backend 1)
** (generate:6473): DEBUG: 00:39:14.912: NetworkManager: definition bond0 is not for us (backend 1)
DEBUG:netplan generated networkd configuration exists, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:device eno2 operstate is up, not replugging
DEBUG:netplan triggering .link rules for eno2
DEBUG:device lo operstate is unknown, not replugging
DEBUG:netplan triggering .link rules for lo
DEBUG:replug eno3: unbinding 0000:03:00.0 from /sys/bus/pci/drivers/igb
DEBUG:replug eno3: rebinding 0000:03:00.0 to /sys/bus/pci/drivers/igb
DEBUG:replug eno1: unbinding 0000:01:00.0 from /sys/bus/pci/drivers/igb
DEBUG:replug eno1: rebinding 0000:01:00.0 to /sys/bus/pci/drivers/igb
DEBUG:Cannot replug bond0: cannot read link /sys/class/net/bond0/device: [Errno 2] No such file or directory: '/sys/class/net/bond0/device'
DEBUG:netplan triggering .link rules for bond0
DEBUG:replug eno4: unbinding 0000:04:00.0 from /sys/bus/pci/drivers/igb
DEBUG:replug eno4: rebinding 0000:04:00.0 to /sys/bus/pci/drivers/igb

我不知道该如何理解这句话

Cannot replug bond0: cannot read link /sys/class/net/bond0/device: [Errno 2] No such file or directory: '/sys/class/net/bond0/device'

因为该目录/sys/class/net/bond0是由命令生成的netplan apply

我检查了我的ifconfig输出,我的网络设备似乎配置正确,但没有设置地址bond0

bond0: flags=5123<UP,BROADCAST,MASTER,MULTICAST>  mtu 1500
    ether XX:XX:XX:XX:XX:XX  txqueuelen 1000  (Ethernet)
    RX packets 112768  bytes 7785014 (7.7 MB)
    RX errors 0  dropped 54  overruns 0  frame 0
    TX packets 18854  bytes 2337896 (2.3 MB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
    ether XX:XX:XX:XX:XX:XX  txqueuelen 1000  (Ethernet)
    RX packets 290  bytes 19322 (19.3 KB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 55  bytes 6820 (6.8 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    device memory 0xdf400000-df47ffff  

eno2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
    ether XX:XX:XX:XX:XX:XX  txqueuelen 1000  (Ethernet)
    RX packets 73991  bytes 29824155 (29.8 MB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 20848  bytes 2110417 (2.1 MB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    device memory 0xdf300000-df37ffff  

eno3: flags=6147<UP,BROADCAST,SLAVE,MULTICAST>  mtu 1500
    ether XX:XX:XX:XX:XX:XX  txqueuelen 1000  (Ethernet)
    RX packets 0  bytes 0 (0.0 B)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 0  bytes 0 (0.0 B)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    device memory 0xdf200000-df27ffff  

eno4: flags=6147<UP,BROADCAST,SLAVE,MULTICAST>  mtu 1500
    ether XX:XX:XX:XX:XX:XX  txqueuelen 1000  (Ethernet)
    RX packets 0  bytes 0 (0.0 B)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 0  bytes 0 (0.0 B)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    device memory 0xdf100000-df17ffff  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
    inet 127.0.0.1  netmask 255.0.0.0
    inet6 ::1  prefixlen 128  scopeid 0x10<host>
    loop  txqueuelen 1000  (Local Loopback)
    RX packets 2923  bytes 184477 (184.4 KB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 2923  bytes 184477 (184.4 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

这些ether XX:XX:XX:XX:XX:XX语句代替了每个接口的 mac 地址。在原始输出中,所有地址都是相同的。

我缺少什么来成功配置我的系统?

答案1

经过一番挖掘,我发现 Ubuntu 18.04 使用一个名为的实用程序cloud-init来处理启动过程中的网络配置和初始化。该文件/etc/cloud/cloud.cfg.d/50-curtin-networking.cfg和其他.cfg文件用于重新配置cloud-init设置。我的配置文件设置如下:

network:
  version: 2
  ethernets:
    eports:
      match:
        name: eno*
      optional: true
  bonds:
    bond0:
      interfaces: [eports]
      addresses: [192.168.1.101/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
      parameters:
        mode: 802.3ad
        lacp-rate: fast
        mii-monitor-interval: 100

optional: true参数可防止系统在启动时等待有效的网络连接,从而为您节省等待机器启动 2 分钟的麻烦。更新配置文件后,运行以下命令来更新您的配置。

cloud-init clean -reboot

或者,运行以下命令可以在不重新启动机器的情况下获取一些调试信息;但是,在早期启动阶段需要重新启动才能提交更改。

cloud-init clean
cloud-init init
cloud-init status 

答案2

netplan.io 网站似乎表明 cloud-init 是 netplan 配置的几个实用程序之一。netplan 的问题可能是您在指定稍后要绑定的物理接口时需要指定 dhcp4 = false。如果不这样做,DHCP 可能会在绑定之前将地址附加到各个接口。因此在绑定时会与现有的 IP 逻辑发生冲突。

我怀疑您的 cloud-init(在启动顺序中更早?)解决方法可能通过在 DHCP 进程发生之前绑定接口来工作。或者使用 clean/init 序列重置 DHCP 地址,然后在重新应用 DHCP 进程之前绑定。但是,这可能意味着如果维护人员对启动逻辑/顺序进行哪怕是微小的更改,解决方法也可能会停止工作。

相关内容