1、更新Binary

# cp /usr/loca/nginx/sbin/nginx  /usr/loca/nginx/sbin/nginxbak //备份
# cp /usr/local/nginx-12.1/sbin/nginx/  /usr/loca/sbin/nginx  //跟新新文件

2、给原来的nginx master进程发送USR2信号

# kill -USR2 `cat /var/run/nginx.pid`

 2.1此时会生成两个nginx 的master进程及其work进程

# ps aux | grep nginx
root     20650  1.0  0.1 1336856 22536 ?       S    11:29   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody   20655  0.0  0.3 1378272 53352 ?       S    11:29   0:00 nginx: worker process      
nobody   20656  0.0  0.3 1378468 54412 ?       S    11:29   0:00 nginx: worker process      
nobody   20657  0.0  0.3 1378272 53352 ?       S    11:29   0:00 nginx: worker process      
nobody   20658  0.0  0.3 1378272 53352 ?       S    11:29   0:00 nginx: worker process      
nobody   20659  0.0  0.0 1336856 12168 ?       S    11:29   0:00 nginx: cache manager process
nobody   20660  0.0  0.0 1336856 12048 ?       S    11:29   0:00 nginx: cache loader process
root     22250  0.0  0.1 1336856 22540 ?       S    11:10   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody   22251  0.0  0.3 1378272 53356 ?       S    11:10   0:00 nginx: worker process      
nobody   22252  0.0  0.3 1378568 54728 ?       S    11:10   0:00 nginx: worker process      
nobody   22254  0.0  0.3 1378468 54416 ?       S    11:10   0:00 nginx: worker process      
nobody   22255  0.0  0.3 1378272 53356 ?       S    11:10   0:00 nginx: worker process      
nobody   22256  0.0  0.0 1336856 12172 ?       S    11:10   0:00 nginx: cache manager process

3、给原来的nginx 的master进程发送WINCH信号,执行步骤二之后,老的nginx进程会在/var/run/生成一个旧的pid文件,为:/var/run/nginx.pid.oldbin

# kill -WINCH `cat  /var/run/nginx.pid.oldbin`

 3.1此时旧nginx的work进行已不存在

# ps aux | grep nginx
hujingfu  1324  0.0  0.0 103304   848 pts/101  S+   11:30   0:00 grep nginx
root     20650  0.2  0.1 1336856 22536 ?       S    11:29   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody   20655  0.0  0.3 1378272 53352 ?       S    11:29   0:00 nginx: worker process      
nobody   20656  0.0  0.3 1378468 54412 ?       S    11:29   0:00 nginx: worker process      
nobody   20657  0.0  0.3 1378272 53352 ?       S    11:29   0:00 nginx: worker process      
nobody   20658  0.0  0.3 1378272 53352 ?       S    11:29   0:00 nginx: worker process      
nobody   20659  0.0  0.0 1336856 12168 ?       S    11:29   0:00 nginx: cache manager process
nobody   20660  0.0  0.0 1336856 12048 ?       S    11:29   0:00 nginx: cache loader process
root     22250  0.0  0.1 1336856 22540 ?       S    11:10   0:00 nginx: master process /usr/local/nginx/sbin/nginx

4、给旧nginx 的master进行发送QUIT信号,让其推出

# kill -QUIT `cat /var/run/nginx.pid.oldbin`

 4.1 此时旧的nginx所有进程都已推出,新的nginx已经生效,nginx 热跟新Binary 完成

# ps aux | grep nginx
hujingfu  1502  0.0  0.0 103304   844 pts/101  S+   11:30   0:00 grep nginx
root     20650  0.1  0.1 1336856 22536 ?       S    11:29   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody   20655  0.0  0.3 1378272 53352 ?       S    11:29   0:00 nginx: worker process      
nobody   20656  0.0  0.3 1378468 54412 ?       S    11:29   0:00 nginx: worker process      
nobody   20657  0.0  0.3 1378272 53352 ?       S    11:29   0:00 nginx: worker process      
nobody   20658  0.0  0.3 1378272 53352 ?       S    11:29   0:00 nginx: worker process      
nobody   20659  0.0  0.0 1336856 12168 ?       S    11:29   0:00 nginx: cache manager process
nobody   20660  0.0  0.0 1336856 12048 ?       S    11:29   0:00 nginx: cache loader process

参考链接:

http://www.cnblogs.com/sayou/p/3711918.html

http://blog.csdn.net/huzelin1008/article/details/43193991