Debian

systemd-networkd.service 和 networking.service 在全新安裝時在重新啟動時交替啟動

  • March 24, 2021

我在伺服器提供商 OVH 提供的 Debian Buster 模板上安裝了 LEMP Web 伺服器。

伺服器存在連接問題:有時 ping 會失去,然後需要 OVH 技術人員進行硬重啟。

我從頭開始重新安裝了作業系統模板三次。我執行了處理器和記憶體測試,結果正常。我執行了文件系統檢查由於上周大火摧毀了一個數據中心,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 還是網路?
  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 連續版本之間的網路配置更改使學習恕我直言更加困難。

只供您/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 wki: systemd- networkd

Debian wiki:systemd-networkd

引用自:https://unix.stackexchange.com/questions/639764