nginx升级与回退
nginx1.16.1的部署安装我参考的这个博客https://www.cnblogs.com/FengGeBlog/p/13534156.html。先看下这个文章,然后一会我们对这个进行版本升级
注意:下文将1.16.1版本成为旧版本nginx,1.18.0成为新版本nginx
1、先确认旧的nginx进程是已经存在的
旧版本nginx启动进程
[root@master2 nginx]# ps aux | grep nginx
root 17440 0.0 0.0 79732 1496 ? Ss 11:42 0:00 nginx: master process sbin/nginx
nobody 17441 0.0 0.0 80120 2212 ? S 11:42 0:00 nginx: worker process
nobody 17442 0.0 0.1 80120 2456 ? S 11:42 0:00 nginx: worker process
nobody 17443 0.0 0.0 80120 2212 ? S 11:42 0:00 nginx: worker process
nobody 17444 0.0 0.1 80120 2456 ? S 11:42 0:00 nginx: worker process
nobody 17445 0.0 0.0 80120 2212 ? S 11:42 0:00 nginx: worker process
旧版本的nginx我已经启动了,设置5个worker进程。
2、开始编译安装新版本1.18.0的nginx
编译的步骤如下所示:
wget http://nginx.org/download/nginx-1.18.0.tar.gz
mv nginx-1.18.0.tar.gz /usr/local
cd /usr/local
tar xf nginx-1.18.0.tar.gz
先获取旧版本nginx编译的选项
[root@master2 nginx]# sbin/nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_image_filter_module --with-http_geoip_module --with-http_gunzip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
拿到这个选项,然后放在新版本nginx里面。执行configure
[root@master2 nginx-1.18.0]# pwd
/usr/local/nginx-1.18.0
[root@master2 nginx-1.18.0]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_image_filter_module --with-http_geoip_module --with-http_gunzip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
checking for GeoIP IPv6 support ... found
creating objs/MakefileConfiguration summary+ using system PCRE library+ using system OpenSSL library+ using system zlib librarynginx path prefix: "/usr/local/nginx"nginx binary file: "/usr/local/nginx/sbin/nginx"nginx modules path: "/usr/local/nginx/modules"nginx configuration prefix: "/usr/local/nginx/conf"nginx configuration file: "/usr/local/nginx/conf/nginx.conf"nginx pid file: "/usr/local/nginx/logs/nginx.pid"nginx error log file: "/usr/local/nginx/logs/error.log"nginx http access log file: "/usr/local/nginx/logs/access.log"nginx http client request body temporary files: "client_body_temp"nginx http proxy temporary files: "proxy_temp"nginx http fastcgi temporary files: "fastcgi_temp"nginx http uwsgi temporary files: "uwsgi_temp"nginx http scgi temporary files: "scgi_temp"
注意:有些人可能有疑惑,新下载的nginx在执行./configure的时候–prefix指定的目录是需要指向旧的nginx所指向的prefix目录还是随便指向一个就行,答案是需要指向旧版本的nginx的安装目录
执行make命令
[root@master2 nginx-1.18.0]# make
执行完成之后不要执行make install指令,这点需要注意。
3、平滑升级
3.1、先备份旧的nginx二进制可执行程序
[root@master2 nginx-1.18.0]# cd /usr/local/nginx/sbin
[root@master2 sbin]# ls
nginx
[root@master2 sbin]# cp nginx{,.bak}
[root@master2 sbin]# ls
nginx nginx.bak
3.2、查看未升级前的nginx版本
[root@master2 sbin]# ./nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC
xxxx
xxx
3.3、找到nginx-1.18.0新版本的nginx的二进制执行程序
[root@master2 sbin]# cd /usr/local/nginx-1.18.0/
[root@master2 nginx-1.18.0]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@master2 nginx-1.18.0]# cd objs
[root@master2 objs]# ls
autoconf.err Makefile nginx nginx.8 ngx_auto_config.h ngx_auto_headers.h ngx_modules.c ngx_modules.o src
上面的这个nginx就是我们要拿到的新版本的nginx可执行程序文件。
3.4、使用nginx-1.18.0的二进制文件将nginx-1.16.1的二进制文件进行强制覆盖
[root@master2 objs]# cp -f nginx /usr/local/nginx/sbin/nginx
cp: overwrite ‘/usr/local/nginx/sbin/nginx’? y
3.5、设定旧的服务不再接收用户请求(下线),新服务启动子进程接收用户请求(上线)
先查看当前未升级的nginx进程(这是旧版本的nginx进程)
[root@master2 objs]# ps aux | grep nginx
root 17440 0.0 0.0 79732 1496 ? Ss 11:42 0:00 nginx: master process sbin/nginx
nobody 17441 0.0 0.0 80120 2212 ? S 11:42 0:00 nginx: worker process
nobody 17442 0.0 0.1 80120 2456 ? S 11:42 0:00 nginx: worker process
nobody 17443 0.0 0.0 80120 2212 ? S 11:42 0:00 nginx: worker process
nobody 17444 0.0 0.1 80120 2456 ? S 11:42 0:00 nginx: worker process
nobody 17445 0.0 0.1 80120 2456 ? S 11:42 0:00 nginx: worker process
找到nginx父进程的pid号,现在对其发送USR2信号
[root@master2 objs]# kill -USR2 17440 #设定新的子进程开始接收用户的访问请求,旧的不再接受用户的访问请求
再次查看进程
[root@master2 objs]# ps aux | grep nginx
root 17440 0.0 0.0 79732 1496 ? Ss 11:42 0:00 nginx: master process sbin/nginx
nobody 17441 0.0 0.0 80120 2212 ? S 11:42 0:00 nginx: worker process
nobody 17442 0.0 0.1 80120 2456 ? S 11:42 0:00 nginx: worker process
nobody 17443 0.0 0.0 80120 2212 ? S 11:42 0:00 nginx: worker process
nobody 17444 0.0 0.1 80120 2456 ? S 11:42 0:00 nginx: worker process
nobody 17445 0.0 0.1 80120 2456 ? S 11:42 0:00 nginx: worker process
root 21081 0.5 0.1 79740 4080 ? S 20:00 0:00 nginx: master process sbin/nginx
nobody 21082 0.0 0.0 80192 2200 ? S 20:00 0:00 nginx: worker process
nobody 21083 0.0 0.0 80192 2200 ? S 20:00 0:00 nginx: worker process
nobody 21084 0.0 0.0 80192 2200 ? S 20:00 0:00 nginx: worker process
nobody 21085 0.0 0.0 80192 2200 ? S 20:00 0:00 nginx: worker process
nobody 21086 0.0 0.0 80192 2200 ? S 20:00 0:00 nginx: worker process
现在是nginx的新老版本的进程共存的一种情况。虽然现在旧版本的nginx进程还存在,但是已经不再接受用户的请求了。除此之外,旧版本的nginx进程也依然处于监听的状态,我们通过lsof命令可以看到,比如:
[root@master2 objs]# lsof -p 17440 | grep LISTEN # 这里的pid号是旧版本的nginx的master进程的pid号
nginx 17440 root 6u IPv4 120768 0t0 TCP *:http (LISTEN)
虽然在监听,但实际不会处理新连接,因为fd已经从epoll中移出了。另外,旧master是新master的父进程,所以新master才能共享打开的监听端口。保留旧版本的master是为了方便回滚(当然你可以发信号QUIT或者直接杀掉进程)
3.6、进行旧服务进程的关闭
[root@master2 objs]# kill -WINCH 17440 # 进行旧服务进程的关闭,该pid号是旧版本的nginx的master进程的pid号
再次查看当前nginx进程
[root@master2 objs]# ps aux | grep nginx
root 17440 0.0 0.0 79732 1652 ? Ss 11:42 0:00 nginx: master process sbin/nginx
root 21081 0.0 0.1 79740 4080 ? S 20:00 0:00 nginx: master process sbin/nginx
nobody 21082 0.0 0.0 80192 2200 ? S 20:00 0:00 nginx: worker process
nobody 21083 0.0 0.0 80192 2200 ? S 20:00 0:00 nginx: worker process
nobody 21084 0.0 0.0 80192 2200 ? S 20:00 0:00 nginx: worker process
nobody 21085 0.0 0.0 80192 2200 ? S 20:00 0:00 nginx: worker process
nobody 21086 0.0 0.0 80192 2200 ? S 20:00 0:00 nginx: worker process
可以看到现在的旧版本的nginx的worker进程已经全部被杀死了,只剩下的旧版本nginx的master进程
确定升级没有任何问题的话,那么现在我们可以把这个master进程给杀死掉。可以用kill -QUIT把旧master进程杀掉。方法已经教给大家了,但是这里我先不杀死,因为我还要往下演示如何回退。
3.7、查看当前nginx的版本
[root@master2 nginx]# sbin/nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_image_filter_module --with-http_geoip_module --with-http_gunzip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
可以看到现在已经升级成功了。
还可以访问一下
[root@master2 nginx]# curl http://192.168.50.129
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
xxx
xxx
xxx
4、现在我们演示一下如何回退
这种情况主要是用于当新版本的nginx升级失败之后,我们立马回退到旧版本的nginx
4.1、将旧版本的nginx二进制文件强行覆盖
[root@master2 sbin]# mv nginx.bak nginx
mv: overwrite ‘nginx’? y
查看进程
[root@master2 sbin]# ps aux | grep nginx
root 17440 0.0 0.0 79732 1652 ? Ss Aug20 0:00 nginx: master process sbin/nginx
root 21081 0.0 0.1 79740 4080 ? S Aug20 0:00 nginx: master process sbin/nginx
nobody 21082 0.0 0.0 80192 2200 ? S Aug20 0:00 nginx: worker process
nobody 21083 0.0 0.1 80192 2452 ? S Aug20 0:00 nginx: worker process
nobody 21084 0.0 0.0 80192 2200 ? S Aug20 0:00 nginx: worker process
nobody 21085 0.0 0.0 80192 2200 ? S Aug20 0:00 nginx: worker process
nobody 41895 0.0 0.0 80192 2200 ? S 10:53 0:00 nginx: worker process
4.2、向旧版本nginx进程发送HUP信号
[root@master2 sbin]# kill -HUP 17440 #注意这是旧版本的nginx进程pid号
说明一下:这个命令就相当与reload指令的作用,把旧的nginx的worker进程拉起来,但是咱们并不是直接使用reload的方式来执行,而是发送HUP信号,它会在没有worker进程时启动worker进程,这点需要注意一下。此时再次查看进程
[root@master2 sbin]# ps aux | grep nginx
root 17440 0.0 0.0 79732 1652 ? Ss Aug20 0:00 nginx: master process sbin/nginx
root 21081 0.0 0.1 79740 4080 ? S Aug20 0:00 nginx: master process sbin/nginx
nobody 21082 0.0 0.0 80192 2200 ? S Aug20 0:00 nginx: worker process
nobody 21083 0.0 0.1 80192 2452 ? S Aug20 0:00 nginx: worker process
nobody 21084 0.0 0.0 80192 2200 ? S Aug20 0:00 nginx: worker process
nobody 21085 0.0 0.0 80192 2200 ? S Aug20 0:00 nginx: worker process
nobody 41895 0.0 0.0 80192 2200 ? S 10:53 0:00 nginx: worker process
nobody 42070 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
nobody 42071 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
nobody 42072 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
nobody 42073 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
nobody 42074 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
发现多了很多worker进程,多出来的部分是旧版本的nginx进程。
4.3、让新版本的服务停止接收用户请求
[root@master2 sbin]# kill -USR2 21081
此时,接收用户请求的是旧版本的nginx进程。新版本的nginx进程不再接受用户请求
4.4、进行新版本服务进程的关闭
[root@master2 sbin]# kill -WINCH 21081
查看一下进程
[root@master2 sbin]# ps aux | grep nginx
root 17440 0.0 0.0 79732 1652 ? Ss Aug20 0:00 nginx: master process sbin/nginx
root 21081 0.0 0.1 79740 4080 ? S Aug20 0:00 nginx: master process sbin/nginx
nobody 42070 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
nobody 42071 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
nobody 42072 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
nobody 42073 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
nobody 42074 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
现在,旧版本已经回退成功了,我们可以把新版本的nginx的master进程发送QUIT进程将其退出。
4.5、kill掉新版本nginx进程
[root@master2 sbin]# kill -QUIT 21081
[root@master2 sbin]# ps aux | grep nginx
root 17440 0.0 0.0 79732 1652 ? Ss Aug20 0:00 nginx: master process sbin/nginx
nobody 42070 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
nobody 42071 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
nobody 42072 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
nobody 42073 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
nobody 42074 0.0 0.0 80120 2208 ? S 15:42 0:00 nginx: worker process
现在已经回退成功了
参考链接 :
nginx升级与回退 : https://mp.weixin.qq.com/s/8sgDMMtzfnimv_zjpzuGgw
nginx升级与回退相关推荐
- nginx的安装部署,热升级与回退,日志切割以及gzip(文字压缩)
1.安装部署nginx (1)安装 tar zxf nginx-1.14.0.tar.gz vim auto/cc/gcc #CFLAGS="$CFLAGS -g"##注销日志的d ...
- nginx 升级http请求到websocket
nginx 升级http请求到websocket #自定义变量 $connection_upgrade map $http_upgrade $connection_upgrade {default k ...
- android openssl漏洞,nginx升级之openssl 漏洞
环境 1 之前是yum 安装的 2 centos 6.5 步骤 升级openssl 升级nginx 升级openssl 为了修补openssl低版本存在的漏洞,现将Centos 6.5系统openss ...
- 【关于nginx升级---存在0day漏洞】
[关于nginx升级---存在0day漏洞]
- Nginx升级ssl版本
Nginx升级ssl版本 升级openSSL 版本到 1.0.1+ 官方上面推荐大家将OpenSSL升级到 OpenSSL 1.0.1g . 查看ssl版本 openssl version #Open ...
- 记录一次nginx升级,支持ipv4和ipv6访问https
项目要求,需要让现有网站项目支持https,并同时支持ipv6访问,经过分析,现在nginx版本较老,所以决定升级nignx,并且同步配置https和ipv6. 升级准备 服务器网络环境需要支持ipv ...
- nginx怎么升级php的版本号,nginx 升级指南,最详细的nginx升级步骤
查看nginx当前版本 通过nginx -V 命令就可以查看当前的版本,已经当前版本安装时候的一些nginx命令 [root@localhost sbin]# ./nginx -V nginx ver ...
- nginx升级修复(CVE-2016-4450)
修复以上漏洞 一.下载 nginx修复相对比较简单,到官网下载最新的版本http://nginx.org/en/download.html 或者直接系统 wget http://nginx.org/d ...
- ubuntu新版wireshark的升级与回退
新版wireshark的升级 普通方法安装wireshark最便捷的方式是 sudo apt-get install wireshark 虽然一个命令就能搞定,但是,wireshark的版本过于老旧, ...
最新文章
- squid日志文件太大,怎样处理?
- 新发布AlbumOnNet 、dotnetCharting控件注册资料
- 面试官:自己搭建过vue开发环境吗?
- 优先升级鸿蒙系统的华为(含荣耀)手机,优先升级鸿蒙系统的华为(含荣耀)手机:是这48款!有你的吗?...
- MongoDB 通过 Java 代码 CRUD 数据库与集合
- 实战Nginx(4)-压缩模块与http首部响应报文模块
- Android 自定义控件 Demo合集
- asp.net 设置div带颜色透明
- PPT——背景图格式(排版)和字体排版
- Kali 渗透测试:基于结构化异常处理的渗透-使用Python编写渗透模块
- warning: control reaches end of non-void function(C语言编译报错)
- 孩子们的世界很大,很大...(评刘海强日记)
- 2020-11-07 Mybatis
- RGB 到HSV转换 摘自wiki百科
- 单片机串口通讯RXD与TXD如何对接详解(独家!)
- 【云计算 | OpenStack】从零开始使用libvirt创建一个kvm虚机
- 贴片铝电解电容安装注意事项
- 投入产出核算的知识应用于业务数据分析的思路
- Lenovo 联想老主板装系统
- 涉及个人数据的发布与共享
热门文章
- python38环境变量的配置_Windows下python环境变量配置
- mysql会更改原excel吗,上传到mysql时,excel的日期发生变化
- Android仿人人客户端(v5.7.1)——对从服务器端(网络)获取的图片进行本地双缓存处理(编码实现)...
- 机器人煮面机创始人_那个火爆的煮面机器人搬走了!一大波机器人“入侵”,无人餐厅只是玩噱头?...
- MemCache详细解读(转)
- easyUi load方法重新加载表单的数据
- DB2 char()函数引起全表扫描
- 图像处理 - 滤波器 Filter
- 不谈商业模式,为什么众筹新闻难成功
- 关于mysql保存数据的时候报问题分析