nginx: worker process is shutting down原因及解决方案

原因

通过命令查询nginx进程

[root@localhost]# ps auxf | grep nginx
root     12671  0.0  0.0 112716   968 pts/2    S+   11:03   0:00          \_ grep --color=auto nginx
root     17353  0.0  0.0 565848  7472 ?        Ss    2021   0:13 nginx: master process nginx
root     26426  0.2  0.1 576048 18340 ?        S    Apr29  50:17  \_ nginx: worker process is shutting down
root     16200  0.1  0.0 570312 13280 ?        S    May10   2:58  \_ nginx: worker process is shutting down
root     29245  0.1  0.0 572192 14860 ?        S    May11   3:07  \_ nginx: worker process is shutting down
root     24613  0.3  0.0 570944 12900 ?        S    May11   3:15  \_ nginx: worker process
root     24614  0.0  0.0 565848  6736 ?        S    May11   0:00  \_ nginx: cache manager process

这是我们修改配置文件后,使用service nginx reload重载nginx ,这是一种平滑重启的方案,不会把已有的连接断掉,而这些维护已有连接的 nginx 进程则会进入worker process is shutting down 状态,稍等片刻就会消失。

方案

一、配置超时时间

如果长时间不消失,会造成资源无法释放,我们可以在nginx.conf配置全局变量

worker_shutdown_timeout 10;

注意:nginx版本需要大于1.13.7

二、直接杀掉进程

编辑脚本

vi nginx-stop-shutting-down.sh

增加内容

#!/bin/bash

PIDS=`ps aux | grep nginx | grep "worker process is shutting down" |awk '{print $2}'`

for PID in $PIDS ;
  do
    kill $PID > /dev/null 2>&1;
  done

ps aux --forest | grep nginx

赋予权限

chmod +x nginx-stop-shutting-down.sh 

你可能感兴趣的:(nginx: worker process is shutting down原因及解决方案)