平滑升级你的Nginx
1、概述(可以直接跳过看第2部分)
Nginx方便地帮助我们实现了平滑升级。其原理简单概括,就是:
(1)在不停掉老进程的情况下,启动新进程。
(2)老进程负责处理仍然没有处理完的请求,但不再接受处理请求。
(3)新进程接受新请求。
(4)老进程处理完所有请求,关闭所有连接后,停止。
这样就很方便地实现了平滑升级。一般有两种情况下需要升级Nginx,一种是确实要升级Nginx的版本,另一种是要为Nginx添加新的模块。
2. 升级过程
具体的操作也很简单,如下:
(0)查看当前版本
在存放Nginx的可执行文件的目录下输入:
- ./nginx -V
(1)下载新的Nginx版本并编译。
- wget nginx-1.0.11.tar.gz
- tar zxvf nginx-1.0.11.tar.gz
- cd nginx-1.0.11
- ./configure --add-module=/customized_module_0 --add-module=/customized_module_1
- make
注意不要进行make install
(2)备份老版本的可执行文件
- cd /usr/local/nginx/sbin
- sudo 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.11
- make 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/nginx
- nobody 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 process
- nobody 6253 6241 0 10:51 ? 00:00:00 nginx: cache loader process
- luming 6310 25051 0 10:51 pts/1 00:00:00 grep --color=auto nginx
- nobody 7995 10419 0 Jan12 ? 00:20:37 nginx: worker process is shutting down
- nobody 7996 10419 0 Jan12 ? 00:20:11 nginx: worker process is shutting down
- nobody 7998 10419 0 Jan12 ? 00:20:04 nginx: worker process is shutting down
- nobody 8003 10419 0 Jan12 ? 00:20:12 nginx: worker process is shutting down
- 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只有两个了:
- root 6241 10419 0 10:51 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
- nobody 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 process
- nobody 6253 6241 0 10:51 ? 00:00:00 nginx: cache loader process
- luming 6430 25051 0 10:51 pts/1 00:00:00 grep --color=auto nginx
- nobody 7996 10419 0 Jan12 ? 00:20:11 nginx: worker process is shutting down
- nobody 8003 10419 0 Jan12 ? 00:20:12 nginx: worker process is shutting down
- root 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/nginx
- nobody 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 process
- luming 8680 25051 0 10:56 pts/1 00:00:00 grep --color=auto nginx
Congratulations! You can upgrade your Nginx server gracefully.
平滑升级你的Nginx的更多相关文章
- 高性能Web服务器Nginx的配置与部署研究(14)平滑升级你的Nginx
1.概述(可以直接跳过看第2部分) Nginx方便地帮助我们实现了平滑升级.其原理简单概括,就是: (1)在不停掉老进程的情况下,启动新进程. (2)老进程负责处理仍然没有处理完的请求,但不再接受处理 ...
- 原创|1分钟搞定 Nginx 版本的平滑升级与回滚
Nginx无论是对于运维.开发.还是测试来说,都是日常工作需要掌握的一个知识点,之前也写过不少关于Nginx相关的文章: Nginx服务介绍与安装 Nginx服务配置文件介绍 Nginx配置虚拟主机 ...
- nginx的平滑升级,不间断服务
nginx的平滑升级,不间断服务 Nginx更新真的很快,最近nginx的1.0.5稳定版,nginx的0.8.55和nginx的0.7.69旧的稳定版本已经发布.我一项比较喜欢使用新版本的软件, ...
- Nginx在线服务状态下平滑升级或新增模块的详细操作
今天应开发的需求,需要在Nginx增加一个模块,并不能影响现有的业务,所以就必须要平滑升级Nginx,好了,不多说了 1:查看现有的nginx编译参数 /usr/local/nginx/sbin/ng ...
- 让你的网站免费支持 HTTPS 及 Nginx 平滑升级
为什么要使用 HTTPS ? 首先来说一下 HTTP 与 HTTPS 协议的区别吧,他们的根本区别就是 HTTPS 在 HTTP 协议的基础上加入了 SSL 层,在传输层对网络连接进行加密.简单点说在 ...
- nginx 平滑升级tengine
wget http://tengine.taobao.org/download/tengine-1.5.1.tar.gz //下载Tengine1.5.1版本 tar zxvf tengine-1. ...
- 源码安装nginx以及平滑升级
源码安装nginx以及平滑升级 ...
- nginx平滑重启与平滑升级的方法
如何实现nginx平滑重启与平滑升级? 平滑重启 kill -HUP `cat /usr/local/www/nginx/logs/nginx.pid` 平滑升级nginx: cd /yujialin ...
- Nginx的平滑重启和平滑升级
一,Nginx的平滑重启如果改变了Nginx的配置文件(nginx.conf),想重启Nginx,可以发送系统信号给Nginx主进程的方式来进行.在重启之前,要确认Nginx配置文件的语法是正确的. ...
随机推荐
- 使用Spring Cloud搭建服务注册中心
我们在之前的博客中已经介绍过阿里的分布式服务框架dubbo[Linux上安装Zookeeper以及一些注意事项][一个简单的案例带你入门Dubbo分布式框架],但是小伙伴们应该也看到了,阿里的dubb ...
- 你安装的是SUN/Oracle JDK还是OpenJDK?
目录 1 如何查看你安装的JDK版本 1.1 要用到的命令行工具 1.2 查看JDK的版本 2 什么是 OpenJDK 2.1 OpenJDK 的来历 2.2 Oracle JDK的来历 3 Orac ...
- Chapter 5 Blood Type——6
"Yes — giving up trying to be good. I'm just going to do what I want now, and let the chips fal ...
- [ Java面试题 ]并发篇
1.Java内存模型是什么? Java内存模型规定和指引Java程序在不同的内存架构.CPU和操作系统间有确定性地行为.它在多线程的情况下尤其重要.Java内存模型对一个线程所做的变动能被其它线程可见 ...
- 开源库Magicodes.Storage正式发布
说明 Magicodes.Storage,是心莱科技团队提供的统一存储库,相关库均使用.NET标准库(netstandard2.0)编写,支持.NET Framework以及.NET Core. 我们 ...
- springboot情操陶冶-jmx解析
承接前文springboot情操陶冶-@Configuration注解解析,近期笔者接触的项目中有使用到了jmx的协议框架,遂在前文的基础上讲解下springboot中是如何整合jmx的 知识储备 J ...
- SQL——嵌套查询与子查询
前言 sql的嵌套查询可以说是sql语句中比较复杂的一部分,但是掌握好了的话就可以提高查询效率.下面将介绍带in的子查询.带比较运算符的子查询.带any/all的子查询.带exists的子查询以及基于 ...
- mac终端代理
终端代理,需要首先有自己的梯子,以下方式需要配合shadowsocks 终端FQ有很多好处,对于一个程序员来说,墙外有很多优秀的代码,走终端可以方便下载和使用- (编程思想强调复用,软件开发避免重复造 ...
- SpringCloud系列——Eureka 服务注册与发现
前言 Eureka是一种基于REST(具像状态传输)的服务,主要用于AWS云中定位服务,以实现中间层服务器的负载平衡和故障转移.本文记录一个简单的服务注册与发现实例. GitHub地址:https:/ ...
- 用C#写的一个OA类的APP, ios、Android都能跑,有源代码
这是一个用C#写的OA类APP,功能包含请假.报销.部门管理.签到.IM.文件上传等功能 话不多说,先看视频 视频地址:http://v.youku.com/v_show/id_XMzUwMjQ1Mz ...