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包管理工具pip的升级指南

《Python包管理工具pip的升级指南》本文全面探讨Python包管理工具pip的升级策略,从基础升级方法到高级技巧,涵盖不同操作系统环境下的最佳实践,我们将深入分析pip的工作原理,介绍多种升级方... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

前端如何通过nginx访问本地端口

《前端如何通过nginx访问本地端口》:本文主要介绍前端如何通过nginx访问本地端口的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、nginx安装1、下载(1)下载地址(2)系统选择(3)版本选择2、安装部署(1)解压(2)配置文件修改(3)启动(4)

Nginx 重写与重定向配置方法

《Nginx重写与重定向配置方法》Nginx重写与重定向区别:重写修改路径(客户端无感知),重定向跳转新URL(客户端感知),try_files检查文件/目录存在性,return301直接返回永久重... 目录一.try_files指令二.return指令三.rewrite指令区分重写与重定向重写: 请求

Nginx 配置跨域的实现及常见问题解决

《Nginx配置跨域的实现及常见问题解决》本文主要介绍了Nginx配置跨域的实现及常见问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来... 目录1. 跨域1.1 同源策略1.2 跨域资源共享(CORS)2. Nginx 配置跨域的场景2.1

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

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