Apache 无法启动,已在运行但未匹配 pid 文件?

Apache 无法启动,已在运行但未匹配 pid 文件?

每当我尝试apache2使用启动/重新启动我的服务systemctl时,我都会收到一条关于它已在运行但无法匹配我的错误pid file

● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Mon 2017-01-09 21:42:38 EST; 16s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 18354 ExecStop=/etc/init.d/apache2 stop (code=exited, status=1/FAILURE)
  Process: 18337 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)

Jan 09 21:42:38 username apache2[18337]: Action 'start' failed.
Jan 09 21:42:38 username apache2[18337]: The Apache error log may have more information.
Jan 09 21:42:38 username apache2[18337]:  *
Jan 09 21:42:38 username apache2[18354]:  * Stopping Apache httpd web server apache2
Jan 09 21:42:38 username apache2[18354]:  *
Jan 09 21:42:38 username apache2[18354]:  * There are processes named 'apache2' running which do not match your pid file which are left untouched in the name of safety, Please review the situation by hand.
Jan 09 21:42:38 username systemd[1]: apache2.service: Control process exited, code=exited status=1
Jan 09 21:42:38 username systemd[1]: Failed to start LSB: Apache2 web server.
Jan 09 21:42:38 username systemd[1]: apache2.service: Unit entered failed state.
Jan 09 21:42:38 username systemd[1]: apache2.service: Failed with result 'exit-code'.

runningps aux | grep apache2显示某些程序已在运行,但我无法终止它们。一旦我终止它们,它们就会以不同的 pid 重新生成。

root       8931  0.0  0.2 227232 23632 ?        Ss   21:30   0:00 apache2 -DFOREGROUND
username   9193  0.0  0.1 227264  9056 ?        S    21:30   0:00 apache2 -DFOREGROUND
username   9194  0.0  0.1 227264  9056 ?        S    21:30   0:00 apache2 -DFOREGROUND
username   9195  0.0  0.1 227264  9056 ?        S    21:30   0:00 apache2 -DFOREGROUND
username   9196  0.0  0.1 227264  9056 ?        S    21:30   0:00 apache2 -DFOREGROUND
username   9197  0.0  0.1 227264  9056 ?        S    21:30   0:00 apache2 -DFOREGROUND

下面的apache日志/var/log/apache2/errors.log是空的。

附加到第一个 pid 使用sudo strace -p 8931,我得到:

strace: Process 8931 attached
select(0, NULL, NULL, NULL, {0, 58750}) = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0}^Cstrace: Process 8931 detached

一遍又一遍地重复

运行 sudo /usr/sbin/apachectl -k start出现以下错误。但我不确定是什么在使用端口 80。

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
Action '-k start' failed.
The Apache error log may have more information.

运行后sudo netstat -lnpt我发现我忘记了正在运行的docker容器......

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
...
tcp6       0      0 :::80                   :::*                    LISTEN      8856/docker-proxy
...

答案1

活动:失败(结果:退出代码)自 2017-01-09 星期一 21:42:38 EST;16 秒前

这意味着服务未正确启动,请尝试使用“#/apacheHome/bin/apachectl -k start/stop”手动启动并检查日志。

答案2

跑步

sudo netstat -tulpn | grep :80

你将获得类似的输出

tcp     0      0 0.0.0.0:80        0.0.0.0:*      LISTEN      1066/lighttpd

注意监听端口的进程的 PID,在我的情况下是 1066。然后运行

sudo kill -9 1066

记得将 pid 更改为监听端口的 pid,它可能与 1066 不一样

这对我有用。

相关内容