nginx: [error] invalid PID number ““ in “/usr/local/nginx/logs/nginx.pid“

服务器非正常关机导致以下问题

nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"

并且杀死进程无效也无法停止也无法启动及重启

无法停止

[root@localhost sbin]# ./nginx -s stop
nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
[root@localhost sbin]# ps -ef | grep nginx
root      7566  6406  0 09:22 pts/0    00:00:00 grep --color=auto nginx
[root@localhost sbin]# ps -aux | grep nginx
root      7753  0.0  0.0 112824   980 pts/0    R+   09:23   0:00 grep --color=auto nginx
[root@localhost sbin]# ps -aux | grep nginx
root      7894  0.0  0.0 112824   984 pts/0    R+   09:23   0:00 grep --color=auto nginx

无法杀死

[root@localhost sbin]# pkill -9 nginx 
[root@localhost sbin]# ps -aux | grep nginx
root      9604  0.0  0.0 112824   984 pts/0    R+   09:27   0:00 grep --color=auto nginx
[root@localhost sbin]# kill -9 112824
-bash: kill: (112824) - 没有那个进程
[root@localhost sbin]# ps -aux | grep nginx
root      9968  0.0  0.0 112824   984 pts/0    R+   09:28   0:00 grep --color=auto nginx
[root@localhost sbin]# kill -9 984
-bash: kill: (984) - 没有那个进程
[root@localhost sbin]# ps -aux | grep nginx
root      9997  0.0  0.0 112824   984 pts/0    R+   09:29   0:00 grep --color=auto nginx

无法重启

[root@localhost sbin]# ./nginx -s reload
nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
[root@localhost sbin]# ps -ef | grep nginx
root     12315  6406  0 09:35 pts/0    00:00:00 grep --color=auto nginx[root@localhost sbin]# ./nginx -s reload
nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
[root@localhost sbin]# ps -ef | grep nginx
root     12315  6406  0 09:35 pts/0    00:00:00 grep --color=auto nginx**

检查nginx.pid文件是否存在

[root@localhost sbin]# cd ..
[root@localhost nginx]# cd logs/
[root@localhost logs]# ll
总用量 406796
-rw-r--r--. 1 root root 332651918 1116 16:50 access.log
-rw-r--r--. 1 root root  83889973 1127 09:35 error.log
-rw-r--r--. 1 root root         0 1127 09:22 nginx.pid

经过检查文件是存在的,所以和这个没关系


通过killall命令全部强制停止试验一下

先安装 killall命令

[root@localhost logs]# yum install -y psmisc
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
 * base: mirrors.bupt.edu.cn
 * extras: mirrors.bupt.edu.cn
 * updates: mirrors.163.com
base                                                                                | 3.6 kB  00:00:00     
docker-ce-stable                                                                    | 3.5 kB  00:00:00     
extras                                                                              | 2.9 kB  00:00:00     
updates                                                                             | 2.9 kB  00:00:00     
(1/2): docker-ce-stable/7/x86_64/primary_db                                         |  69 kB  00:00:00     
(2/2): updates/7/x86_64/primary_db                                                  |  12 MB  00:00:00     
正在解决依赖关系
--> 正在检查事务
---> 软件包 psmisc.x86_64.0.22.20-17.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

===========================================================================================================
 Package                 架构                    版本                          源                     大小
===========================================================================================================
正在安装:
 psmisc                  x86_64                  22.20-17.el7                  base                  141 k

事务概要
===========================================================================================================
安装  1 软件包

总下载量:141 k
安装大小:475 k
Downloading packages:
psmisc-22.20-17.el7.x86_64.rpm                                                      | 141 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : psmisc-22.20-17.el7.x86_64                                                             1/1 
  验证中      : psmisc-22.20-17.el7.x86_64                                                             1/1 

已安装:
  psmisc.x86_64 0:22.20-17.el7                                                                             

完毕!

通过killall命令看是否能杀停

[root@localhost logs]# cd ../sbin/
[root@localhost sbin]# killall nginx
nginx: no process found

尝试重新加载nginx的nginx.conf文件

root@localhost sbin]# cd ..
[root@localhost nginx]# ll
总用量 2476
drwx------.  2 nobody root       6 1115 19:02 client_body_temp
drwxr-xr-x.  2 root   root    4096 922 13:08 conf
drwx------.  2 nobody root       6 922 13:06 fastcgi_temp
drwxr-xr-x.  2 root   root      40 922 13:05 html
drwxr-xr-x.  4 root   root      97 830 16:57 html_zm
-rw-r--r--.  1 root   root 2528264 922 13:54 html_zm.zip
drwxr-xr-x.  2 root   root      58 1127 09:22 logs
drwx------. 12 nobody root      96 922 14:43 proxy_temp
drwxr-xr-x.  2 root   root      19 922 13:05 sbin
drwx------.  2 nobody root       6 922 13:06 scgi_temp
drwx------.  2 nobody root       6 922 13:06 uwsgi_temp
[root@localhost nginx]# /usr/local/nginx/sbin/nginx  -c /usr/local/nginx/conf/nginx.conf

至此发现可以重新启动及相关的正常操作了

[root@localhost nginx]# cd sbin/
[root@localhost sbin]# ll
总用量 3660
-rwxr-xr-x. 1 root root 3746584 922 13:05 nginx
[root@localhost sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost sbin]# ./nginx -s reload
[root@localhost sbin]# ./nginx -s stop
[root@localhost sbin]# ps -ef | grep nginx
root     17625  6406  0 09:49 pts/0    00:00:00 grep --color=auto nginx
[root@localhost sbin]# ./nginx -s reload
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
[root@localhost sbin]# ./nginx
[root@localhost sbin]# ./nginx -s reload
[root@localhost sbin]# killall nginx 
[root@localhost sbin]# ./nginx -s reload
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)

总结分析

`nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"出现的原因可能如下:

1.nginx进程可能已经启动活着占用了
	解决方案:杀掉当前目录下的nginx进程,重新启动
2.没有nginx.pid文件
	解决方案:重新加载nginx.conf配置文件,再重新启动
3.非正常停止nginx或者服务器突然断电,导致nginx无法启动,也无法使用
	解决方案:重新加载nginx.conf配置文件,再重新启动`

分享一句我特别喜欢的话:每一天都是一个新的日子,走运当然是好的,不过我情愿做到分毫不差。这样,运气来的时候,你就有准备了。 ————海明威《老人与海》

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值