通过指定网络配置加速 21.04 服务器启动

通过指定网络配置加速 21.04 服务器启动

我最近在一些新硬件上安装了服务器 21.04。我在家里使用它,主要用于一些开发实验。

我不明白系统启动时发生的所有事情,但它花费的时间比我预期的要长得多。当我启动启动顺序时,我注意到一条消息比其他消息花费的时间要长得多:

Host and Network Name Lookups

下一行接着:

A start job is running for Wait for Network to be Configured

我猜这意味着服务器正在等待分配网络地址?这应该由我的 ISP 提供的调制解调器/wifi 盒来处理?它似乎可以毫无问题地处理所有其他有线和无线连接。

这是 ifconfig 的输出:

enp40s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.27  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 2a01:110f:1333:8500:2ef0:5dff:fe9d:f549  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::2ef0:5dff:fe9d:f549  prefixlen 64  scopeid 0x20<link>
        ether 2c:f0:5d:9d:f5:49  txqueuelen 1000  (Ethernet)
        RX packets 20947  bytes 28975249 (28.9 MB)
        RX errors 0  dropped 200  overruns 0  frame 0
        TX packets 9869  bytes 738607 (738.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

我无法详细阅读,但看起来还行?已授予 IP4 和 IP6 地址,我可以通过 IP4 地址或名称通过 SSH 连接到服务器。

这是 systemd-analyze 的输出:

Startup finished in 16.290s (firmware) + 5.242s (loader) + 4.306s (kernel) + 2min 3.331s (userspace) = 2min 29.171s 
graphical.target reached after 2min 3.111s in userspace

我想对于大多数系统来说,这在用户空间中太长了?

您能提出导致等待时间过长的原因吗?我该如何进一步调查?

如果这是由于等待分配名称和地址而导致的,我可以在 .conf 文件中手动指定这些地址吗?如果我在 DHCP 服务器上保留该地址,那应该不会造成任何进一步的问题,对吗?

编辑:这是输出cat /etc/netplan/*.yaml(该目录中只有一个文件):

# This is the network config written by 'subiquity'
network:
  ethernets:
    enp40s0:
      dhcp4: true
    enp42s0:
      dhcp4: true
  version: 2

这是的输出sudo lshw -C network

  *-network                 
       description: Ethernet interface
       product: RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
       vendor: Realtek Semiconductor Co., Ltd.
       physical id: 0
       bus info: pci@0000:28:00.0
       logical name: enp40s0
       version: 15
       serial: 2c:f0:5d:9d:f5:49
       size: 1Gbit/s
       capacity: 1Gbit/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress msix bus_master cap_list ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=r8169 driverversion=5.11.0-16-generic duplex=full firmware=rtl8168h-2_0.0.2 02/26/15 ip=192.168.1.27 latency=0 link=yes multicast=yes port=twisted pair speed=1Gbit/s
       resources: irq:37 ioport:e000(size=256) memory:fc604000-fc604fff memory:fc600000-fc603fff
  *-network
       description: Ethernet interface
       product: RTL8125 2.5GbE Controller
       vendor: Realtek Semiconductor Co., Ltd.
       physical id: 0
       bus info: pci@0000:2a:00.0
       logical name: enp42s0
       version: 04
       serial: 2c:f0:5d:9d:f5:48
       capacity: 1Gbit/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress msix vpd bus_master cap_list ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=r8169 driverversion=5.11.0-16-generic firmware=rtl8125b-2_0.0.2 07/13/20 latency=0 link=no multicast=yes port=twisted pair
       resources: irq:40 ioport:d000(size=256) memory:fc500000-fc50ffff memory:fc510000-fc513fff
  *-network:0
       description: Ethernet interface
       physical id: 1
       logical name: cali43ea770e11b
       serial: ee:ee:ee:ee:ee:ee
       size: 10Gbit/s
       capabilities: ethernet physical
       configuration: autonegotiation=off broadcast=yes driver=veth driverversion=1.0 duplex=full link=yes multicast=yes port=twisted pair speed=10Gbit/s
  *-network:1
       description: Ethernet interface
       physical id: 2
       logical name: vxlan.calico
       serial: 66:9b:20:93:4e:ac
       size: 1Gbit/s
       capacity: 1Gbit/s
       capabilities: ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=vxlan driverversion=0.1 duplex=full ip=10.1.50.0 link=yes multicast=yes port=twisted pair speed=1Gbit/s

该目录/etc/network/interfaces是空的。

答案1

试试这个 .yaml... 保持与我所拥有的完全一致... 相同的缩进、间距,没有制表符...

network:
  version: 2
  renderer: networkd
  ethernets:
    enp40s0:
      dhcp4: true
      optional: true
    enp42s0:
      dhcp4: true
      optional: true

sudo netplan generate

sudo netplan apply

reboot

相关内容