ubuntu nginx启动失败 Failed to start A high performance web server and a reverse proxy server
root@orbbec-B550M-AORUS-ELITE:/etc/nginx# systemctl status nginx● nginx.service - A high performance web server and a reverse proxy serverLoaded: loaded (/lib/systemd/system/nginx.service; enabled; ve
·
root@orbbec-B550M-AORUS-ELITE:/etc/nginx# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: timeout) since Thu 2022-03-10 17:20:45 CST; 1min 21s ago
Docs: man:nginx(8)
Process: 5030 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 5032 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 19051)
Memory: 3.7M
CGroup: /system.slice/nginx.service
Mar 10 17:20:45 orbbec-B550M-AORUS-ELITE systemd[1]: nginx.service: Killing process 5050 (nginx) with signal SIGKILL.
Mar 10 17:20:45 orbbec-B550M-AORUS-ELITE systemd[1]: nginx.service: Killing process 5051 (nginx) with signal SIGKILL.
Mar 10 17:20:45 orbbec-B550M-AORUS-ELITE systemd[1]: nginx.service: Killing process 5052 (nginx) with signal SIGKILL.
Mar 10 17:20:45 orbbec-B550M-AORUS-ELITE systemd[1]: nginx.service: Killing process 5053 (nginx) with signal SIGKILL.
Mar 10 17:20:45 orbbec-B550M-AORUS-ELITE systemd[1]: nginx.service: Killing process 5054 (nginx) with signal SIGKILL.
Mar 10 17:20:45 orbbec-B550M-AORUS-ELITE systemd[1]: nginx.service: Killing process 5055 (nginx) with signal SIGKILL.
Mar 10 17:20:45 orbbec-B550M-AORUS-ELITE systemd[1]: nginx.service: Killing process 5056 (nginx) with signal SIGKILL.
Mar 10 17:20:45 orbbec-B550M-AORUS-ELITE systemd[1]: nginx.service: Killing process 5057 (nginx) with signal SIGKILL.
Mar 10 17:20:45 orbbec-B550M-AORUS-ELITE systemd[1]: nginx.service: Failed with result 'timeout'.
Mar 10 17:20:45 orbbec-B550M-AORUS-ELITE systemd[1]: Failed to start A high performance web server and a reverse proxy server.
这样看来没看到什么有用的故障排查信息。
之后在一次偶然的情况下,再次启动nginx,并在systemctl status nginx 的状态输出信息中看到这样的现象:nginx.service: Can’t open PID file /run/nginx.pid (yet?) after start:
root@orbbec-B550M-AORUS-ELITE:/etc/security/limits.d# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: activating (start) since Thu 2022-03-10 16:55:20 CST; 12s ago
Docs: man:nginx(8)
Process: 13391 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 13392 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 19051)
Memory: 20.0K
CGroup: /system.slice/nginx.service
Mar 10 16:55:20 orbbec-B550M-AORUS-ELITE systemd[1]: Starting A high performance web server and a reverse proxy server...
Mar 10 16:55:20 orbbec-B550M-AORUS-ELITE systemd[1]: nginx.service: Can't open PID file /run/nginx.pid (yet?) after start:
遂检查nginx配置,但配置中配置的是/tmp/nginx.pid,手动执行 nginx 没有提示报错信息,nginx -t也提示配置正常,突然想到了 nginx 的systemd自启动配置,检查发现
root@orbbec-B550M-AORUS-ELITE:/etc/nginx# cat /lib/systemd/system/nginx.service
# Stop dance for nginx
# =======================
#
# ExecStop sends SIGSTOP (graceful stop) to the nginx process.
# If, after 5s (--retry QUIT/5) nginx is still running, systemd takes control
# and sends SIGTERM (fast shutdown) to the main process.
# After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends
# SIGKILL to all the remaining processes in the process group (KillMode=mixed).
#
# nginx signals reference doc:
# http://nginx.org/en/docs/control.html
#
[Unit]
Description=A high performance web server and a reverse proxy server
Documentation=man:nginx(8)
After=network.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
这里也有pid配置,所以得出结论是由于nginx启动后的pid生成在了/tmp/nginx.pid 位置,但systemd检查nginx的pid是/run/nginx.pid,当检查不到pid位置,systemd以为nginx没有启动成功,将两个地方pid改为一致服务才可以正常启动
更多推荐
已为社区贡献3条内容
所有评论(0)