Nginx平滑升级

需求:

旧的nginx版本:

root@mysql243:~# ll /usr/local/|grep nginx

lrwxrwxrwx  1 root      root        25 2014-03-11 19:03 nginx -> /usr/local/nginx-1.4.2-gz/

打算升级到最新的nginx-1.6.2

1.使用初始化脚本nginx_install.sh 安装新版nginx-1.6.2  

cp nginx.conf /usr/local/nginx-1.6.2/conf/  #拷贝旧的nginx.conf

cp -a sites /usr/local/nginx-1.6.2/conf/

#先检查语法是否错误

root@mysql243:~# /usr/local/nginx-1.6.2/sbin/nginx -t -c /usr/local/nginx-1.6.2/conf/nginx.conf

nginx: the configuration file /usr/local/nginx-1.6.2/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx-1.6.2/conf/nginx.conf test is successful

2.mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old

 

3.拷贝重编译的nginx

cp /usr/local/nginx-1.6.2/sbin/nginx /usr/local/nginx/sbin/

 

4.平滑的升级nginx二进制文件

kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`

root     35568  1.0  0.0  30588  2980 ?        S    16:30   0:00 nginx: master process /usr/local/nginx/sbin/nginx

nobody   35569  2.0  0.0  47560 18408 ?        S    16:30   0:00 nginx: worker process      

nobody   35570  1.0  0.0  47560 18408 ?        S    16:30   0:00 nginx: worker process      

nobody   35571  4.0  0.0  47984 19264 ?        S    16:30   0:00 nginx: worker process      

nobody   35572  2.0  0.0  47560 18408 ?        S    16:30   0:00 nginx: worker process      

nobody   35573  2.0  0.0  47832 19040 ?        S    16:30   0:00 nginx: worker process      

nobody   35574  1.0  0.0  47560 18408 ?        S    16:30   0:00 nginx: worker process      

nobody   35575  1.0  0.0  47560 18408 ?        S    16:30   0:00 nginx: worker process      

nobody   35576  1.0  0.0  47560 18392 ?        S    16:30   0:00 nginx: worker process      

root     35581  0.0  0.0   7640  1016 pts/12   S+   16:30   0:00 grep --color=auto nginx

root     60574  0.0  0.0  30572   956 ?        Ss   Dec22   0:00 nginx: master process /usr/local/nginx/sbin/nginx

nobody   60575  0.9  0.0  49652  9800 ?        S    Dec22 125:44 nginx: worker process      

nobody   60576  0.9  0.0  47088 11604 ?        S    Dec22 125:37 nginx: worker process      

nobody   60577  0.9  0.0  47444  7908 ?        S    Dec22 125:33 nginx: worker process      

nobody   60578  0.9  0.0  47160 11592 ?        S    Dec22 127:54 nginx: worker process      

nobody   60579  0.9  0.0  47380  7764 ?        S    Dec22 126:20 nginx: worker process      

nobody   60580  0.9  0.0  47452 12496 ?        S    Dec22 127:52 nginx: worker process      

nobody   60581  0.9  0.0  48204  9192 ?        S    Dec22 127:09 nginx: worker process      

nobody   60582  0.9  0.0  47280 11932 ?        S    Dec22 126:26 nginx: worker process

5.从容关闭旧版本的worker进程(等待关闭worker进程,可能需要处理一小会)

kill -WINCH `cat /usr/local/nginx/logs/nginx.pid.oldbin`

root     35568  0.0  0.0  30588  2980 ?        S    16:30   0:00 nginx: master process /usr/local/nginx/sbin/nginx

nobody   35569  2.2  0.0  51340 22680 ?        S    16:30   0:00 nginx: worker process      

nobody   35570  0.0  0.0  47832 18940 ?        D    16:30   0:00 nginx: worker process      

nobody   35571  1.3  0.0  47984 19484 ?        S    16:30   0:00 nginx: worker process      

nobody   35572  0.5  0.0  47832 19128 ?        S    16:30   0:00 nginx: worker process      

nobody   35573  1.0  0.0  48100 19536 ?        S    16:30   0:00 nginx: worker process      

nobody   35574  0.0  0.0  47560 18476 ?        S    16:30   0:00 nginx: worker process      

nobody   35575  0.0  0.0  47560 18476 ?        S    16:30   0:00 nginx: worker process      

nobody   35576  0.0  0.0  47832 18972 ?        D    16:30   0:00 nginx: worker process      

root     35601  0.0  0.0   7640  1012 pts/12   S+   16:30   0:00 grep --color=auto nginx

root     60574  0.0  0.0  30572   956 ?        Ss   Dec22   0:00 nginx: master process /usr/local/nginx/sbin/nginx

nobody   60575  0.9  0.0  48576  9016 ?        D    Dec22 125:45 nginx: worker process is shutting down

nobody   60576  0.9  0.0  46940 11500 ?        D    Dec22 125:37 nginx: worker process is shutting down

nobody   60577  0.9  0.0  47444  8040 ?        D    Dec22 125:33 nginx: worker process is shutting down

nobody   60578  0.9  0.0  49720 14280 ?        D    Dec22 127:54 nginx: worker process is shutting down

nobody   60579  0.9  0.0  47380  7896 ?        D    Dec22 126:20 nginx: worker process is shutting down

nobody   60580  0.9  0.0  47452 12620 ?        D    Dec22 127:52 nginx: worker process is shutting down

nobody   60581  0.9  0.0  46848  7856 ?        D    Dec22 127:09 nginx: worker process is shutting down

nobody   60582  0.9  0.0  47280 12064 ?        D    Dec22 126:26 nginx: worker process is shutting down

过了一会之后再查看,已经关闭好了

root@mysql243:/usr/local/nginx/sbin# ps aux|grep nginx

root     35568  0.0  0.0  30588  2980 ?        S    16:30   0:00 nginx: master process /usr/local/nginx/sbin/nginx

nobody   35569  1.5  0.0  51340 22768 ?        S    16:30   0:01 nginx: worker process      

nobody   35570  0.7  0.0  47988 19436 ?        S    16:30   0:00 nginx: worker process      

nobody   35571  0.6  0.0  48288 19664 ?        S    16:30   0:00 nginx: worker process      

nobody   35572  0.7  0.0  48836 20368 ?        S    16:30   0:00 nginx: worker process      

nobody   35573  0.7  0.0  48100 19636 ?        S    16:30   0:00 nginx: worker process      

nobody   35574  0.6  0.0  48364 19736 ?        S    16:30   0:00 nginx: worker process      

nobody   35575  0.8  0.0  48564 20072 ?        S    16:30   0:01 nginx: worker process      

nobody   35576  1.2  0.0  49080 20536 ?        S    16:30   0:01 nginx: worker process      

root     36007  0.0  0.0   7640  1012 pts/12   S+   16:32   0:00 grep --color=auto nginx

root     60574  0.0  0.0  30572   964 ?        Ss   Dec22   0:00 nginx: master process /usr/local/nginx/sbin/nginx

6.关闭旧版本的nginx进程

kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`

root@mysql243:/usr/local/nginx/sbin# ps aux|grep nginx

root     35568  0.0  0.0  30588  2980 ?        S    16:30   0:00 nginx: master process /usr/local/nginx/sbin/nginx

nobody   35569  1.2  0.0  47964 19500 ?        S    16:30   0:01 nginx: worker process      

nobody   35570  0.6  0.0  47988 19436 ?        S    16:30   0:01 nginx: worker process      

nobody   35571  0.8  0.0  48432 19944 ?        S    16:30   0:01 nginx: worker process      

nobody   35572  1.0  0.0  50120 21552 ?        S    16:30   0:01 nginx: worker process      

nobody   35573  0.9  0.0  48408 19808 ?        S    16:30   0:01 nginx: worker process      

nobody   35574  0.5  0.0  48364 19736 ?        S    16:30   0:00 nginx: worker process      

nobody   35575  0.9  0.0  48564 20076 ?        S    16:30   0:01 nginx: worker process      

nobody   35576  0.9  0.0  47768 19304 ?        S    16:30   0:01 nginx: worker process      

root     36146  0.0  0.0   7640  1012 pts/12   S+   16:33   0:00 grep --color=auto nginx

7.删除旧的软链接,创建新的软链

cd /usr/local

rm -f nginx

ln -s /usr/local/nginx-1.6.2 nginx

 

8.观察access.log 是否正常


你可能感兴趣的:(nginx升级)