1、概述(可以直接跳过看第2部分)

Nginx方便地帮助我们实现了平滑升级。其原理简单概括,就是:

(1)在不停掉老进程的情况下,启动新进程。

(2)老进程负责处理仍然没有处理完的请求,但不再接受处理请求。

(3)新进程接受新请求。

(4)老进程处理完所有请求,关闭所有连接后,停止。

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

2. 升级过程

具体的操作也很简单,如下:

(0)查看当前版本

在存放Nginx的可执行文件的目录下输入:

  1. ./nginx -V

(1)下载新的Nginx版本并编译。

  1. wget nginx-1.0.11.tar.gz
  2. tar zxvf nginx-1.0.11.tar.gz
  3. cd nginx-1.0.11
  4. ./configure --add-module=/customized_module_0 --add-module=/customized_module_1
  5. make

注意不要进行make install

(2)备份老版本的可执行文件

  1. cd /usr/local/nginx/sbin
  2. sudo cp nginx nginx.old

(3)修改配置文件

如果有必要的话,进行配置文件的修改。

(4)拷贝新的可执行文件

  1. sudo cp /home/michael/tmp/nginx-1.0.11/objs/nginx /usr/local/nginx/sbin/

(5)升级

  1. cd /home/michael/tmp/nginx-1.0.11
  2. make upgrade

(6)清理多余文件

  1. rm -rf /home/michael/tmp/nginx-1.0.11

(7)查看Nginx版本

  1. cd /usr/local/nginx/sbin
  2. ./nginx -V

3、观察进程变化

在我的机器上可以观察到,我配置的是10个worker进程,启动后观察到:

  1. root      6241 10419  0 10:51 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
  2. nobody    6242  6241  2 10:51 ?        00:00:00 nginx: worker process
  3. nobody    6243  6241  0 10:51 ?        00:00:00 nginx: worker process
  4. nobody    6244  6241  0 10:51 ?        00:00:00 nginx: worker process
  5. nobody    6245  6241  0 10:51 ?        00:00:00 nginx: worker process
  6. nobody    6246  6241  0 10:51 ?        00:00:00 nginx: worker process
  7. nobody    6247  6241  0 10:51 ?        00:00:00 nginx: worker process
  8. nobody    6248  6241  0 10:51 ?        00:00:00 nginx: worker process
  9. nobody    6249  6241  0 10:51 ?        00:00:00 nginx: worker process
  10. nobody    6250  6241  0 10:51 ?        00:00:00 nginx: worker process
  11. nobody    6251  6241  1 10:51 ?        00:00:00 nginx: worker process
  12. nobody    6252  6241  0 10:51 ?        00:00:00 nginx: cache manager process
  13. nobody    6253  6241  0 10:51 ?        00:00:00 nginx: cache loader process
  14. luming    6310 25051  0 10:51 pts/1    00:00:00 grep --color=auto nginx
  15. nobody    7995 10419  0 Jan12 ?        00:20:37 nginx: worker process is shutting down
  16. nobody    7996 10419  0 Jan12 ?        00:20:11 nginx: worker process is shutting down
  17. nobody    7998 10419  0 Jan12 ?        00:20:04 nginx: worker process is shutting down
  18. nobody    8003 10419  0 Jan12 ?        00:20:12 nginx: worker process is shutting down
  19. root     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只有两个了:

  1. root      6241 10419  0 10:51 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
  2. nobody    6242  6241  1 10:51 ?        00:00:00 nginx: worker process
  3. nobody    6243  6241  0 10:51 ?        00:00:00 nginx: worker process
  4. nobody    6244  6241  0 10:51 ?        00:00:00 nginx: worker process
  5. nobody    6245  6241  0 10:51 ?        00:00:00 nginx: worker process
  6. nobody    6246  6241  0 10:51 ?        00:00:00 nginx: worker process
  7. nobody    6247  6241  0 10:51 ?        00:00:00 nginx: worker process
  8. nobody    6248  6241  0 10:51 ?        00:00:00 nginx: worker process
  9. nobody    6249  6241  0 10:51 ?        00:00:00 nginx: worker process
  10. nobody    6250  6241  0 10:51 ?        00:00:00 nginx: worker process
  11. nobody    6251  6241  0 10:51 ?        00:00:00 nginx: worker process
  12. nobody    6252  6241  0 10:51 ?        00:00:00 nginx: cache manager process
  13. nobody    6253  6241  0 10:51 ?        00:00:00 nginx: cache loader process
  14. luming    6430 25051  0 10:51 pts/1    00:00:00 grep --color=auto nginx
  15. nobody    7996 10419  0 Jan12 ?        00:20:11 nginx: worker process is shutting down
  16. nobody    8003 10419  0 Jan12 ?        00:20:12 nginx: worker process is shutting down
  17. root     10419     1  0 Jan08 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx

再过一小会儿观察:

  1. root      6241     1  0 10:51 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
  2. nobody    6242  6241  0 10:51 ?        00:00:01 nginx: worker process
  3. nobody    6243  6241  0 10:51 ?        00:00:01 nginx: worker process
  4. nobody    6244  6241  0 10:51 ?        00:00:01 nginx: worker process
  5. nobody    6245  6241  0 10:51 ?        00:00:00 nginx: worker process
  6. nobody    6246  6241  0 10:51 ?        00:00:00 nginx: worker process
  7. nobody    6247  6241  0 10:51 ?        00:00:00 nginx: worker process
  8. nobody    6248  6241  0 10:51 ?        00:00:00 nginx: worker process
  9. nobody    6249  6241  0 10:51 ?        00:00:00 nginx: worker process
  10. nobody    6250  6241  0 10:51 ?        00:00:01 nginx: worker process
  11. nobody    6251  6241  0 10:51 ?        00:00:02 nginx: worker process
  12. nobody    6252  6241  0 10:51 ?        00:00:00 nginx: cache manager process
  13. luming    8680 25051  0 10:56 pts/1    00:00:00 grep --color=auto nginx

Congratulations! You can upgrade your Nginx server gracefully.

平滑升级你的Nginx的更多相关文章

  1. 高性能Web服务器Nginx的配置与部署研究(14)平滑升级你的Nginx

    1.概述(可以直接跳过看第2部分) Nginx方便地帮助我们实现了平滑升级.其原理简单概括,就是: (1)在不停掉老进程的情况下,启动新进程. (2)老进程负责处理仍然没有处理完的请求,但不再接受处理 ...

  2. 原创|1分钟搞定 Nginx 版本的平滑升级与回滚

    Nginx无论是对于运维.开发.还是测试来说,都是日常工作需要掌握的一个知识点,之前也写过不少关于Nginx相关的文章: Nginx服务介绍与安装 Nginx服务配置文件介绍 Nginx配置虚拟主机 ...

  3. nginx的平滑升级,不间断服务

    nginx的平滑升级,不间断服务   Nginx更新真的很快,最近nginx的1.0.5稳定版,nginx的0.8.55和nginx的0.7.69旧的稳定版本已经发布.我一项比较喜欢使用新版本的软件, ...

  4. Nginx在线服务状态下平滑升级或新增模块的详细操作

    今天应开发的需求,需要在Nginx增加一个模块,并不能影响现有的业务,所以就必须要平滑升级Nginx,好了,不多说了 1:查看现有的nginx编译参数 /usr/local/nginx/sbin/ng ...

  5. 让你的网站免费支持 HTTPS 及 Nginx 平滑升级

    为什么要使用 HTTPS ? 首先来说一下 HTTP 与 HTTPS 协议的区别吧,他们的根本区别就是 HTTPS 在 HTTP 协议的基础上加入了 SSL 层,在传输层对网络连接进行加密.简单点说在 ...

  6. nginx 平滑升级tengine

    wget  http://tengine.taobao.org/download/tengine-1.5.1.tar.gz //下载Tengine1.5.1版本 tar zxvf tengine-1. ...

  7. 源码安装nginx以及平滑升级

                                                           源码安装nginx以及平滑升级                               ...

  8. nginx平滑重启与平滑升级的方法

    如何实现nginx平滑重启与平滑升级? 平滑重启 kill -HUP `cat /usr/local/www/nginx/logs/nginx.pid` 平滑升级nginx: cd /yujialin ...

  9. Nginx的平滑重启和平滑升级

    一,Nginx的平滑重启如果改变了Nginx的配置文件(nginx.conf),想重启Nginx,可以发送系统信号给Nginx主进程的方式来进行.在重启之前,要确认Nginx配置文件的语法是正确的. ...

随机推荐

  1. C++版 - 剑指offer 面试题23:从上往下打印二叉树(二叉树的层次遍历BFS) 题解

    剑指offer  面试题23:从上往下打印二叉树 参与人数:4853  时间限制:1秒  空间限制:32768K 提交网址: http://www.nowcoder.com/practice/7fe2 ...

  2. 从0打卡leetcode之day 3 -- 最大子序列和

    前言 就有要把leetcode的题刷完,每天一道题,每天进步一点点 从零打卡leetcode之day 3 题目描述: 给定一个int类型的数组,求最大子序列的和. 也就是说,从这个数组中截取一个子数组 ...

  3. 使用mpvue开发小程序教程(六)

    在上一章节中,我们列举了在Vue中能用但在mpvue中不能用或需要特别注意的特性,在实际开发前了解一下还是很有必要的,可以避免浪费找错误的时间. 如果你使用过原生的小程序框架,你一定经历过或思考过怎么 ...

  4. Chapter 4 Invitations——15

    He slouched off, back toward the school. 他无精打采的回去了学校. I heard a low chuckle. 我听到了低声的笑. Edward was wa ...

  5. spring cloud 配置zuul实用

    在线演示 演示地址:http://139.196.87.48:9002/kitty 用户名:admin 密码:admin 技术背景 前面我们通过Ribbon或Feign实现了微服务之间的调用和负载均衡 ...

  6. 导航页-LeetCode专题-Python实现

    LeetCode专题-Python实现之第1题:Two Sum LeetCode专题-Python实现之第7题:Reverse Integer LeetCode专题-Python实现之第9题:Pali ...

  7. Java提高班(一)Thread详解

    一.概述 在开始学习Thread之前,我们先来了解一下 线程和进程之间的关系: 线程(Thread)是进程的一个实体,是CPU调度和分派的基本单位. 线程不能够独立执行,必须依存在应用程序中,由应用程 ...

  8. .NET [MVC] 利用特性捕捉异常

    声明:本代码只适用于.NET MVC. 先创建一个类继承ActionFilterAttribute这个抽象类以及实现IExceptionFilter接口,并实现它的方法OnException. 代码如 ...

  9. hive 中遇到的正则

    1.提取科室中,"科"字前面的内容 regexp_extract(t1.doctor_department_format,'(.*)科') 2.去除字符串中的数字 第一种方式: S ...

  10. [PHP]命令执行函数的区别

    <?php $cmd="ps aux|grep php-fpm"; $res=exec($cmd,$o); var_dump($o);//数组形式返回,每行一个元素 var_ ...