github学习笔记
用什么命令启动的,就需要使用什么工具去管理
使用nginx 启动,使用systemctl管理,之后使用nginx stop关闭会导致报错,反之一样
# 使用nginx命令启动nginx
[root@iZ2ze58f53sxjm9z7mgn5xZ ~]# nginx
# 查看启动状态
[root@iZ2ze58f53sxjm9z7mgn5xZ ~]# ps -aux | grep nginx
root 905155 0.0 0.0 121288 2184 ? Ss 15:32 0:00 nginx: master process nginx
nginx 905156 0.0 0.2 151824 8208 ? S 15:32 0:00 nginx: worker process
nginx 905157 0.0 0.2 151824 8212 ? S 15:32 0:00 nginx: worker process
root 905436 0.0 0.0 9208 1112 pts/0 S+ 15:32 0:00 grep --color=auto nginx
# 使用nginx启动的,但是使用systemctl管理,之后会导致命令报错
[root@iZ2ze58f53sxjm9z7mgn5xZ ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2022-09-21 17:20:16 CST; 1 day 22h ago
Sep 21 17:20:16 iZ2ze58f53sxjm9z7mgn5xZ systemd[1]: Starting The nginx HTTP and reverse proxy server...
Sep 21 17:20:16 iZ2ze58f53sxjm9z7mgn5xZ systemd[1]: nginx.service: Control process exited, code=exited status=203
Sep 21 17:20:16 iZ2ze58f53sxjm9z7mgn5xZ systemd[1]: nginx.service: Failed with result 'exit-code'.
Sep 21 17:20:16 iZ2ze58f53sxjm9z7mgn5xZ systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
# 报错
[root@iZ2ze58f53sxjm9z7mgn5xZ ~]# systemctl restart nginx
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
# 重新加载也报错
[root@iZ2ze58f53sxjm9z7mgn5xZ ~]# nginx -s reload
nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)
# 停止也会报错
[root@iZ2ze58f53sxjm9z7mgn5xZ ~]# nginx -s stop
nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)
# 查看对应的进程文件nginx.pid文件不存,这是因为不是使用systemctl启动的,但是使用systemctl去管理导致的错误
[root@iZ2ze58f53sxjm9z7mgn5xZ ~]# cat /run/nginx.pid
cat: /run/nginx.pid: No such file or directory
# 解决, 查询出nginx的master进程pid
[root@iZ2ze58f53sxjm9z7mgn5xZ ~]# ps -aux | grep nginx | grep master
root 905155 0.0 0.0 121288 2184 ? Ss 15:32 0:00 nginx: master process nginx
# 将进程pid写入进程管理文件,之后就可以正常停止nginx
[root@iZ2ze58f53sxjm9z7mgn5xZ ~]# echo 905155 > /run/nginx.pid
[root@iZ2ze58f53sxjm9z7mgn5xZ ~]# nginx -s stop
[root@iZ2ze58f53sxjm9z7mgn5xZ ~]# ps -aux | grep nginx
root 921991 0.0 0.0 9208 1072 pts/0 S+ 15:40 0:00 grep --color=auto nginx
# 使用systemctl管理nginx
[root@iZ2ze58f53sxjm9z7mgn5xZ ~]# systemctl start nginx
# 查看状态正常运行
[root@iZ2ze58f53sxjm9z7mgn5xZ ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2022-09-23 15:40:36 CST; 6s ago
Process: 922707 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 922705 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 922703 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 922708 (nginx)
Tasks: 3 (limit: 22997)
Memory: 4.9M
CGroup: /system.slice/nginx.service
├─922708 nginx: master process /usr/sbin/nginx
├─922709 nginx: worker process
└─922710 nginx: worker process
Sep 23 15:40:36 iZ2ze58f53sxjm9z7mgn5xZ systemd[1]: Starting The nginx HTTP and reverse proxy server...
Sep 23 15:40:36 iZ2ze58f53sxjm9z7mgn5xZ nginx[922705]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Sep 23 15:40:36 iZ2ze58f53sxjm9z7mgn5xZ nginx[922705]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Sep 23 15:40:36 iZ2ze58f53sxjm9z7mgn5xZ systemd[1]: Started The nginx HTTP and reverse proxy server.
749

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



