当前位置: 首页 > news >正文

【NGINX】-11 nginx 平滑升级

文章目录

  • 1、nginx平滑升级
    • 1.1 平滑升级的应用场景和意义
  • 2、平滑升级的操作
    • 2.1 安装 nginx1.20.2
    • 2.2 平滑升级操作
    • 2.3 平滑回滚
  • 3、总结


1、nginx平滑升级

1.1 平滑升级的应用场景和意义

Nginx平滑升级具有重要意义与广泛的应用场景。在意义层面,它可在不中断服务的前提下完成版本更新,避免因服务暂停导致的用户访问中断、业务损失及影响用户体验,同时能让新版本的功能、性能优化和安全补丁及时生效,增强服务器稳定性与安全性,还可减少运维操作复杂度和对业务的干扰,提升系统可用性。在应用场景方面,当Nginx新版本引入关键功能(如更高效的负载均衡算法、新协议支持)时,平滑升级能让业务快速受益;面对已知安全漏洞,可通过平滑升级及时修复,降低被攻击风险;当业务流量增长,需利用新版本性能优化(如连接处理优化、内存管理改进)提升服务器处理能力时,平滑升级可在不中断服务的情况下实现;此外,在需要对Nginx配置进行重大调整或模块升级时,平滑升级能确保调整过程中服务持续可用,避免因配置变更导致的服务中断问题。

2、平滑升级的操作

2.1 安装 nginx1.20.2

   #拖入相关的安装包24  yum -y install gcc pcre-devel openssl-devel zlib-devel openssl openssl-devel#安装依赖环境25  useradd -M -s /sbin/nologin nginx#创建nginx用户便于管理26  ls27  tar -xf nginx-1.20.2.tar.gz 28  ls29  cd nginx-1.20.2/30  l31  ls32  ./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module#指定编译路径,以及可能用得到的模块33  vim /etc/profile34  source /etc/profile#声明nginx的环境变量35  nginx -v36  vim /etc/profile37  ls38  make -j2 && make install#编译安装39  nginx -v
[root@localhost nginx-1.20.2]# 

查看安装的版本为1.20.2

[root@localhost nginx-1.20.2]# nginx -v
nginx version: nginx/1.20.2
[root@localhost nginx-1.20.2]# nginx -V
nginx version: nginx/1.20.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
[root@localhost nginx-1.20.2]# 

2.2 平滑升级操作

[root@localhost ~]# cd /opt/
[root@localhost opt]# ls
rh
[root@localhost opt]# rz -E
rz waiting to receive.
[root@localhost opt]# ls
nginx-1.28.0.tar.gz  rh
#拖入安装包
[root@localhost opt]# tar -xf nginx-1.28.0.tar.gz 
[root@localhost opt]# ls
nginx-1.28.0  nginx-1.28.0.tar.gz  rh
[root@localhost opt]# cd nginx-1.28.0/
[root@localhost nginx-1.28.0]# ls
auto        CODE_OF_CONDUCT.md  contrib          LICENSE    SECURITY.md
CHANGES     conf                CONTRIBUTING.md  man        src
CHANGES.ru  configure           html             README.md
[root@localhost nginx-1.28.0]# ./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
#需要和上面低版本的模块一样

编译(注意只能编译)make -j2

[root@localhost nginx-1.28.0]# ls
auto        CODE_OF_CONDUCT.md  contrib          LICENSE   objs         src
CHANGES     conf                CONTRIBUTING.md  Makefile  README.md
CHANGES.ru  configure           html             man       SECURITY.md
[root@localhost nginx-1.28.0]# make -j2

复制nginx的执行文件到相应的位置

[root@localhost nginx-1.28.0]# ls
auto        CODE_OF_CONDUCT.md  contrib          LICENSE   objs         src
CHANGES     conf                CONTRIBUTING.md  Makefile  README.md
CHANGES.ru  configure           html             man       SECURITY.md[root@localhost nginx-1.28.0]# cd objs/
#进入obj目录
[root@localhost objs]# ls
autoconf.err  nginx    ngx_auto_config.h   ngx_modules.c  src
Makefile      nginx.8  ngx_auto_headers.h  ngx_modules.o
#找到nginx的执行文件
[root@localhost objs]# cd /apps/nginx/sbin/
[root@localhost sbin]# ls
nginx
[root@localhost sbin]# mv nginx nginx.old
#备份原来的执行文件为nginx.old
[root@localhost sbin]# cd -
/opt/nginx-1.28.0/objs
[root@localhost objs]# ls
autoconf.err  nginx    ngx_auto_config.h   ngx_modules.c  src
Makefile      nginx.8  ngx_auto_headers.h  ngx_modules.o
[root@localhost objs]# mv nginx /apps/nginx/sbin/
#把高版本的nginx可执行文件移动到低版本的工作目录
[root@localhost objs]# ls /apps/nginx/sbin/
nginx  nginx.old
[root@localhost objs]# 

make upgrade操作

[root@localhost objs]# cd /opt/nginx-1.28.0/
[root@localhost nginx-1.28.0]# ls
auto        CODE_OF_CONDUCT.md  contrib          LICENSE   objs         src
CHANGES     conf                CONTRIBUTING.md  Makefile  README.md
CHANGES.ru  configure           html             man       SECURITY.md
[root@localhost nginx-1.28.0]# 
#需要切换到nginx的文件夹目录[root@localhost nginx-1.28.0]# make upgrade
/apps/nginx/sbin/nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /apps/nginx/logs/nginx.pid`
sleep 1
test -f /apps/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /apps/nginx/logs/nginx.pid.oldbin`
[root@localhost nginx-1.28.0]# nginx -v
nginx version: nginx/1.28.0
[root@localhost nginx-1.28.0]# 
#此时我们就完成了升级

2.3 平滑回滚

在上面的基础上,回滚操作就显得很容易了

[root@localhost nginx-1.28.0]# cd /apps/nginx/sbin/
[root@localhost sbin]# ls
nginx  nginx.old
#进入目录
[root@localhost sbin]# mv nginx nginx.1.28
[root@localhost sbin]# ls
nginx.1.28  nginx.old
[root@localhost sbin]# mv nginx.old nginx.
[root@localhost sbin]# mv nginx. nginx
[root@localhost sbin]# ls
nginx  nginx.1.28
#更改nginx可执行文件的名称
[root@localhost sbin]# ls
nginx  nginx.1.28
[root@localhost sbin]# cd /opt/nginx-1.28.0/
#进入nginx文件目录
[root@localhost nginx-1.28.0]# make upgrade
/apps/nginx/sbin/nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /apps/nginx/logs/nginx.pid`
sleep 1
test -f /apps/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /apps/nginx/logs/nginx.pid.oldbin`
#make upgrade成功
[root@localhost nginx-1.28.0]# nginx -v
nginx version: nginx/1.20.2
#查看版本是否回滚成功
[root@localhost nginx-1.28.0]# 

3、总结

通过nginx的执行文件可以决定nginx运行的版本,更换nginx的执行文件可以实现nginx版本的升级和回滚。

相关文章:

  • 如何使用patch-package给npm包打补丁
  • halcon 连接相机
  • 扫描电镜:打开微观世界的“超维相机“
  • 晶圆隐裂检测提高半导体行业效率
  • LNCS-2009《Adaptive Sampling for $k$-Means Clustering》
  • 探索Dify:开启大语言模型应用开发新时代
  • 2025电工杯数学建模A题思路数模AI提示词工程
  • 从细胞工厂到智能制造:Extracellular 用时序数据库 TDengine 打通数据生命线
  • LIEDNet: A Lightweight Network for Low-light Enhancement and Deblurring论文阅读
  • uni-app/vue2:微信小程序实现文件流的下载及预览
  • 【菜狗work前端】小程序加if判断时不及时刷新 vs Web
  • 微气象在线监测装置:精准感知环境变化的科技之眼
  • 微信小程序用<web-view 嵌入h5网页,改了h5网页后,可能是缓存的原因,小程序上看还是原来的,怎么处理
  • AI浪潮下,媒体内容运营的五重变奏
  • IP 地址反向解析(IP反查域名)的原理详解
  • 力扣HOT100之图论:200. 岛屿数量
  • 解决MybatisPlus使用Druid1.2.11连接池查询PG数据库报Merge sql error的一种办法
  • 九州未来十三载:开源赋能 智启未来
  • [C语言实战]如何封装 JNI 实现 Java 与 C 的高效交互?原理详解 + 代码实战(附完整测试步骤)
  • Tailwind css实战,基于Kooboo构建AI对话框页面(一)
  • 有哪些好的网页设计/优化设计全部答案
  • 商务网站开发的基本流程/互联网品牌宣传推广服务公司
  • 招商网站建设解决方案/阜阳seo
  • 深圳网站制作建设/关键字搜索引擎
  • 电商思维做招聘网站/网店代运营的套路
  • 网站短信验证怎么做/网站seo外包靠谱吗