Linux-nginx不停机平滑升级

本文详细描述了如何在保持服务稳定性的前提下,从旧版本的Nginx升级到新版本,包括查看现有版本信息、备份、参照旧版本编译参数、新版本安装、发送信号进行热部署和优雅地结束旧进程的操作过程。
摘要由CSDN通过智能技术生成

1. 查看现有nginx 版本及参数

查看版本和原编译参数

#旧版本的nginx安装目录/usr/local/nginx
$cd /usr/local/nginx
$./sbin/nginx -V
nginx version: nginx/1.22.1
built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r4) 
built with OpenSSL 3.0.7 1 Nov 2022 (running with OpenSSL 3.0.8 7 Feb 2023)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-Os -fomit-frame-pointer -g' --with-ld-opt=-Wl,--as-needed,-O1,--sort-common

2. 备份现有的nginx

$cp -a ./nginx ./nginx.bak

3. 参考之前旧版本的编译参数,编译安装新的nginx

#如果新版本的nginx源代码文件位置/opt/nginx-1.24.0.tar.gz
$cd /opt
$tar -zxvf nginx-1.24.0.tar.gz
$cd nginx-1.24.0
$./configure --prefix=/usr/local/nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-Os -fomit-frame-pointer -g' --with-ld-opt=-Wl,--as-needed,-O1,--sort-common
$make && make install

4. 生成新的master进程

给正在运行nginx的master进程发送一个信号,告诉master要热部署,做一次版本升级,这个信号是USER2,USER2信号用来传递热部署的信号

$kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`

5. 优雅退出老worker进程
向老的master进程发信号,4076是老nginx的master进程的进程号,告诉它关闭其worker进程

kill -WINCH 4076

6. 升级完成,退出老的worker进程
经过一段时间测试,服务器没问题,退出老的master进程

kill -QUIT 4076

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值