博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx平滑升级
阅读量:7019 次
发布时间:2019-06-28

本文共 3873 字,大约阅读时间需要 12 分钟。

转载请注明转自: , 本文固定链接:

1. nginx平滑升级

当我们开发了一个新的nginx模块,须要升级nginx binary时,须要进行下面的步骤:

a) 替换老的nginx binary

[root@lg-miui-file-mfs09 sbin]# mv nginx nginx.old[root@lg-miui-file-mfs09 sbin]# scp guojun1@10.237.92.30:/usr/local/nginx/sbin/nginx .guojun1@10.237.92.30's password:nginx
b) 向old master process 发送SIGUSR2信号[root@lg-miui-file-mfs09 sbin]# kill -s SIGUSR2 16236nginx.pid文件会被重命名为nginx.pid.oldbin,而且执行新的nginx binary文件,此时新老版本号会同一时候执行:
[root@lg-miui-file-mfs09 sbin]# ll ../logs/total 14392-rw-r--r-- 1 guojun1  500     893 May 30 10:58 error.log-rw-r--r-- 1 guojun1  500 5617929 May 12 13:12 nginx-access.log-rw-r--r-- 1 guojun1  500 9102050 May 13 22:39 nginx-error.log-rw-r--r-- 1 root    root       6 May 30 10:58 nginx.pid-rw-r--r-- 1 root    root       6 May 30 10:58 nginx.pid.oldbin[root@lg-miui-file-mfs09 sbin]# ps aux | grep nginxroot     16236  0.0  0.0  92920  3064 ?

Ss 10:58 0:00 nginx: master process ./nginx root 16237 0.0 0.0 94992 3988 ? S 10:58 0:00 nginx: worker process root 16238 0.0 0.0 94992 3988 ? S 10:58 0:00 nginx: worker process root 16239 0.0 0.0 94992 3988 ?

S 10:58 0:00 nginx: worker process root 16385 0.0 0.0 92924 6072 ? S 10:58 0:00 nginx: master process ./nginx root 16386 0.0 0.0 94996 3908 ? S 10:58 0:00 nginx: worker process root 16387 0.0 0.0 94996 3980 ? S 10:58 0:00 nginx: worker process root 16388 0.0 0.0 94996 3980 ? S 10:58 0:00 nginx: worker process root 16445 0.0 0.0 103244 852 pts/4 S+ 10:58 0:00 grep nginx

c) 向old master process发送SIGWINCH此时,master会”优雅地”关闭它的工作进程:
[root@lg-miui-file-mfs09 sbin]# kill -s SIGWINCH 16236[root@lg-miui-file-mfs09 sbin]# ps aux | grep nginxroot     16236  0.0  0.0  92920  3072 ?

Ss 10:58 0:00 nginx: master process ./nginx root 16385 0.0 0.0 92924 6072 ?

S 10:58 0:00 nginx: master process ./nginx root 16386 0.0 0.0 94996 3908 ? S 10:58 0:00 nginx: worker process root 16387 0.0 0.0 94996 3980 ? S 10:58 0:00 nginx: worker process root 16388 0.0 0.0 94996 3980 ? S 10:58 0:00 nginx: worker process

d) 关闭old master假设查看log发送更新成功,能够关闭old master,此时向old master进程发送SIGQUIT,仅仅留下新的server执行。
[root@lg-miui-file-mfs09 sbin]# kill -s SIGQUIT 16236[root@lg-miui-file-mfs09 sbin]# ps aux | grep nginxroot     16385  0.0  0.0  92924  6072 ?

S 10:58 0:00 nginx: master process ./nginx root 16386 0.0 0.0 94996 3908 ? S 10:58 0:00 nginx: worker process root 16387 0.0 0.0 94996 3980 ? S 10:58 0:00 nginx: worker process root 16388 0.0 0.0 94996 3980 ? S 10:58 0:00 nginx: worker process

2. 回滚

假设我们在关闭老的工作进行之后查看log发现新的nginx server执行有问题,我们能够回滚到老的版本号。其过程例如以下:

a) 启动老的worker 进程能够通过向old master 进程发送SIGHUP信号,让其启动老的worker 进程。

[root@lg-miui-file-mfs09 sbin]# ps aux | grep nginxroot     16385  0.0  0.0  92924  6072 ?        S    10:58   0:00 nginx: master process ./nginxroot     44583  0.0  0.0  92924  6076 ?

S 11:57 0:00 nginx: master process ./nginx root 44584 0.0 0.0 94996 3984 ? S 11:57 0:00 nginx: worker process root 44585 0.0 0.0 94996 3984 ? S 11:57 0:00 nginx: worker process root 44586 0.0 0.0 94996 3984 ?

S 11:57 0:00 nginx: worker process root 44757 0.0 0.0 94996 3908 ? S 11:58 0:00 nginx: worker process root 44758 0.0 0.0 94996 3980 ? S 11:58 0:00 nginx: worker process root 44759 0.0 0.0 94996 3980 ?

S 11:58 0:00 nginx: worker process

b) 关闭新的master进程和worker进程向新的master进程发送SIGQUIT信号。关闭新的master进程和worker进程;
[root@lg-miui-file-mfs09 sbin]# kill -s SIGQUIT 44583[root@lg-miui-file-mfs09 sbin]# ps aux | grep nginxroot     16385  0.0  0.0  92924  6072 ?        S    10:58   0:00 nginx: master process ./nginxroot     44757  0.0  0.0  94996  3908 ?        S    11:58   0:00 nginx: worker processroot     44758  0.0  0.0  94996  3980 ?        S    11:58   0:00 nginx: worker processroot     44759  0.0  0.0  94996  3980 ?        S    11:58   0:00 nginx: worker process

假设新的master进程因为某些原因hung住了没有关闭,能够向它们发送SIGTERM或者SIGKILL信号。当新的master进程退出后。老的master进程会将nginx.pid.oldbin文件重命名为nginx.pid. 

參考文献:

Nginx:

陶辉。

你可能感兴趣的文章
常用选择器
查看>>
eclipse 调试多线程
查看>>
各种排序算法
查看>>
条码控件商IDAutomation极大改善了Barcode Image Generator性能
查看>>
AxureRP7.0基础教程系列 部件详解 Menu 菜单
查看>>
SpringMVC 搭建及详解
查看>>
PCC-S-02201
查看>>
solr的分词器
查看>>
源码包安装
查看>>
docker hello-world
查看>>
5个词 带你回忆2014 IT安全圈
查看>>
微信小程序从入门到项目实战
查看>>
CentOS7 安装执行 VmwareCore
查看>>
EL表达式详解
查看>>
docker容器
查看>>
系统性能指标查看方法-Linux
查看>>
Android应用退出的认识
查看>>
BAT及各大互联网公司2014前端笔试面试题--JavaScript篇
查看>>
AirTight C-60 AP
查看>>
我的友情链接
查看>>