两者都是 CentOS 服务器。
服务器 A:
运行后service nginx stop
,Nginx 进程被终止。
ps -aux | grep "nginx"
root 1729 0.0 0.0 125600 6488 ? Ss Sep15 0:00 nginx: master process /usr/sbin/nginx
root 2240 0.0 0.0 125604 5744 ? S Sep15 0:00 nginx: worker process
root 2241 0.0 0.0 125604 5752 ? S Sep15 0:00 nginx: worker process
root 2242 0.0 0.0 125604 4100 ? S Sep15 0:00 nginx: worker process
root 2243 0.0 0.0 125604 5748 ? S Sep15 0:00 nginx: worker process
root 2244 0.0 0.0 125604 4100 ? S Sep15 0:00 nginx: worker process
root 2245 0.0 0.0 125604 4304 ? S Sep15 0:00 nginx: worker process
root 2246 0.0 0.0 125604 5744 ? S Sep15 0:00 nginx: worker process
root 2247 0.0 0.0 125604 5744 ? S Sep15 0:00 nginx: worker process
root 2248 0.0 0.0 125604 4044 ? S Sep15 0:01 nginx: cache manager process
root 3705 0.0 0.0 112708 988 pts/0 S+ 21:15 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn nginx
➜ ~ service nginx stop
Redirecting to /bin/systemctl stop nginx.service
➜ ~ ps -aux | grep "nginx"
root 3896 0.0 0.0 112704 988 pts/0 S+ 21:16 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn nginx
服务器B:
运行之后service nginx stop
,Nginx 进程根本不会被杀死:
[root@machine123 ~]# ps -aux | grep "nginx"
root 1376 0.0 0.1 136592 12592 ? Ss 09:21 0:00 nginx: master process nginx -c /etc/nginx/nginx.conf
root 1388 0.0 0.1 165788 13072 ? S 09:21 0:00 nginx: worker process
root 1389 0.0 0.1 165788 11392 ? S 09:21 0:00 nginx: worker process
root 1390 0.0 0.1 165788 9260 ? S 09:21 0:00 nginx: worker process
root 1391 0.0 0.1 165788 9260 ? S 09:21 0:00 nginx: worker process
root 1392 0.0 0.1 165788 9260 ? S 09:21 0:00 nginx: worker process
root 1393 0.0 0.1 165788 9260 ? S 09:21 0:00 nginx: worker process
root 1394 0.0 0.1 165788 9260 ? S 09:21 0:00 nginx: worker process
root 1395 0.0 0.1 165788 9260 ? S 09:21 0:00 nginx: worker process
root 1396 0.0 0.1 165552 9068 ? S 09:21 0:00 nginx: cache manager process
root 1892 0.0 0.0 12108 1084 pts/0 S+ 09:48 0:00 grep --color=auto nginx
[root@machine123 ~]# service nginx stop
Redirecting to /bin/systemctl stop nginx.service
[root@machine123 ~]# ps -aux | grep "nginx"
root 1376 0.0 0.1 136592 12592 ? Ss 09:21 0:00 nginx: master process nginx -c /etc/nginx/nginx.conf
root 1388 0.0 0.1 165788 13072 ? S 09:21 0:00 nginx: worker process
root 1389 0.0 0.1 165788 11392 ? S 09:21 0:00 nginx: worker process
root 1390 0.0 0.1 165788 9260 ? S 09:21 0:00 nginx: worker process
root 1391 0.0 0.1 165788 9260 ? S 09:21 0:00 nginx: worker process
root 1392 0.0 0.1 165788 9260 ? S 09:21 0:00 nginx: worker process
root 1393 0.0 0.1 165788 9260 ? S 09:21 0:00 nginx: worker process
root 1394 0.0 0.1 165788 9260 ? S 09:21 0:00 nginx: worker process
root 1395 0.0 0.1 165788 9260 ? S 09:21 0:00 nginx: worker process
root 1396 0.0 0.1 165552 9068 ? S 09:21 0:00 nginx: cache manager process
root 1906 0.0 0.0 12108 1028 pts/0 S+ 09:49 0:00 grep --color=auto nginx
我能做些什么来调试它吗?
谢谢您的任何提示。
systemctl status nginx
结果:
[root@machine123 ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2020-09-18 09:34:52 CST; 36min ago
Process: 1868 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE)
Process: 1865 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 1862 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Sep 18 09:34:51 machine123 nginx[1868]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Sep 18 09:34:51 machine123 nginx[1868]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Sep 18 09:34:51 machine123 nginx[1868]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Sep 18 09:34:51 machine123 nginx[1868]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Sep 18 09:34:52 machine123 nginx[1868]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Sep 18 09:34:52 machine123 nginx[1868]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Sep 18 09:34:52 machine123 nginx[1868]: nginx: [emerg] still could not bind()
Sep 18 09:34:52 machine123 systemd[1]: nginx.service: Control process exited, code=exited status=1
Sep 18 09:34:52 machine123 systemd[1]: nginx.service: Failed with result 'exit-code'.
Sep 18 09:34:52 machine123 systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
答案1
您不知何故成功启动了 systemd 无法控制的 nginx。您应该手动将其终止,然后使用 systemd 重新启动它。
答案2
你能试一下吗:
杀死主进程:kill -9 1376(nginx主进程的PID)
再次验证:(确保干净地杀死 nginx 并且没有任何进程使用端口 80、443) ps -ef | grep nginx netstat -naopt | grep 443
再次启动服务 nginx start