nginx中kill信号的功能HUP与USR

之前系统上使用的是apache httpd,httpd有自带的日志滚动模式。但nginx中却没有,需要自行配置。看方案都是使用kill -HUP或者kill -USR1的方式进行重新加载文件。
于是学习了一下nginx中的信号。

nginx常用信号量如下:

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 -HUP $PID时,会发现进程被重启了。而使用kill -USR1 $PID时,则进程不会重启。

[root@vm-vmw64003-app logs]# ps -ef|grep 88239
nobody    31466  88239  0 20:10 ?        00:00:00 nginx: worker process
root      49442  64266  0 20:21 pts/0    00:00:00 grep --color=auto 88239
root      88239      1  0 14:29 ?        00:00:00 nginx: master process ../nginx
[root@vm-vmw64003-app logs]# kill -USR1 88239
[root@vm-vmw64003-app logs]# ps -ef|grep 88239
nobody    31466  88239  0 20:10 ?        00:00:00 nginx: worker process
root      50059  64266  0 20:21 pts/0    00:00:00 grep --color=auto 88239
root      88239      1  0 14:29 ?        00:00:00 nginx: master process ../nginx
[root@vm-vmw64003-app logs]# kill -HUP 88239
[root@vm-vmw64003-app logs]# ps -ef|grep 88239
nobody    50427  88239  0 20:21 ?        00:00:00 nginx: worker process
root      50771  64266  0 20:21 pts/0    00:00:00 grep --color=auto 88239
root      88239      1  0 14:29 ?        00:00:00 nginx: master process ../nginx
[root@vm-vmw64003-app logs]#

posted @ 2022-09-03 20:23  liujw2001  阅读(1003)  评论(0)    收藏  举报