我们有一个运行 Debian 10 的 ESXi 虚拟机,遇到了 postfix 启动过早的问题。这导致在 postfix chroot 之前未填充 resolv.conf 的问题。我已确保
- /lib/systemd/system/postfix.service
- /lib/systemd/系统/[电子邮件保护]
文件有行
After=network-online.target nss-lookup.target
但是,我们在此虚拟机中安装了多个网卡,/etc/network/interfaces 文件包含
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug ens192
iface ens192 inet static
address 10.1.0.29/21
dns-nameservers 10.1.0.20 10.1.0.23
# The secondary network interface
allow-hotplug ens224
iface ens224 inet static
address 192.168.1.8/24
gateway 192.168.1.240
当我跑步时
grep -E "(Postfix Mail Transport Agent|e1000|Link is Up|link is not ready|link becomes ready|resolv.conf differ|target)" /var/log/syslog
我看到 network-online.target 仅等待其中一个网卡在线。
Jan 12 18:46:54 assp0 kernel: [ 1.738897] e1000e: Intel(R) PRO/1000 Network Driver - 3.2.6-k
Jan 12 18:46:54 assp0 kernel: [ 1.738897] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
Jan 12 18:46:54 assp0 kernel: [ 1.739922] e1000e 0000:0b:00.0: Interrupt Throttling Rate (ints/sec) set to dynamic conservative mode
Jan 12 18:46:54 assp0 kernel: [ 1.795419] e1000e 0000:0b:00.0 0000:0b:00.0 (uninitialized): registered PHC clock
Jan 12 18:46:54 assp0 kernel: [ 1.859484] e1000e 0000:0b:00.0 eth0: (PCI Express:2.5GT/s:Width x1)
Jan 12 18:46:54 assp0 kernel: [ 1.859486] e1000e 0000:0b:00.0 eth0: Intel(R) PRO/1000 Network Connection
Jan 12 18:46:54 assp0 kernel: [ 1.859558] e1000e 0000:0b:00.0 eth0: MAC: 3, PHY: 8, PBA No: 000000-000
Jan 12 18:46:54 assp0 kernel: [ 1.860245] e1000e 0000:13:00.0: Interrupt Throttling Rate (ints/sec) set to dynamic conservative mode
Jan 12 18:46:54 assp0 kernel: [ 1.915403] e1000e 0000:13:00.0 0000:13:00.0 (uninitialized): registered PHC clock
Jan 12 18:46:54 assp0 kernel: [ 1.979239] e1000e 0000:13:00.0 eth1: (PCI Express:2.5GT/s:Width x1)
Jan 12 18:46:54 assp0 kernel: [ 1.979240] e1000e 0000:13:00.0 eth1: Intel(R) PRO/1000 Network Connection
Jan 12 18:46:54 assp0 kernel: [ 1.979290] e1000e 0000:13:00.0 eth1: MAC: 3, PHY: 8, PBA No: 000000-000
Jan 12 18:46:54 assp0 kernel: [ 1.981312] e1000e 0000:0b:00.0 ens192: renamed from eth0
Jan 12 18:46:54 assp0 kernel: [ 1.994070] e1000e 0000:13:00.0 ens224: renamed from eth1
Jan 12 18:46:54 assp0 kernel: [ 4.577652] IPv6: ADDRCONF(NETDEV_UP): ens224: link is not ready
Jan 12 18:46:54 assp0 kernel: [ 4.583595] e1000e: ens224 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
Jan 12 18:46:54 assp0 systemd[1]: Reached target Swap.
Jan 12 18:46:54 assp0 systemd[1]: Reached target System Initialization.
Jan 12 18:46:54 assp0 systemd[1]: Reached target Sockets.
Jan 12 18:46:54 assp0 systemd[1]: Reached target Basic System.
Jan 12 18:46:54 assp0 systemd[1]: Reached target Timers.
Jan 12 18:46:54 assp0 systemd[1]: Reached target Network.
Jan 12 18:46:54 assp0 systemd[1]: Reached target Network is Online.
Jan 12 18:46:54 assp0 systemd[1]: Starting Postfix Mail Transport Agent (instance -)...
Jan 12 18:46:54 assp0 systemd[1]: Reached target Login Prompts.
Jan 12 18:46:54 assp0 kernel: [ 4.671007] IPv6: ADDRCONF(NETDEV_UP): ens192: link is not ready
Jan 12 18:46:54 assp0 kernel: [ 4.671206] IPv6: ADDRCONF(NETDEV_CHANGE): ens224: link becomes ready
Jan 12 18:46:54 assp0 kernel: [ 4.675749] e1000e: ens192 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
Jan 12 18:46:54 assp0 kernel: [ 4.676553] IPv6: ADDRCONF(NETDEV_CHANGE): ens192: link becomes ready
Jan 12 18:46:55 assp0 postfix/postfix-script[750]: warning: /var/spool/postfix/etc/resolv.conf and /etc/resolv.conf differ
我认为您可以在网络配置中写入一些内容来表明在操作系统认为网络已启动之前需要连接,但我似乎找不到该信息。
在我将一些对我们足够有用的东西拼凑在一起之前,我想知道如何让 network-online.target 等待所有的网卡,或者最好是我指定的网卡。- 编辑 -我所说的问题在于增加了启动顺序的延迟。
编辑:我找到了一个我所想的链接,但它在 CentOS 中,并且是IPV4_FAILURE_FATAL=是行添加到其中一个 ifcfg 文件中。Debian 是否有类似的东西,您认为这会影响 systemd 目标的触发吗?
编辑:启用 systemd 网络服务看起来可能会有所帮助,当阅读有关systemd-networkd-wait-online.service。在我转换到使用网络管理器(networkd)配置设置之前,我是否读得正确并且它可以解决这个问题?
答案1
只要目标(我猜这取决于 RHEL 上的 network.service 或 NetworkManager.service)报告网络已启动,Systemd 就会自动假定网络已在线。我们遇到了一个问题,dnsmasq 报告它已启动,但实际上它需要一点时间才能提供 NFS 挂载服务。作为解决方法,您可以:
- 创建一个服务,它将在你的网络服务之后和你的 postfix 之前执行
- 在你的网络服务中设置延迟(可能是 PostExec 节)
- 通过 Postfix 服务中的“ExecStartPre=”条目创建“预启动延迟”
以下是 CentOS7 上 network.service 的一个示例:
# /run/systemd/generator.late/network.service
# Automatically generated by systemd-sysv-generator
[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/rc.d/init.d/network
Description=LSB: Bring up/down networking
Before=multi-user.target
Before=multi-user.target
Before=multi-user.target
Before=graphical.target
Before=network-online.target
Before=network.target
Before=vxpbx_exchanged.service
对于 2),您可以创建如下内容:
#cat /etc/systemd/system/network.service.d/01-delay.conf
[Service]
ExecStartPost=/bin/sleep 5
对于 3),您可以创建类似以下内容的内容:
#cat /etc/systemd/system/postfix.service.d/01-delay.conf
[Service]
ExecStartPre=/bin/sleep 5
当然,这些只是解决方法,需要通过错误来解决。