从 16.04 升级到 18.04 后 apache2 无法启动 - 没有错误消息

从 16.04 升级到 18.04 后 apache2 无法启动 - 没有错误消息

我刚刚将系统从 16.04 升级到 18.04。从那时起,apache2 就无法启动,但没有在任何地方(我能找到的地方)显示任何错误消息。

启动后立即的状态:

# systemctl status apache2
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; static; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
       └─apache2-systemd.conf
   Active: inactive (dead)
 Docs: man:systemd-sysv-generator(8)

如果我再次手动启动 apache2,则大约需要 5 分钟,然后我会收到来自 systemd 的超时错误:

# systemctl status apache2
● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; static; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: timeout) since Sun 2020-06-28 17:48:00 CEST; 1min 2s
     Docs: man:systemd-sysv-generator(8)
  Process: 1912 ExecStart=/etc/init.d/apache2 start (code=killed, signal=TERM)
    Tasks: 0 (limit: 4915)
   CGroup: /system.slice/apache2.service

Jun 28 17:43:00 server apache2[1912]:  * Starting Apache httpd web server apa
Jun 28 17:43:00 server apache2[1912]: Invoking 'systemctl start apache2'.
Jun 28 17:43:00 server apache2[1912]: Use 'systemctl status apache2' for more
Jun 28 17:48:00 server systemd[1]: apache2.service: Start operation timed out
Jun 28 17:48:00 server systemd[1]: apache2.service: Failed with result 'timeo
Jun 28 17:48:00 server systemd[1]: Failed to start LSB: Apache2 web server.
Jun 28 17:48:00 server apache2[1912]: Job for apache2.service failed because
Jun 28 17:48:00 server apache2[1912]: See "systemctl status apache2.service"
Jun 28 17:48:00 server apache2[1912]: Action 'start' failed.
Jun 28 17:48:00 server apache2[1912]: The Apache error log may have more info

没有写入 apache2 日志。

配置语法似乎仍然正确:

# apache2ctl -t
Syntax OK

80、443端口未被占用:

# netstat -tlpne | egrep ':(80|443)'
root@server:/var/www#

我尝试了 Debug LogLevel,但没有任何改变。

最后,我尝试了 strace,但输出并没有真正帮助我:

[lotsofstuffandthen]
[pid  3956] openat(AT_FDCWD, "/run/systemd/ask-password", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 6
[pid  3956] fstat(6, {st_mode=S_IFDIR|0755, st_size=40, ...}) = 0
[pid  3956] getdents(6, /* 2 entries */, 32768) = 48
[pid  3956] getdents(6, /* 0 entries */, 32768) = 0
[pid  3956] close(6)                    = 0
[pid  3956] poll([{fd=4, events=POLLIN}, {fd=5, events=POLLIN}], 2, -1

然后它挂起 5 分钟,直到:

[pid  3956] poll([{fd=4, events=POLLIN}, {fd=5, events=POLLIN}], 2, -1 <unfinished ...>
[pid  3954] <... ppoll resumed> )       = 1 ([{fd=3, revents=POLLIN}])
[pid  3954] recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\4\1\1\251\2\0\0\n\0\0\0\276\0\0\0\1\1o\0000\0\0\0", iov_len=24}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 24
[pid  3954] recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="/org/freedesktop/systemd1/unit/a"..., iov_len=865}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 865
[pid  3954] recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\4\1\1L\3\0\0\v\0\0\0\276\0\0\0\1\1o\0000\0\0\0", iov_len=24}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 24
[pid  3954] recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="/org/freedesktop/systemd1/unit/a"..., iov_len=1028}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 1028
[pid  3954] recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\4\1\1L\0\0\0\f\0\0\0\246\0\0\0\1\1o\0\31\0\0\0", iov_len=24}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 24
[pid  3954] recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="/org/freedesktop/systemd1\0\0\0\0\0\0\0"..., iov_len=236}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 236
[pid  3954] recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\4\1\1K\0\0\0\r\0\0\0\242\0\0\0\1\1o\0\31\0\0\0", iov_len=24}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 24
[pid  3954] recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="/org/freedesktop/systemd1\0\0\0\0\0\0\0"..., iov_len=235}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 235
[pid  3954] sendmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\1\4\0013\0\0\0\4\0\0\0\250\0\0\0\1\1o\0000\0\0\0/org/fre"..., iov_len=184}, {iov_base=" \0\0\0org.freedesktop.systemd1.Ser"..., iov_len=51}], msg_iovlen=2, msg_controllen=0, msg_flags=0}, MSG_DONTWAIT|MSG_NOSIGNAL) = 235
[pid  3954] recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\4\1\1\251\2\0\0\16\0\0\0\276\0\0\0\1\1o\0000\0\0\0", iov_len=24}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 24
[pid  3954] recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="/org/freedesktop/systemd1/unit/a"..., iov_len=865}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 865
[pid  3954] recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\4\1\1\34\3\0\0\17\0\0\0\276\0\0\0\1\1o\0000\0\0\0", iov_len=24}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 24
[pid  3954] recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="/org/freedesktop/systemd1/unit/a"..., iov_len=980}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 980
[pid  3954] recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\2\1\1\20\0\0\0\20\0\0\0007\0\0\0\5\1u\0\4\0\0\0", iov_len=24}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 24
[pid  3954] recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="\7\1s\0\30\0\0\0org.freedesktop.systemd1"..., iov_len=64}], msg_iovlen=1, msg_controllen=0, msg_flags=MSG_CMSG_CLOEXEC}, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) = 64
[pid  3954] writev(2, [{iov_base="Job for apache2.service failed b"..., iov_len=62}, {iov_base="\n", iov_len=1}], 2Job for apache2.service failed because a timeout was exceeded.
) = 63
[pid  3954] writev(2, [{iov_base="See \"systemctl status apache2.se"..., iov_len=72}, {iov_base="\n", iov_len=1}], 2See "systemctl status apache2.service" and "journalctl -xe" for details.
) = 73
[pid  3954] close(3)                    = 0
[pid  3954] kill(3956, SIGTERM <unfinished ...>
[pid  3956] <... poll resumed> )        = 1 ([{fd=5, revents=POLLIN}])
[pid  3954] <... kill resumed> )        = 0
[pid  3956] close(3 <unfinished ...>
[pid  3954] kill(3956, SIGCONT <unfinished ...>
[pid  3956] <... close resumed> )       = 0
[pid  3954] <... kill resumed> )        = 0
[pid  3956] --- SIGCONT {si_signo=SIGCONT, si_code=SI_USER, si_pid=3954, si_uid=0} ---
[pid  3954] waitid(P_PID, 3956,  <unfinished ...>
[pid  3956] close(5)                    = 0
[pid  3956] close(4)                    = 0
[pid  3956] exit_group(0)               = ?
[pid  3956] +++ exited with 0 +++
[pid  3954] <... waitid resumed> {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=3956, si_uid=0, si_status=0, si_utime=0, si_stime=0}, WEXITED, NULL) = 0
[pid  3954] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=3956, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
[pid  3954] exit_group(1)               = ?
[pid  3954] +++ exited with 1 +++
<... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 1}], 0, NULL) = 3954
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=3954, si_uid=0, si_status=1, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]})                 = 3954
write(1, "Action 'start' failed.\n", 23Action 'start' failed.
) = 23
write(1, "The Apache error log may have mo"..., 48The Apache error log may have more information.
) = 48
exit_group(1)                           = ?
+++ exited with 1 +++

如果我能提供任何关于如何调试 Apache 无法启动的原因的提示,我将不胜感激。

编辑:在配置中禁用我的所有网站没有帮助。清除并重新安装 apache2 也没有用。

答案1

错误在于 apache2.service 没有从 systemd 中完全删除。升级假定这不是必需的。Ubuntu 16.04 显示以下内容:

[email protected]:~# systemctl -a | grep apache2
  apache2.service                                                               
loaded    active   running   LSB: Apache HTTP Server
[email protected]:~#

在全新安装的 Ubuntu 18.04 上,我得到的是:

[email protected]:~# systemctl -a | grep apache2
  apache2.service                                                               
loaded    active   running   The Apache HTTP Server                             
[email protected]:~# 

因此,如果您丢弃了所有 apache2 软件包,那么您也不要忘记丢弃旧的 apache2.service 服务文件。

具体如下:

如何删除 systemd 服务 2015 年 7 月 6 日 https://superuser.com/questions/513159/how-to-remove-systemd-services

“我的服务毁灭秘诀(小心 rm 语句!)”

systemctl stop [servicename]
systemctl disable [servicename]
rm /etc/systemd/system/[servicename]
rm /etc/systemd/system/[servicename] # and symlinks that might be related
rm /usr/lib/systemd/system/[servicename] 
rm /usr/lib/systemd/system/[servicename] # and symlinks that might be related
systemctl daemon-reload
systemctl reset-failed

“Systemd 服务可能会在 etc/init.d 中‘包装’旧式脚本,因此您可能也想清理它,但这不是 systemd 服务所在的位置。”

从 systemd 中删除 apache2.service 后,您只需运行:apt install apache2,即可成功完成

[email protected]:~# systemctl -a | grep apache2
  apache2.service                                                               
loaded    active   running   The Apache HTTP Server                             
[email protected]:~# 

以及欢迎 index.html 页面

相关内容