nginx平滑升级与回滚

2024-09-01 06:20
文章标签 nginx 升级 回滚 平滑

本文主要是介绍nginx平滑升级与回滚,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

华子目录

  • 升级
    • 实验环境准备
    • 测试内容准备
    • 实验要求
    • 实验步骤
      • 1.解压包
      • 2.检测1.26版本的环境
      • 3.make编译
      • 4.备份之前的`nginx`启动脚本
      • 5.将1.26中的nginx启动脚本覆盖掉1.24中的
      • 6.`kill -USR2 旧主进程pid`
      • 7.`kill -WINCH 旧主进程pid`
    • 实验测试
  • 回滚
    • 1.`kill -HUP 旧主进程pid`
    • 2.`kill -WINCH 新主进程pid`
    • 3.备份`nginx`启动脚本
    • 4.`nginx.old`覆盖`nginx`
    • 5.`kill -9 新主进程pid`
    • 回滚测试

升级

实验环境准备

  • nginx版本:1.24
  • 需要升级到的版本:1.26
  • 需要的包:echo-nginx-module-0.63.tar.gznginx-1.24.0.tar.gznginx-1.26.2.tar.gz
[root@nginx ~]# ls
公共  视频  文档  音乐  anaconda-ks.cfg                nginx-1.24.0         nginx-1.26.2.tar.gz
模板  图片  下载  桌面  echo-nginx-module-0.63.tar.gz  nginx-1.24.0.tar.gz  vmset-rhel9-mountYum.sh

测试内容准备

[root@nginx ~]# cd /usr/local/nginx/html
[root@nginx html]# echo hello world > index.html[root@nginx html]# cat index.html
hello world
while true; do curl 172.25.254.100;sleep 1; done

在这里插入图片描述

实验要求

  • 在升级的过程中,原nginx提供的web服务不能中断
[root@nginx ~]# ps -ef | grep nginx
root       42795       1  0 09:31 ?        00:00:00 nginx: master process nginx
nginx      42796   42795  0 09:31 ?        00:00:00 nginx: worker process
root       42798   39792  0 09:31 pts/0    00:00:00 grep --color=auto nginx
[root@nginx ~]# curl -I 172.25.254.100
HTTP/1.1 200 OK
Server: nginx/1.24.0    #可以看到旧版本是1.24的
Date: Sat, 31 Aug 2024 13:32:21 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Sat, 31 Aug 2024 13:31:18 GMT
Connection: keep-alive
ETag: "66d31b26-267"
Accept-Ranges: bytes

实验步骤

1.解压包

[root@nginx ~]# tar -zxvf echo-nginx-module-0.63.tar.gz
[root@nginx ~]# tar -zxvf nginx-1.26.2.tar.gz

2.检测1.26版本的环境

[root@nginx ~]# cd nginx-1.26.2/
[root@nginx nginx-1.26.2]# ./configure --prefix=/usr/local/nginx \   #--prefix表示nginx安装的位置
> --user=nginx \   #指定nginx运行用户
> --group=nginx \   #指定nginx运行组
> --with-http_ssl_module \   #支持https://
> --with-http_v2_module \   #支持http版本2
> --with-http_realip_module \   #支持ip透传
> --with-http_stub_status_module \   #支持状态页面
> --with-http_gzip_static_module \   #支持压缩
> --with-pcre \      #支持正则
> --with-stream \    #支持tcp反向代理
> --with-stream_ssl_module   #支持tcp的ssl加密
> --add-module=/root/echo-nginx-module-0.63    #指定添加的模块路径(这个模块的作用:在nginx内部可以执行echo命令)

3.make编译

  • make编译,不要make install
[root@nginx nginx-1.26.2]# make

4.备份之前的nginx启动脚本

[root@nginx ~]# cd /usr/local/nginx/sbin/
[root@nginx sbin]# ls
nginx
[root@nginx sbin]# cp nginx nginx.old
[root@nginx sbin]# ls
nginx  nginx.old

5.将1.26中的nginx启动脚本覆盖掉1.24中的

#-f表示强制覆盖
[root@nginx sbin]# \cp -f /root/nginx-1.26.2/objs/nginx /usr/local/nginx/sbin/

6.kill -USR2 旧主进程pid

  • 使用kill -USR2启动一个新的只启动,不监听端口
[root@nginx sbin]# ps -aux | grep nginx
root       52797  0.0  0.0   9832   928 ?        Ss   10:56   0:00 nginx: master process nginx
nginx      52798  0.0  0.1  13720  5348 ?        S    10:56   0:00 nginx: worker process
root       52800  0.0  0.0 221680  2252 pts/0    S+   10:57   0:00 grep --color=auto nginx[root@nginx sbin]# pidof nginx
52798 52797[root@nginx sbin]# kill -USR2 52797      #指定master的pid[root@nginx sbin]# ps -aux | grep nginx
root       52797  0.0  0.0   9832  2396 ?        Ss   10:56   0:00 nginx: master process nginx
nginx      52798  0.0  0.1  13720  5348 ?        S    10:56   0:00 nginx: worker process
root       52823  0.0  0.1   9864  5912 ?        S    10:58   0:00 nginx: master process nginx
nginx      52824  0.0  0.1  13752  5308 ?        S    10:58   0:00 nginx: worker process
root       52826  0.0  0.0 221680  2324 pts/0    S+   10:58   0:00 grep --color=auto nginx
  • 此时访问还在继续

在这里插入图片描述

7.kill -WINCH 旧主进程pid

  • 使用kill -WINCH把旧的主进程回收掉
[root@nginx sbin]# kill -WINCH 52797[root@nginx sbin]# ps -aux | grep nginx
root       52797  0.0  0.0   9832  2396 ?        Ss   10:56   0:00 nginx: master process nginx
root       52823  0.0  0.1   9864  5912 ?        S    10:58   0:00 nginx: master process nginx
nginx      52824  0.0  0.1  13752  5308 ?        S    10:58   0:00 nginx: worker process
root       52842  0.0  0.0 221680  2316 pts/0    S+   11:03   0:00 grep --color=auto nginx
  • 此时访问还在继续

在这里插入图片描述

实验测试

[root@nginx sbin]# curl -I 172.25.254.100
HTTP/1.1 200 OK
Server: nginx/1.26.2   #可以看到版本升级成功
Date: Sat, 31 Aug 2024 15:04:16 GMT
Content-Type: text/html
Content-Length: 12
Last-Modified: Sat, 31 Aug 2024 14:43:41 GMT
Connection: keep-alive
ETag: "66d32c1d-c"
Accept-Ranges: bytes

在这里插入图片描述

  • 发现web服务也没有中断过

回滚

1.kill -HUP 旧主进程pid

[root@nginx sbin]# ps -aux | grep nginx
root       52797  0.0  0.0   9832  2396 ?        Ss   10:56   0:00 nginx: master process nginx
root       52823  0.0  0.1   9864  5912 ?        S    10:58   0:00 nginx: master process nginx
nginx      52824  0.0  0.1  13752  5308 ?        S    10:58   0:00 nginx: worker process
root       52848  0.0  0.0 221680  2344 pts/0    S+   11:06   0:00 grep --color=auto nginx[root@nginx sbin]# kill -HUP 52797[root@nginx sbin]# ps -aux | grep nginx
root       52797  0.0  0.0   9832  2396 ?        Ss   10:56   0:00 nginx: master process nginx
root       52823  0.0  0.1   9864  5912 ?        S    10:58   0:00 nginx: master process nginx
nginx      52824  0.0  0.1  13752  5308 ?        S    10:58   0:00 nginx: worker process
nginx      52849  0.0  0.1  13720  5348 ?        S    11:08   0:00 nginx: worker process
root       52851  0.0  0.0 221680  2356 pts/0    S+   11:08   0:00 grep --color=auto nginx

2.kill -WINCH 新主进程pid

  • 新的主进程回收了
[root@nginx sbin]# kill -WINCH 52823[root@nginx sbin]# ps -aux | grep nginx
root       52797  0.0  0.0   9832  2396 ?        Ss   10:56   0:00 nginx: master process nginx
root       52823  0.0  0.1   9864  6416 ?        S    10:58   0:00 nginx: master process nginx
nginx      52849  0.0  0.1  13720  5348 ?        S    11:08   0:00 nginx: worker process
root       52858  0.0  0.0 221680  2352 pts/0    S+   11:10   0:00 grep --color=auto nginx

3.备份nginx启动脚本

[root@nginx sbin]# ls
nginx  nginx.old
[root@nginx sbin]# cp nginx nginx.new
[root@nginx sbin]# ls
nginx  nginx.new  nginx.old

4.nginx.old覆盖nginx

[root@nginx sbin]# \cp -f nginx.old nginx
[root@nginx sbin]# ls
nginx  nginx.new  nginx.old

5.kill -9 新主进程pid

[root@nginx sbin]# ps -aux | grep nginx
root       52797  0.0  0.0   9832  2396 ?        Ss   10:56   0:00 nginx: master process nginx
root       52823  0.0  0.1   9864  6416 ?        S    10:58   0:00 nginx: master process nginx
nginx      52849  0.0  0.1  13720  5348 ?        S    11:08   0:00 nginx: worker process
root       52880  0.0  0.0 221680  2240 pts/0    S+   11:15   0:00 grep --color=auto nginx[root@nginx sbin]# kill -9 52823[root@nginx sbin]# ps -aux | grep nginx
root       52797  0.0  0.0   9832  2396 ?        Ss   10:56   0:00 nginx: master process nginx
nginx      52849  0.0  0.1  13720  5348 ?        S    11:08   0:00 nginx: worker process
root       52883  0.0  0.0 221680  2352 pts/0    S+   11:15   0:00 grep --color=auto nginx

回滚测试

[root@nginx sbin]# curl -I 172.25.254.100
HTTP/1.1 200 OK
Server: nginx/1.24.0   #发现已经回滚到旧版本
Date: Sat, 31 Aug 2024 15:12:01 GMT
Content-Type: text/html
Content-Length: 12
Last-Modified: Sat, 31 Aug 2024 14:43:41 GMT
Connection: keep-alive
ETag: "66d32c1d-c"
Accept-Ranges: bytes

在这里插入图片描述

  • 发现web服务也没有中断过

这篇关于nginx平滑升级与回滚的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1126183

相关文章

springboot上传zip包并解压至服务器nginx目录方式

《springboot上传zip包并解压至服务器nginx目录方式》:本文主要介绍springboot上传zip包并解压至服务器nginx目录方式,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录springboot上传zip包并解压至服务器nginx目录1.首先需要引入zip相关jar包2.然

如何使用Nginx配置将80端口重定向到443端口

《如何使用Nginx配置将80端口重定向到443端口》这篇文章主要为大家详细介绍了如何将Nginx配置为将HTTP(80端口)请求重定向到HTTPS(443端口),文中的示例代码讲解详细,有需要的小伙... 目录1. 创建或编辑Nginx配置文件2. 配置HTTP重定向到HTTPS3. 配置HTTPS服务器

通过Spring层面进行事务回滚的实现

《通过Spring层面进行事务回滚的实现》本文主要介绍了通过Spring层面进行事务回滚的实现,包括声明式事务和编程式事务,具有一定的参考价值,感兴趣的可以了解一下... 目录声明式事务回滚:1. 基础注解配置2. 指定回滚异常类型3. ​不回滚特殊场景编程式事务回滚:1. ​使用 TransactionT

Nginx中配置HTTP/2协议的详细指南

《Nginx中配置HTTP/2协议的详细指南》HTTP/2是HTTP协议的下一代版本,旨在提高性能、减少延迟并优化现代网络环境中的通信效率,本文将为大家介绍Nginx配置HTTP/2协议想详细步骤,需... 目录一、HTTP/2 协议概述1.HTTP/22. HTTP/2 的核心特性3. HTTP/2 的优

详解nginx 中location和 proxy_pass的匹配规则

《详解nginx中location和proxy_pass的匹配规则》location是Nginx中用来匹配客户端请求URI的指令,决定如何处理特定路径的请求,它定义了请求的路由规则,后续的配置(如... 目录location 的作用语法示例:location /www.chinasem.cntestproxy

将Mybatis升级为Mybatis-Plus的详细过程

《将Mybatis升级为Mybatis-Plus的详细过程》本文详细介绍了在若依管理系统(v3.8.8)中将MyBatis升级为MyBatis-Plus的过程,旨在提升开发效率,通过本文,开发者可实现... 目录说明流程增加依赖修改配置文件注释掉MyBATisConfig里面的Bean代码生成使用IDEA生

如何自定义Nginx JSON日志格式配置

《如何自定义NginxJSON日志格式配置》Nginx作为最流行的Web服务器之一,其灵活的日志配置能力允许我们根据需求定制日志格式,本文将详细介绍如何配置Nginx以JSON格式记录访问日志,这种... 目录前言为什么选择jsON格式日志?配置步骤详解1. 安装Nginx服务2. 自定义JSON日志格式各

Nginx指令add_header和proxy_set_header的区别及说明

《Nginx指令add_header和proxy_set_header的区别及说明》:本文主要介绍Nginx指令add_header和proxy_set_header的区别及说明,具有很好的参考价... 目录Nginx指令add_header和proxy_set_header区别如何理解反向代理?proxy

Nginx配置location+rewrite实现隐性域名配置

《Nginx配置location+rewrite实现隐性域名配置》本文主要介绍了Nginx配置location+rewrite实现隐性域名配置,包括基于根目录、条件和反向代理+rewrite配置的隐性... 目录1、配置基于根目录的隐性域名(就是nginx反向代理)2、配置基于条件的隐性域名2.1、基于条件

Ubuntu中Nginx虚拟主机设置的项目实践

《Ubuntu中Nginx虚拟主机设置的项目实践》通过配置虚拟主机,可以在同一台服务器上运行多个独立的网站,本文主要介绍了Ubuntu中Nginx虚拟主机设置的项目实践,具有一定的参考价值,感兴趣的可... 目录简介安装 Nginx创建虚拟主机1. 创建网站目录2. 创建默认索引文件3. 配置 Nginx4