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 ...
随机推荐
- 微信小程序使用本地图片在真机不显示的问题
最近做的小程序,在真机测试发现有些本地图片在开发工具上可以显示,但是在真机上预览的时候不能显示 代码是这样写的 <view class='seat-size' wx:for="{{it ...
- LGOJP4381 [IOI2008]Island
题目链接 https://www.luogu.org/problem/P4381 题解 基环树直径的板子.但是dfs会爆栈...所以最后改成了bfs.还是一个很考验码力的板子. 首先基环树的直径显然有 ...
- python实现抖音多线程下载无水印视频【附源码】
昨天发了一个无水印解析,评论说想要多线程下载,还是比较简单的. py文件同目录下创建url.txt,把链接一行一行复制进去,就能批量下载. 代码中的延时不能去掉,由于是多线程,速度较快,延时很重要. ...
- workerman——消息推送(web-msg-send)
前言 说下场景,当后台将号码池的号码分配给指定客服的时候,需要给指定的客户推送一条消息告诉该客户,通讯录有新增数据. 步骤 下载 https://www.workerman.net/web-sende ...
- Chocolatey——windows下的包管理器
前言 windows 包管理器 | https://chocolatey.org/ 命令 文档 | https://chocolatey.org/docs 根据使用会补充命令
- getchar()函数举例
#include<stdio.h>void main(){ char ch; ch=getchar(); printf("%c",ch);}
- Kafka为什么速度那么快?该怎么回答
Kafka的消息是保存或缓存在磁盘上的,一般认为在磁盘上读写数据是会降低性能的,因为寻址会比较消耗时间,但是实际上,Kafka的特性之一就是高吞吐率.即使是普通的服务器,Kafka也可以轻松支持每秒百 ...
- 自定义mvc增删改查
对t_mvc_book表的增删改查 导入jar包 BaseDao package com.hmc.util; import java.lang.reflect.Field; import java.s ...
- 溢出的文字隐藏(text-overflow)
<body> <div>一定要首先强制一行内显示,再次和overflow搭配使用,三个步骤缺一不可</div> </body> <style> ...
- PHP安装之configure的配置参数
1.生成环境安装配置如下 要求安装如下库: imagickgdmysqlmysqlimysqlndphalconPharsoapsocketsxwebxsvczipzlib 具体查看 vim php- ...