高性能Web服务器Nginx的配置与部署研究(14)平滑升级你的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.
高性能Web服务器Nginx的配置与部署研究(14)平滑升级你的Nginx的更多相关文章
- 高性能Web服务器Nginx的配置与部署研究(13)应用模块之Memcached模块+Proxy_Cache双层缓存模式
通过<高性能Web服务器Nginx的配置与部署研究——(11)应用模块之Memcached模块的两大应用场景>一文,我们知道Nginx从Memcached读取数据的方式,如果命中,那么效率 ...
- 高性能Web服务器Nginx的配置与部署研究(7)核心模块之主模块的非测试常用指令
1. error_log 含义:指定存储错误日志的文件 语法:error_log <file> [debug|info|notice|warn|error|crit] 缺省:${prefi ...
- 高性能Web服务器Nginx的配置与部署研究(11)应用模块之Memcached模块的两大应用场景
一.应用场景1 最近在一个项目中,用到了Nginx的Memcached模块,所以就在这个系列教程中提前把Memcached模块拿出来写了.另外发现最近我的 博客文章频频被很多用采集器的网站拿走,帮我发 ...
- 高性能Web服务器Nginx的配置与部署研究(2)Nginx入门级配置与部署及“Hello World”
1. Nginx 程序包 目前最新的开发版本时1.1.12: Linux/Unix:nginx-1.1.12.tar.gz Windows:nginx-1.1.12.zip 我们可以下载稳定版尝试: ...
- 高性能Web服务器Nginx的配置与部署研究(1)Nginx简介及入门示例
概述 从这篇博文起,将带领读者们一起领略Nginx的强大. Nginx 是做什么用的?我相信很多朋友都已经使用过,如果你没有,那么你一定知道以下这些名称之一:Apache,Lighttpd,Tomca ...
- 高性能Web服务器Nginx的配置与部署研究(3)Nginx请求处理机制
1. 处理什么样的请求 处理访问到 Nginx 所在 IP 地址的请求,并且这些请求的 HTTP 头信息中的 Host 为所要处理的域名(如下以80端口为例),如下几个 server 就对应响应的请求 ...
- 高性能Web服务器Nginx的配置与部署研究(4)Nginx常用命令
1. 启动 Nginx poechant@ubuntu:sudo ./sbin/nginx 2. 停止 Nginx poechant@ubuntu:sudo ./sbin/nginx -s stop ...
- 高性能Web服务器Nginx的配置与部署研究(8)核心模块之事件模块
一.事件模块的作用是什么? 用来设置Nginx处理链接请求. 二.相关指令 1. accept_mutex 含义:设置是否使用连接互斥锁进行顺序的accept()系统调用. 语法:accept_mut ...
- 高性能Web服务器Nginx的配置与部署研究系列(1)-- 入门 hello work
简介: Nginx 是一个基于 BSD-like 协议.开源.高性能.轻量级的HTTP服务器.反向代理服务器以及电子邮件(SMTP.POP3.IMAP)服务器.Nginx 是由一个俄罗斯的名叫“Igo ...
随机推荐
- mysql导入外部sql脚本的方法
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011043843/article/details/29689853 导入的方法分为两种:一是採用图 ...
- @Autowired & @Resource 区别 & 解读@Bean
一样 Autowired & @Resource 都可以用来Bean的注入,可以写在属性(字段)上.也可以写在setter方法上 不一样 1.来源不一样 @Autowired 由Spr ...
- ORACLE11g 没有控制文件如何通过rman备份恢复数据的详细实战过程
1.副总裁需要裸恢复的严峻现实 集团总部的信息部负责人给我打电话说为了找一年前的记录,所以需要对一年前2015年5月1日的数据进行恢复.而2016年初因为进行迁移,所以有些文件可能丢失,手上只有rma ...
- 设置Maven的Web工程启动名称
java application的web工程名称就是工程名称:但是maven则不同,他的默认的website名称是在maven的pom文件里面的artifactId节点配置的值:例如: <gro ...
- angularJS自定义一个过滤器
ng允许我们自定义指令 下面来我们自己来定义一个过滤指令:filter,返回一个函数的形式 filter(name,callback(){//name:过滤器的名字,callback:匿名函数 ret ...
- Eclipse git插件使用
1.Eclipse git插件使用 1)配置提交用户名和邮箱 2)在eclipse中选择Show View 搜索git 3)点击clone按钮 选择代码保存路径 4)导入项目 5)git插件功能介绍 ...
- Java-Runoob:Java StringBuffer 类
ylbtech-Java-Runoob:Java StringBuffer 类 1.返回顶部 1. Java StringBuffer 和 StringBuilder 类 当对字符串进行修改的时候,需 ...
- 条件随机场(CRF)-基础
条件随机场(conditional random fields,简称 CRF,或CRFs)下文简称CRF,是一种典型的判别模型,相比隐马尔可夫模型可以没有很强的假设存在,在分词.词性标注.命名实体识别 ...
- Linux常用命令英文缩写
命令缩写: ls:list(列出目录内容) cd:Change Directory(改变目录) su:switch user 切换用户 (ubuntu 使用管理员权限 是 sudo) rpm ...
- 【BZOJ】1441 Min(数学)
题目 传送门:QWQ 分析 裴蜀定理. 因为存在 $ a_1 $ $ a_2 $...... $ a_n $的最大公约数为 $ d $,那么必定存在 $ x_1*a_1+x_2*a_2+...x_n* ...