设为首页 收藏本站
查看: 691|回复: 0

[经验分享] 高性能Web服务器Nginx的配置与部署研究(14)平滑升级你的Nginx

[复制链接]

尚未签到

发表于 2016-12-24 06:27:52 | 显示全部楼层 |阅读模式
  1、概述(可以直接跳过看第2部分)
  Nginx方便地帮助我们实现了平滑升级。其原理简单概括,就是:
  

  (1)在不停掉老进程的情况下,启动新进程。
  (2)老进程负责处理仍然没有处理完的请求,但不再接受处理请求。
  (3)新进程接受新请求。
  (4)老进程处理完所有请求,关闭所有连接后,停止。
  

  这样就很方便地实现了平滑升级。一般有两种情况下需要升级Nginx,一种是确实要升级Nginx的版本,另一种是要为Nginx添加新的模块。
  

  2. 升级过程
  具体的操作也很简单,如下:
  

  (0)查看当前版本
  在存放Nginx的可执行文件的目录下输入:
./nginx -V
(1)下载新的Nginx版本并编译。wget nginx-1.0.11.tar.gztar zxvf nginx-1.0.11.tar.gzcd nginx-1.0.11./configure --add-module=/customized_module_0 --add-module=/customized_module_1make
注意不要进行make install  

  (2)备份老版本的可执行文件
cd /usr/local/nginx/sbinsudo cp nginx nginx.old
(3)修改配置文件  如果有必要的话,进行配置文件的修改。
  

  (4)拷贝新的可执行文件
sudo cp /home/michael/tmp/nginx-1.0.11/objs/nginx /usr/local/nginx/sbin/
(5)升级cd /home/michael/tmp/nginx-1.0.11make upgrade
  (6)清理多余文件
rm -rf /home/michael/tmp/nginx-1.0.11
(7)查看Nginx版本cd /usr/local/nginx/sbin./nginx -V
  3、观察进程变化
  在我的机器上可以观察到,我配置的是10个worker进程,启动后观察到:
root      6241 10419  0 10:51 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginxnobody    6242  6241  2 10:51 ?        00:00:00 nginx: worker process      nobody    6243  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6244  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6245  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6246  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6247  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6248  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6249  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6250  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6251  6241  1 10:51 ?        00:00:00 nginx: worker process      nobody    6252  6241  0 10:51 ?        00:00:00 nginx: cache manager processnobody    6253  6241  0 10:51 ?        00:00:00 nginx: cache loader processluming    6310 25051  0 10:51 pts/1    00:00:00 grep --color=auto nginxnobody    7995 10419  0 Jan12 ?        00:20:37 nginx: worker process is shutting downnobody    7996 10419  0 Jan12 ?        00:20:11 nginx: worker process is shutting downnobody    7998 10419  0 Jan12 ?        00:20:04 nginx: worker process is shutting downnobody    8003 10419  0 Jan12 ?        00:20:12 nginx: worker process is shutting downroot     10419     1  0 Jan08 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
可见新的进程有1个master和10个worker,另外还有1个老的master(可以从时间上看出)和4个worker(其他6个老的worker已经处理完所有连接而shutdown了)。还有一个loader进程。过几秒种可以看到worker只有两个了:root      6241 10419  0 10:51 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginxnobody    6242  6241  1 10:51 ?        00:00:00 nginx: worker process      nobody    6243  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6244  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6245  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6246  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6247  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6248  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6249  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6250  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6251  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6252  6241  0 10:51 ?        00:00:00 nginx: cache manager processnobody    6253  6241  0 10:51 ?        00:00:00 nginx: cache loader processluming    6430 25051  0 10:51 pts/1    00:00:00 grep --color=auto nginxnobody    7996 10419  0 Jan12 ?        00:20:11 nginx: worker process is shutting downnobody    8003 10419  0 Jan12 ?        00:20:12 nginx: worker process is shutting downroot     10419     1  0 Jan08 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
再过一小会儿观察:root      6241     1  0 10:51 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginxnobody    6242  6241  0 10:51 ?        00:00:01 nginx: worker process      nobody    6243  6241  0 10:51 ?        00:00:01 nginx: worker process      nobody    6244  6241  0 10:51 ?        00:00:01 nginx: worker process      nobody    6245  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6246  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6247  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6248  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6249  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6250  6241  0 10:51 ?        00:00:01 nginx: worker process      nobody    6251  6241  0 10:51 ?        00:00:02 nginx: worker process      nobody    6252  6241  0 10:51 ?        00:00:00 nginx: cache manager processluming    8680 25051  0 10:56 pts/1    00:00:00 grep --color=auto nginx
  Congratulations! You can upgrade your Nginx server gracefully.
  

  -

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-318465-1-1.html 上篇帖子: nginx+php5.5环境安装 下篇帖子: nginx+awstats+geoip详细步骤
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表