Nginx信号控制和命令操作

1.Nginx信号控制

TERM, INT

Quick shutdown  快速关闭

QUIT

Graceful shutdown  优雅的关闭进程,即等请求结束后再关闭

HUP

Configuration reload ,Start the new worker processes with

 a new configuration Gracefully shutdown the old worker processes

改变配置文件,平滑的重读配置文件

USR1

Reopen the log files 重读日志,在日志按月/日分割时有用

USR2

Upgrade Executable on the fly 平滑的升级

WINCH

Gracefully shutdown the worker processes 优雅关闭旧的进程(配合USR2来进行升级)

具体语法:

kill -信号选项 nginx的主进程号

例如::

[root@data1 ~]# ps -aux |grep nginx
root       9869  0.0  0.0  20548   604 ?        Ss   19:50   0:00 nginx: master process ./nginx
nobody     9870  0.0  0.1  20992  1068 ?        S    19:50   0:00 nginx: worker process
root      10940  0.0  0.0 112724   976 pts/1    R+   19:59   0:00 grep --color=auto nginx
[root@data1 ~]# kill -HUP 9869
[root@data1 ~]# ps -aux |grep nginx
root       9869  0.0  0.1  20548  1348 ?        Ss   19:50   0:00 nginx: master process ./nginx
nobody    10942  0.0  0.1  20996  1432 ?        S    20:00   0:00 nginx: worker process
root      10944  0.0  0.0 112724   972 pts/1    R+   20:00   0:00 grep --color=auto nginx

上面是先查询nginx的主进程号,再使用主进程号执行信号控制

也可以使用下面的命令,执行从文件中读取主进程号来执行

kill -信号控制 `cat /xxx/path/log/nginx.pid`

kill -HUP `cat /xxx/path/log/nginx.pid`

例如:

[root@data1 nginx]# pwd
/usr/local/nginx
[root@data1 nginx]# kill -HUP `cat logs/nginx.pid`

nginx 的主进程号记录在usr/local/nginx/logs/nginx.pid中

其中"usr/local/nginx"是nginx的安装目录

2.Nginx命令

使用nginx -h查看命令帮助文档

[root@data1 nginx]# ./sbin/nginx -h
nginx version: nginx/1.14.0
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help    查看帮助信息
  -v            : show version and exit 查看nginx版本
  -V            : show version and configure options then exit 查看nginx版本、编译器版本和配置参数
  -t            : test configuration and exit 测试nginx的配置文件,检查配置文件的正确性
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
发送信号给主进程,stop快速关闭、quit优雅关闭、reopen重新打开日志文件(用于切换日志文件)、reload重新加载配置文件
  -p prefix     : set prefix path (default: /usr/local/nginx/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

常用的就是nginx -s signal命令,实现跟信号控制一样的功能

修改nginx的配置文件后,直接执行nginx -s reload即可重新加载配置文件

[root@data1 nginx]# ./sbin/nginx -s reload

猜你喜欢

转载自blog.csdn.net/u012279312/article/details/81209898
今日推荐