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改为一致服务才可以正常启动
本文档记录了在Ubuntu系统上遇到nginx服务启动失败的问题,表现为systemd超时并尝试杀死进程。经过排查,发现nginx实际生成的PID文件位置与systemd配置的PID文件路径不一致,导致服务无法正常启动。解决方案是将systemd配置文件中的PID文件路径更改为实际生成的位置,从而解决了问题。



5650

被折叠的 条评论
为什么被折叠?



