Nginx如何进行热升级部署

Posted by jintang on 2014-07-21

Nginx支持热部署,非常方便地不关闭nginx服务的前提下,添加新的模块功能。

首先查看当前编译参数,复制别漏了原来的模块

1
nginx -V 

略过编译部分…

make完之后,不要make install

先备份原来的nginx二进制文件

1
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old

编译后,源码包里面有一个objs文件夹,复制新的nginx到nginx目录,覆盖

1
cp objs/nginx /usr/local/nginx/sbin/nginx 

查看当前nginx master进程号

1
$ ps -aux | grep nginx

发送USR2型号给nginx master进程

1
$ kill -USR2 PID

发送WINCH型号让旧的nginx master优雅关闭worker子进程

1
$ kill -WINCH PID

Nginx的信号

信号 描述
TERM, INT Quick shutdown
QUIT Graceful shutdown
KILL Halts a stubborn process
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

关于Linux进程信号,参考:https://www.cnblogs.com/f-ck-need-u/p/7058920.html#auto_id_10