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

nginx快速实现平滑版本升级

1、解压并编译新版的nginx

# 目前版本为1.18,解压一个1.21版本的nginx包
wget https://nginx.org/download/nginx-1.21.0.tar.gz
tar -zxf nginx-1.21.0.tar.gz
cd nginx-1.21.0/
[root@ubt-server nginx-1.21.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src# 安装编译
[root@ubt-server sbin]# pwd
/usr/local/nginx/sbin[root@ubt-server sbin]# ./nginx -V           # 先找到之前使用的是什么参数去安装的
...
...
configure arguments: --prefix=/usr/local/nginx# 找到参数后返回新版nginx的目录
[root@ubt-server nginx-1.21.0]# ./configure --prefix=/usr/local/nginx          # 使用和上面一样的参数去编译
[root@ubt-server nginx-1.21.0]# make
[root@ubt-server nginx-1.21.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src

2、备份老的二进制文件,将新的二进制文件替换上去

[root@ubt-server nginx-1.21.0]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old.running
[root@ubt-server nginx-1.21.0]# cp objs/nginx /usr/local/nginx/sbin/nginx# 发送USER2的型号,启用新的主进程来接收新的连接
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`# 让老版nginx处理完进程后优雅退出
kill -WINCH `cat /usr/local/nginx/logs/nginx.pid.oldbin`

3、确认服务是否成功替换

# 确认新版nginx已经成功接替,访问您的nginx服务是否可以正常运行或显示`
[root@ubt-server nginx-1.21.0]# ps aux | grep nginx
root       20942  0.0  0.0   4616   356 ?        Ss   23:44   0:00 nginx: master process /usr/local/nginx/sbin/nginx
root       23618  0.0  0.1   4624  2880 ?        S    23:57   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody     23619  0.0  0.1   5372  2856 ?        S    23:57   0:00 nginx: worker process
root       23622  0.0  0.1   6480  2324 pts/0    S+   23:57   0:00 grep --color=auto nginx# 若是您的服务正常运行,并可以正常显示就能将老进程关闭了
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
[root@ubt-server sbin]# ps aux | grep nginx
root       23618  0.0  0.1   4624  2880 ?        S    23:57   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody     23619  0.0  0.1   5372  2856 ?        S    23:57   0:00 nginx: worker process
root       23634  0.0  0.1   6480  2320 pts/0    S+   23:58   0:00 grep --color=auto nginx# 再次确认版本号,去web界面上确认一次您的服务是否可以正常显示
[root@ubt-server nginx-1.21.0]# cd /usr/local/nginx/sbin/
[root@ubt-server sbin]# ./nginx -v        # 可见nginx版本已被替换
nginx version: nginx/1.21.0   
http://www.hskmm.com/?act=detail&tid=36180

相关文章:

  • Luogu P11159 【MX-X6-T5】 再生 题解 [ 蓝 ] [ 前缀和 ] [ 组合计数 ]
  • 王浩宇 102500416
  • 程序员修炼之路:从小工到专家 读书笔记 2
  • 程序员修炼之路:从小工到专家 读书笔记 3
  • 中级问题
  • 2025.10.21
  • 解答在同步以太坊事件数据时,如何保证后端服务在 API/RPC 不稳定情况下的可用性
  • 程序员修炼之道:从小工到专家 读书笔记 1
  • 好想好想你
  • 10.21日学习笔记
  • 数据库概述
  • 第1天(简单题 基础语法 数据类型、条件判断 、循环 循环嵌套、位运算, ASCII 码)
  • 24信计2班 17曾向嵩 pytorch读书报告
  • 关于第一次作业的时长统计
  • Go 语言问题解释
  • Keil_v5的用法
  • day 8
  • OI 笑传 #21
  • Day1文本格式化标签
  • 【C语言学习记录】你好世界
  • 1021
  • 24信计2班 17曾向嵩 pytorch66页实验题
  • 解答这些常见的智能合约安全问题,并提供相应的防护措施
  • Day1排版标签,标题与段落
  • 读AI赋能05消费者盈余
  • 解答这些 Solidity 开发中的重要问题
  • grpc 哼哈二将,你值得拥有
  • 解释这些 Solidity 智能合约的核心概念
  • C++编程练习
  • 数据结构练习