systemd-networkd.service 和networking.service 在全新安装时重新启动时交替激活

systemd-networkd.service 和networking.service 在全新安装时重新启动时交替激活

我在我的 Debian Buster 模板上安装了 LEMP Web 服务器服务器提供商OVH

服务器存在连接问题:有时会丢失 ping,然后需要 OVH 技术人员进行硬重启。

重新安装操作系统模板从头开始三遍。我运行处理器和内存测试结果OK。我运行文件系统检查。 OVH 支持已超额预订且无法联系,由于上周摧毁了数据中心的大火...,这样我就无法从那里获取任何信息。

然后我意识到systemd-networkd.service并且networking.service 或者在重新启动时处于活动状态。以下是机器的一些输出示例。

昨天硬重启之前,仍然在 ssh 中连接:

   root@srv:~# systemctl | grep network
      cloud-init-local.service  loaded active exited    Initial cloud-init job (pre-networking)                                      
    ● networking.service        loaded failed failed    Raise network interfaces                                                     
      network-online.target     loaded active active    Network is Online                                                            
      network-pre.target        loaded active active    Network (Pre)                                                                
      network.target            loaded active active    Network

root@srv:~# systemctl status networking.service 
    ● networking.service - Raise network interfaces
       Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
       Active: failed (Result: exit-code) since Mon 2021-03-15 10:32:32 CET; 2h 24min ago
         Docs: man:interfaces(5)
      Process: 710 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)
     Main PID: 710 (code=exited, status=1/FAILURE)
    
    Mar 15 10:32:31 srv dhclient[747]: DHCPREQUEST for 111.222.333.213 on enp3s0f0 to 255.255.255.255 port 67
    Mar 15 10:32:31 srv dhclient[747]: DHCPACK of 111.222.333.213 from 111.222.333.253
    Mar 15 10:32:32 srv ifup[710]: /etc/resolvconf/update.d/libc: Warning: /etc/resolv.conf is not a symbolic link to /etc/resolvconf/run/resolv.conf
    Mar 15 10:32:32 srv dhclient[747]: bound to 111.222.333.213 -- renewal in 40762 seconds.
    Mar 15 10:32:32 srv ifup[710]: bound to 111.222.333.213 -- renewal in 40762 seconds.
    Mar 15 10:32:32 srv ifup[710]: RTNETLINK answers: File exists
    Mar 15 10:32:32 srv ifup[710]: ifup: failed to bring up enp3s0f0
    Mar 15 10:32:32 srv systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
    Mar 15 10:32:32 srv systemd[1]: networking.service: Failed with result 'exit-code'.
    Mar 15 10:32:32 srv systemd[1]: Failed to start Raise network interfaces.

昨天硬重启后:

root@srv:/etc/systemd/network# systemctl | grep network
cloud-init-local.service                                                                                         loaded active exited    Initial cloud-init job (pre-networking)                                      
networking.service                                                                                               loaded active exited    Raise network interfaces                                                     
network-online.target                                                                                            loaded active active    Network is Online                                                            
network-pre.target                                                                                               loaded active active    Network (Pre)                                                                
network.target                                                                                                   loaded active active    Network


root@srv:/etc/systemd/network# systemctl status networking.service 
● networking.service - Raise network interfaces
   Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
   Active: active (exited) since Tue 2021-03-16 13:53:25 CET; 1 day 1h ago
     Docs: man:interfaces(5)
 Main PID: 714 (code=exited, status=0/SUCCESS)
    Tasks: 1 (limit: 4915)
   Memory: 14.3M
   CGroup: /system.slice/networking.service
           └─751 /sbin/dhclient -4 -v -i -pf /run/dhclient.enp3s0f0.pid -lf /var/lib/dhcp/dhclient.enp3s0f0.leases -I -df /var/lib/dhcp/dhclient6.enp3s0f0.leases enp3s0f0

root@srv:/etc/systemd/network# systemctl status systemd-networkd
● systemd-networkd.service - Network Service
   Loaded: loaded (/lib/systemd/system/systemd-networkd.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:systemd-networkd.service(8)

网络配置

root@srv:~# ls /etc/network/
if-down.d  if-post-down.d  if-pre-up.d  if-up.d  interfaces  interfaces.d

root@srv:~# cat /etc/network/interfaces
auto lo
iface lo inet loopback

# The normal eth0
allow-hotplug eth0
iface eth0 inet dhcp

# Additional interfaces, just in case we're using multiple networks
allow-hotplug eth1
iface eth1 inet dhcp

allow-hotplug eth2
iface eth2 inet dhcp

# Set this one last, so that cloud-init or user can defaults.
source /etc/network/interfaces.d/*

root@srv:~# ls /etc/network/interfaces.d/
50-cloud-init

root@srv:~# cat /etc/network/interfaces.d/50-cloud-init      
# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
auto lo
iface lo inet loopback

auto enp3s0f0
iface enp3s0f0 inet dhcp
    accept_ra 0

# control-alias enp3s0f0
iface enp3s0f0 inet6 static
    address 2001:abcd:1007:efgh::/56
    dns-nameservers 2001:abcd:3:163::1
    gateway 2001:abcd:1007:1dff:ff:ff:ff:ff
    post-up route add -A inet6 2001:abcd:1007:ef00::/57 gw 2001:abcd:1007:1dff:ff:ff:ff:ff || true
    pre-down route del -A inet6 2001:abcd:1007:ef00::/57 gw 2001:abcd:1007:1dff:ff:ff:ff:ff || true

[... plus about fifty similar lines ...]

root@srv:~# ls /etc/systemd/network

root@srv:~# ls /lib/systemd/network
80-container-host0.network  80-container-ve.network  80-container-vz.network  99-default.link

问题

  1. 该配置中的某些内容可能会导致连接经常丢失吗?

  2. 如何确保始终使用相同的服务(systemd.networkd 或networking)重新启动?

  3. 在丛林中的哪里添加我的静态 IP?

我可以将以下内容添加到文件中/etc/systemd/network/(目前为空),但这意味着尝试启动 systemd.networkd 并停止另一个,不确定我是否可以从远程 ssh 执行此操作...,如果服务是正确设置!

nano /etc/systemd/network/50-default.network

[Address]
Address=FAILOVER_IP/32
Label=failover1 # optional

或者更好地添加类似的东西/etc/network/interfaces并重新启动networking.service

auto eth0:0
iface eth0:0 inet static
address STATIC_IP
netmask 255.255.255.255

auto eth0:1
iface eth0:1 inet static
address OTHER_STATIC_IP
netmask 255.255.255.255

多谢 !

旁注,所有网络配置都是由 OVH 在其模板中提供的,不幸的是我对该主题的了解非常有限。此外,Debian 连续版本之间的网络配置变化使得学习恕我直言变得更加困难。

答案1

仅在您的/etc/network/interfaces城堡内:

#source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback

5.3.无需 GUI 的现代网络配置配置静态或 DHCP 网络配置。例如:

/etc/systemd/network/10-dhcp-enp3s0f0.network:

[Match]
Name=enp3s0f0

[Network]
DHCP=yes

/etc/systemd/network/10-static-eth0-0.network:

[Match]
Name=eth0:0

[Network]
Address=STATIC_IP
Gateway=gatway_here
DNS=dns_here

你有一个警告:

    Mar 15 10:32:32 srv ifup[710]: /etc/resolvconf/update.d/libc: Warning: /etc/resolv.conf is not a symbolic link to /etc/resolvconf/run/resolv.conf

可以通过以下方式解决:

ln -s  /etc/resolvconf/run/resolv.conf /etc/resolv.conf

Archlinux 维基:systemd-networkd

Debian 维基:systemd-networkd

答案2

我将@GAD3R 答案标记为已接受,因为这似乎是处理此问题的现代方法。

然而,最终我坚持使用旧的设置,只是添加了一个enp3s0f0文件,其中/etc/network/interfaces.d包含我的静态 IP 的以下配置:

auto enp3s0f0:1
iface enp3s0f0:1 inet static
address aaa.bb.cc.232/29

auto enp3s0f0:2
iface enp3s0f0:2 inet static
address aaa.bb.cc.233/29

auto enp3s0f0:3
iface enp3s0f0:3 inet static
address aaa.bb.cc.234/29

[...]

然后重新启动networking.service

最后,不确定修复丢失的符号链接ln -s /etc/resolvconf/run/resolv.conf /etc/resolv.conf是否足够,但我几天前重新启动,但我不再尝试网络问题。

相关内容