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

相关文章

Python UV安装、升级、卸载详细步骤记录

《PythonUV安装、升级、卸载详细步骤记录》:本文主要介绍PythonUV安装、升级、卸载的详细步骤,uv是Astral推出的下一代Python包与项目管理器,主打单一可执行文件、极致性能... 目录安装检查升级设置自动补全卸载UV 命令总结 官方文档详见:https://docs.astral.sh/

苹果macOS 26 Tahoe主题功能大升级:可定制图标/高亮文本/文件夹颜色

《苹果macOS26Tahoe主题功能大升级:可定制图标/高亮文本/文件夹颜色》在整体系统设计方面,macOS26采用了全新的玻璃质感视觉风格,应用于Dock栏、应用图标以及桌面小部件等多个界面... 科技媒体 MACRumors 昨日(6 月 13 日)发布博文,报道称在 macOS 26 Tahoe 中

华为鸿蒙HarmonyOS 5.1官宣7月开启升级! 首批支持名单公布

《华为鸿蒙HarmonyOS5.1官宣7月开启升级!首批支持名单公布》在刚刚结束的华为Pura80系列及全场景新品发布会上,除了众多新品的发布,还有一个消息也点燃了所有鸿蒙用户的期待,那就是Ha... 在今日的华为 Pura 80 系列及全场景新品发布会上,华为宣布鸿蒙 HarmonyOS 5.1 将于 7

Windows的CMD窗口如何查看并杀死nginx进程

《Windows的CMD窗口如何查看并杀死nginx进程》:本文主要介绍Windows的CMD窗口如何查看并杀死nginx进程问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录Windows的CMD窗口查看并杀死nginx进程开启nginx查看nginx进程停止nginx服务

Nginx Location映射规则总结归纳与最佳实践

《NginxLocation映射规则总结归纳与最佳实践》Nginx的location指令是配置请求路由的核心机制,其匹配规则直接影响请求的处理流程,下面给大家介绍NginxLocation映射规则... 目录一、Location匹配规则与优先级1. 匹配模式2. 优先级顺序3. 匹配示例二、Proxy_pa

Windows 系统下 Nginx 的配置步骤详解

《Windows系统下Nginx的配置步骤详解》Nginx是一款功能强大的软件,在互联网领域有广泛应用,简单来说,它就像一个聪明的交通指挥员,能让网站运行得更高效、更稳定,:本文主要介绍W... 目录一、为什么要用 Nginx二、Windows 系统下 Nginx 的配置步骤1. 下载 Nginx2. 解压

Nginx 413修改上传文件大小限制的方法详解

《Nginx413修改上传文件大小限制的方法详解》在使用Nginx作为Web服务器时,有时会遇到客户端尝试上传大文件时返回​​413RequestEntityTooLarge​​... 目录1. 理解 ​​413 Request Entity Too Large​​ 错误2. 修改 Nginx 配置2.1

Web技术与Nginx网站环境部署教程

《Web技术与Nginx网站环境部署教程》:本文主要介绍Web技术与Nginx网站环境部署教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、Web基础1.域名系统DNS2.Hosts文件3.DNS4.域名注册二.网页与html1.网页概述2.HTML概述3.

NGINX 配置内网访问的实现步骤

《NGINX配置内网访问的实现步骤》本文主要介绍了NGINX配置内网访问的实现步骤,Nginx的geo模块限制域名访问权限,仅允许内网/办公室IP访问,具有一定的参考价值,感兴趣的可以了解一下... 目录需求1. geo 模块配置2. 访问控制判断3. 错误页面配置4. 一个完整的配置参考文档需求我们有一

使用Nginx配置文件服务器方式

《使用Nginx配置文件服务器方式》:本文主要介绍使用Nginx配置文件服务器方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1. 为什么选择 Nginx 作为文件服务器?2. 环境准备3. 配置 Nginx 文件服务器4. 将文件放入服务器目录5. 启动 N