nginx平滑升级与回滚

news2024/9/23 21:24:43

华子目录

  • 升级
    • 实验环境准备
    • 测试内容准备
    • 实验要求
    • 实验步骤
      • 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服务也没有中断过

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2093829.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【MySQL】索引性能分析工具详解——>为sql优化(select)做准备

前言 大家好吖,欢迎来到 YY 滴MySQL系列 ,热烈欢迎! 本章主要内容面向接触过C的老铁 主要内容含: 欢迎订阅 YY滴C专栏!更多干货持续更新!以下是传送门! YY的《C》专栏YY的《C11》专栏YY的《Lin…

机械学习—零基础学习日志(概率论总笔记1)

概率论的起源 在历史上有明确记载的最早研究随机性的数学家是帕斯卡和费马。帕斯卡就是最早发明机械计算机的那位数学家,他并不是赌徒,但是他有些赌徒朋友,那些人常常玩一种掷骰子游戏,游戏规则是由玩家连续掷4次骰子&#xff0c…

Java | Leetcode Java题解之第378题有序矩阵中第K小的元素

题目&#xff1a; 题解&#xff1a; class Solution {public int kthSmallest(int[][] matrix, int k) {int n matrix.length;int left matrix[0][0];int right matrix[n - 1][n - 1];while (left < right) {int mid left ((right - left) >> 1);if (check(matr…

Python酷库之旅-第三方库Pandas(113)

目录 一、用法精讲 496、pandas.DataFrame.kurtosis方法 496-1、语法 496-2、参数 496-3、功能 496-4、返回值 496-5、说明 496-6、用法 496-6-1、数据准备 496-6-2、代码示例 496-6-3、结果输出 497、pandas.DataFrame.max方法 497-1、语法 497-2、参数 497-3、…

如何从 SD 卡恢复已删除的文件:分步指南

在 SD 卡上查找已删除的文件可能是一项相当艰巨的任务&#xff0c;尤其是当您认为它们已经消失得无影无踪时。然而&#xff0c;希望还是有的&#xff01;现代技术提供了多种有效的方法来恢复这些文件&#xff0c;无论是照片、文档还是其他类型的数据。使用正确的工具和一点耐心…

【初出江湖】大白话解释集中式、分布式、微服务的区别?

目录标题 什么是集中式&#xff1f;什么是分布式&#xff1f;分布式系统的架构一般构成模块分布式的优点分布式的缺点什么是分布式集群&#xff1f; 什么是微服务&#xff1f;微服务和分布式系统有什么主要区别&#xff1f;微服务架构与分布式系统在开发过程中有何不同&#xf…

嵌入式:Arm v7-M指令集架构中的字节序(大小端)

相关阅读 嵌入式https://blog.csdn.net/weixin_45791458/category_12768532.html?spm1001.2014.3001.5482 本文来源于博主无意之中的一个发现&#xff0c;虽然之前就知道Cortex-M3默认为小端模式&#xff0c;但是偶然发现了一些出乎意料的情况。 首先来看看Arm v7-M指令集架构…

【MarkDown】表格的对齐方法

MarkDown中表格的对齐方法 说明格式化对齐举例 摘要&#xff1a; 1.本文介绍了MarkDown语法中&#xff0c;插入表格后&#xff0c;表格的对齐方法 2.在CSDN写博客时&#xff0c;要经常用的功能&#xff0c;务必掌握这个小技巧 说明 在Markdown中创建表格&#xff0c;基本结构由…

奇偶校验、crc循环冗余检验

数据链路层 链路 从一个结点到相邻结点的一段物理线路&#xff0c;而中间没有任何其他的交换点 数据链路 是指把实现通信协议的硬件和软件加到链路上 帧 在数据链路上传输的数据包&#xff0c;称之为帧 数据链路层是以帧为单位进行传输和处理数据的 数据链路层的三个重…

用Springboot(java程序)访问Salesforce RestAPI(通过JWT认证)

外部系统想访问Salesforce的数据,发Rest请求,必须需要Salesforce的AccessToken。那么为了得到这个AccessToken,Salesforce有几种方式可供选择。 一种就是用户名密码认证方式(之前的文章介绍过通过java代码访问Salesforce),一种就是JWT认证方式。当然还有其他方式,之后有…

利用Streamlit前端框架开发Stable Diffusion模型图像生成网页应用(下篇)

今天介绍亚马逊云科技推出的国际前沿人工智能模型平台Amazon Bedrock上的Stability Diffusion模型开发生成式AI图像生成应用&#xff01;本系列共有3篇&#xff0c;在上篇中我们学习了如何在亚马逊云科技控制台上体验该模型的每个特色功能&#xff0c;如文生图、图生图、图像修…

认知杂谈41

今天分享 有人说的一段争议性的话 I I 贫富根源在观念 I 你知道不&#xff1f;穷人穷啊&#xff0c;好多时候是因为他们自己还有家里好几代人呢&#xff0c;都陷在一种不对的想法里出不来&#xff0c;还觉得这样挺好&#xff0c;就一直这么过下去了。可富人的那些想法呢&am…

借老系统重构机会我写了个groovy规则引擎

公司老系统的重构计划早就有了&#xff0c;为了对Java硬编码的各种校验规则进行重构&#xff0c;特地参考了相关技术&#xff0c;最终选择了groovy进行了系统的学习&#xff0c;并编写了一个即插即用的轻量级规则引擎。 文章目录 项目背景技术选型groovy的性能groovy脚本执行线…

Scala之父Martin Odersky作序推荐的Scala速学版(第3版)出版

Scala 是一个很有吸引力的选择。 Scala 的语法简洁&#xff0c; 跟 Java 的“陈词滥调”比起来让人耳目一 新。它运行在 Java 虚拟机&#xff08;Java virtual machine &#xff0c;JVM&#xff09;上&#xff0c;提供对大量库和工具的访问。并 且&#xff0c;Scala 不仅仅瞄准…

设计模式之适配器模式:软件世界的桥梁建筑师

一、什么是适配器模式 适配器模式&#xff08;Adapter Pattern&#xff09;是一种结构型设计模式&#xff08;Structural Pattern&#xff09;&#xff0c;通过将类的接口转换为客户期望的另一个接口&#xff0c;适配器可以让不兼容的两个类一起协同工作。其核心思想是通过一个…

嵌入式全栈开发学习笔记---Linux系统编程(概述)

目录 入门级问题 为什么要学习Linux系统&#xff1f; 为什么Linux系统被嵌入式设备广泛应用&#xff1f; 系统调用 应用层是什么&#xff1f; 系统调用和库函数有什么区别&#xff1f; 为什么在应用层不能直接调用内核中的函数&#xff1f; 为什么有了系统调用就安全了…

Linux系统安装MySQL8.0

1.查看Linux发行版 2.安装前准备 2.1.检查是否安装 rpm -qa | grep mysql 2.2.如已安装mysql&#xff0c;则删除 rpm -e --nodeps 包名 2.3.再次检查安装包是否全部删除 rpm -qa | grep mysql 2.4.搜索mysql文件夹 find / -name mysql 2>/dev/null 2.5.若有mysql文件夹&a…

Golang | Leetcode Golang题解之第388题文件的最长绝对路径

题目&#xff1a; 题解&#xff1a; func lengthLongestPath(input string) (ans int) {n : len(input)level : make([]int, n1)for i : 0; i < n; {// 检测当前文件的深度depth : 1for ; i < n && input[i] \t; i {depth}// 统计当前文件名的长度length, isFi…

Cookie对象的缺陷与应对策略

Cookie对象的缺陷与应对策略 1. 安全性问题&#xff1a;Cookie是明文的2. 存储限制&#xff1a;浏览器对Cookie数量和大小有限制3. 性能影响&#xff1a;Cookie携带过多增加网络流量4. 数据类型限制&#xff1a;Cookie的value值只能是字符串 &#x1f496;The Begin&#x1f4…

82.给定一个已排序的链表的头 head , 删除原始链表中所有重复数字的节点,只留下不同的数字 。实现返回已排序的链表

删除排序链表中的重复元素 II 一、题目描述 82. 删除排序链表中的重复元素 II 给定一个已排序的链表的头 head , 删除原始链表中所有重复数字的节点,只留下不同的数字 。返回 已排序的链表 。 示例 1: 输入:head = [1,2,3,3,4,4,5] 输出:[1,2,5] 示例 2: 输入:hea…