1. 程式人生 > >nginx   Binary熱更新

nginx   Binary熱更新

nginx

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

本文出自 “馬行空” 博客,請務必保留此出處http://maxingkong.blog.51cto.com/6184921/1956387

nginx Binary熱更新