openresty开发系列3--nginx的平滑升级
openresty开发系列3--nginx的平滑升级
nginx服务器从低版本升级为高版本,如果强行停止服务,会影响正在运行的进程。
平滑升级不会停掉正在运行中的进程,这些进程会继续处理请求。但不会接受新请求,这些老的进程在处理完请求之后会停止。此平滑升级过程中,新开的进程会被处理。
一)平滑升级
进入nginx可执行程序的目录
# cd /usr/local/nginx/sbin/
# sbin/nginx -v
nginx version: nginx/1.13.0 #查看nginx版本
1)下载高版本nginx
wget http://nginx.org/download/nginx-1.13.2.tar.gz
执行指令生成版本的Nginx二进制程序
# ./configure
# make #不能执行 make install
# cd objs
此目录下 有高版本的nginx
备份低版本的nginx
cd /usr/local/nginx/sbin/
cp nginx nginx.old
执行强制覆盖,将低版本的nginx替换为刚编译好的高版本的nginx
[root@node5 objs]# cp -rfp /usr/local/src/nginx-1.13.2/objs/nginx /usr/local/nginx/sbin/
cp: overwrite ‘/usr/local/nginx/sbin/nginx’? y
测试一下新复制过来文件生效情况:
# /usr/local/nginx/sbin/nginx -t
[root@node5 objs]# ps -ef|grep nginx
root 43151 1 0 19:40 ? 00:00:00 nginx: master process /usr/local//nginx/sbin/nginx
nobody 43152 43151 0 19:40 ? 00:00:00 nginx: worker process
nobody 43153 43151 0 19:40 ? 00:00:00 nginx: worker process
nobody 43154 43151 0 19:40 ? 00:00:00 nginx: worker process
nobody 43155 43151 0 19:40 ? 00:00:00 nginx: worker process
root 45585 43080 0 19:46 pts/1 00:00:00 grep --color=auto nginx
[root@node5 objs]# cat /usr/local/nginx/logs/nginx.pid
43151
2)执行信号平滑升级
# kill -USR2 `cat /usr/local/nginx/logs/nginx.pid` 更新配置文件
[root@node5 objs]# kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
给nginx发送USR2信号后,nginx会将logs/nginx.pid文件重命名为nginx.pid.oldbin,然后用新的可执行文件启动一个新的nginx主进程和对应的工作进程,并新建一个新的nginx.pid保存新的主进程号
[root@node5 objs]# cat /usr/local/nginx/logs/nginx.pid
45589
3)kill -WINCH 旧的主进程号
旧的主进程号收到WINCH信号后,将旧进程号管理的旧的工作进程优雅的关闭。即一段时间后旧的工作进程全部关闭,只有新的工作进程在处理请求连接。这时,依然可以恢复到旧的进程服务,因为旧的进程的监听socket还未停止。
处理完后,工作进程会自动关闭
[root@node5 objs]# ps -ef|grep nginx
root 43151 1 0 19:40 ? 00:00:00 nginx: master process /usr/local//nginx/sbin/nginx
nobody 43152 43151 0 19:40 ? 00:00:00 nginx: worker process
nobody 43153 43151 0 19:40 ? 00:00:00 nginx: worker process
nobody 43154 43151 0 19:40 ? 00:00:00 nginx: worker process
nobody 43155 43151 0 19:40 ? 00:00:00 nginx: worker process
root 45589 43151 0 19:46 ? 00:00:00 nginx: master process /usr/local//nginx/sbin/nginx
nobody 45590 45589 0 19:46 ? 00:00:00 nginx: worker process
nobody 45591 45589 0 19:46 ? 00:00:00 nginx: worker process
nobody 45592 45589 0 19:46 ? 00:00:00 nginx: worker process
nobody 45593 45589 0 19:46 ? 00:00:00 nginx: worker process
root 45595 43080 0 19:46 pts/1 00:00:00 grep --color=auto nginx
4)# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin` 优雅的关闭
给旧的主进程发送QUIT信号后,旧的主进程退出,并移除logs/nginx.pid.oldbin文件,nginx的升级完成。
升级完成了,最后在看一下升级后的版本
查看
[root@node5 objs]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.13.2
已经平滑升级成功
二)中途停止升级,回滚到旧的nginx
在步骤(3)时,如果想回到旧的nginx不再升级
(1)给旧的主进程号发送HUP命令,此时nginx不重新读取配置文件的情况下重新启动旧主进程的工作进程。
kill -HUP 43151 --旧主进程号
重启工作进程
(2)优雅的关闭新的主进程
kill -QUIT 45589 --新主进程号
openresty开发系列3--nginx的平滑升级的更多相关文章
- openresty开发系列2--nginx的简单安装,正向、反向代理及常用命令和信号控制介绍
openresty开发系列2--nginx的简单安装,正向.反向代理及常用命令和信号控制介绍 一.nginx的安装下载及编译安装1.Nginx下载:nginx-1.13.0.tar.gz,下载到:/u ...
- openresty开发系列10--openresty的简单介绍及安装
openresty开发系列10--openresty的简单介绍及安装 一.Nginx优点 十几年前,互联网没有这么火,软件外包开发,信息化建设,帮助企业做无纸化办公,收银系统,工厂erp,c/s架构偏 ...
- openresty开发系列40--nginx+lua实现获取客户端ip所在的国家信息
openresty开发系列40--nginx+lua实现获取客户端ip所在的国家信息 为了实现业务系统针对不同地区IP访问,展示包含不同地区信息的业务交互界面.很多情况下系统需要根据用户访问的IP信息 ...
- openresty开发系列38--通过Lua+Redis 实现动态封禁IP
openresty开发系列38--通过Lua+Redis 实现动态封禁IP 一)需求背景为了封禁某些爬虫或者恶意用户对服务器的请求,我们需要建立一个动态的 IP 黑名单.对于黑名单之内的 IP ,拒绝 ...
- openresty开发系列37--nginx-lua-redis实现访问频率控制
openresty开发系列37--nginx-lua-redis实现访问频率控制 一)需求背景 在高并发场景下为了防止某个访问ip访问的频率过高,有时候会需要控制用户的访问频次在openresty中, ...
- openresty开发系列36--openresty执行流程之6日志模块处理阶段
openresty开发系列36--openresty执行流程之6日志模块处理阶段 一)header_filter_by_lua 语法:header_filter_by_lua <lua-scri ...
- openresty开发系列35--openresty执行流程之5内容content阶段
openresty开发系列35--openresty执行流程之5内容content阶段 content 阶段 ---init阶段---重写赋值---重写rewrite---access content ...
- openresty开发系列34--openresty执行流程之4访问阶段
openresty开发系列34--openresty执行流程之4访问阶段 访问阶段 用途:访问权限限制 返回403 nginx:allow 允许,deny 禁止 allow ip:deny ip: 涉 ...
- openresty开发系列33--openresty执行流程之3重写rewrite和重定向
openresty开发系列33--openresty执行流程之3重写rewrite和重定向 重写rewrite阶段 1)重定向2)内部,伪静态 先介绍一下if,rewrite指令 一)if指令语法:i ...
随机推荐
- /bin/false和/sbin/nologin的区别
/bin/false是最严格的禁止login选项,一切服务都不能用./sbin/nologin只是不允许login系统 其中树莓派的/sbin/nologin文件在/usr/sbin/nologin小 ...
- java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType.Integer
mybatis配置的jdbaType类型要是大写的,否则就会出现此种异常 原因是在xml中配置的 jdbcType中有小写字母
- 「AHOI / HNOI2017」礼物
「AHOI / HNOI2017」礼物 题目描述 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手环,一个留给自己,一个送给她.每个手环上各有 n 个装饰物,并且每个装饰 ...
- css垂直居中的常用方法
CSS实现垂直居中的常用方法 2017-04-17 渔歌 前端开发 来自:渔歌 - 博客园 链接:www.cnblogs.com/yugege/p/5246652.html(点击尾部阅读原文前往) 已 ...
- Arthas使用指南
Arthas 能为你做什么? 这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception? 我改的代码为什么没有执行到?难道是我没 commit?分支搞错了? 遇到问题无法在预发 de ...
- 2019/8/20 Test
题目 简述 做法 \(BSOJ2237\) 求\(\displaystyle{k\in G:\sum_{i\in G\vee j\in G}\frac{C^k_{i,j}}{C_{i,j}}}\),其 ...
- 【CSS】div
一.div內容溢出 .remark-div { overflow: auto; height: auto; max-height: 100px; } 1.溢出 overflow :auto时,内容超过 ...
- 给各阶段java学习者的建议[转]
第一部分:零基础或基础薄弱的同学这部分主要适用于尚未做过Java工作的同学,包括一些在校生以及刚准备转行Java的同学.一.Java基础首先去找一个Java的基础教程学一下,这里可以推荐达内java课 ...
- C void的指针 强制类型转换(int*)p 把变量指针p强制转换成指向int类型的指针
#include <stdio.h> int main(void){ void *p; int a = 14322; char c ='A'; p = &a; //p = & ...
- codevs6003一次做对算我输
6003 一次做对算我输 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 大师 Master 题目描述 Description 更新数据了!!!!!!!更新数据了!!!!!! ...