即使在重新启动后更新单元文件,Apache2 也不会启动

即使在重新启动后更新单元文件,Apache2 也不会启动

问题:服务器重新启动后,apache2 不会自动启动(必须手动 ssh 并通过 systemctl 启动,启动时没有任何问题)

错误信息:

Feb 08 05:53:46 domain1_test.com systemd[1]: Starting The Apache HTTP Server...
Feb 08 05:53:47 domain1_test.com apachectl[834]: (99)Cannot assign requested address: AH00072: make_sock: could not bind to address [xxxx:xxxx::xxxx:xxxx:xxxx:xxxx]:80
Feb 08 05:53:47 domain1_test.com apachectl[834]: no listening sockets available, shutting down
Feb 08 05:53:47 domain1_test.com apachectl[834]: AH00015: Unable to open logs
Feb 08 05:53:47 domain1_test.com apachectl[809]: Action 'start' failed.
Feb 08 05:53:47 domain1_test.com apachectl[809]: The Apache error log may have more information.
Feb 08 05:53:47 domain1_test.com systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
Feb 08 05:53:47 domain1_test.com systemd[1]: apache2.service: Failed with result 'exit-code'.

当前的阿帕奇设置:

# port.conf
Listen xxx.xxx.xx.xx:80
Listen xxx.xxx.xx.xx:443

Listen [xxxx:xxxx::xxxx:xxxx:xxxx:xxxx]:80
Listen [xxxx:xxxx::xxxx:xxxx:xxxx:xxxx]:443

---

# domain1_VirtualHosts.conf
<VirtualHost xxx.xxx.xx.xx:80 [xxxx:xxxx::xxxx:xxxx:xxxx:xxxx]:80>
....
<VirtualHost xxx.xxx.xx.xx:443 [xxxx:xxxx::xxxx:xxxx:xxxx:xxxx]:443>

我已经测试过通过目标添加网络依赖项并希望在 apache2 单元文件中,但在重新启动后检查 apache2 状态时仍然收到无法绑定套接字错误

[Unit]
Description=The Apache HTTP Server
After=network.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
Documentation=https://httpd.apache.org/docs/2.4/

[Service]
Type=forking
Environment=APACHE_STARTED_BY_SYSTEMD=true
ExecStart=/usr/sbin/apachectl start
ExecStop=/usr/sbin/apachectl stop
ExecReload=/usr/sbin/apachectl graceful
PrivateTmp=true
Restart=on-abort

[Install]
WantedBy=multi-user.target

环境 :

  • 易诺德
  • Ubuntu 20.04.2 LTS
  • Apache/2.4.41
  • VirtualMin/webmin

接口配置:

iface eth0 inet dhcp

iface eth0 inet6 manual
        pre-up /sbin/modprobe -q ipv6 ; /bin/true

系统网络配置:

[Match]
Name=eth0

[Network]
DHCP=no
DNS=xxx.x.xx.xx xxx.xxx.xx.x xxx.xxx.xx.x
Domains=members.linode.com
IPv6PrivacyExtensions=false

Gateway=xxx.xxx.xx.x
Address=xxx.xxx.xx.xx/24

感谢有关此事的任何意见

答案1

这是由于接口获取 IPv6 地址的延迟造成的。一种解决方案是调用ExecStartPre=服务文件中的脚本,该脚本将通过紧密循环检查是否已提供。如(根据需要更改):

#!/bin/sh

for Secs in {1..60}
do
        ip addr show dev eth0 | grep -qi <IPv6 address> && echo Found in ${Secs} &&  exit 0
        sleep 1
done

echo "NOT FOUND after ${Secs} seconds"
exit 1 

我已经测试过该脚本可以工作,只是不在服务文件中。

相关内容