Nginx平滑升级

本文介绍了如何平滑升级Nginx服务器,包括获取编译信息、预编译新版本、避免停服操作以及升级总结,确保网站访客在升级过程中几乎无感知。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Nginx平滑升级

Nginx平滑升级流程

  1. 获取原版本的编译信息可使用nginx -V命令
  2. 获取新版本或功能包
  3. 配置新版本或功能,预编译时带上原版本的编译信息+新版本或新功能(–add-module)
  4. make进行编译,但不能执行make install(安装)操作
  5. 下面几步建议一条命令串完成,耗时短让网站访客无感知到更新

命令串为cp /usr/local/nginx/sbin/nginx{,-bak};pkill nginx;\cp objs/nginx /usr/local/nginx/sbin/;systemctl start nginx

上条命令的解释:先备份(建议cp)原版本的主程序(通常在/usr/local/nginx/sbin/的nginx),然后停止原程序的运行

把新版本程序移动到原程序的存放位置,然后启动

平滑升级总结:在Linux中的源码部署软件升级的流程几乎都是如此,所谓触类旁通。

升级流程演示

[root@localhost ~]# systemctl status nginx.service
● nginx.service - nginx server daemon
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-10-12 14:37:41 CST; 2min 38s ago

[root@localhost ~]# nginx -V
nginx version: nginx/1.20.2
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.22.0.tar.gz
[root@localhost src]# dnf -y install git
[root@localhost src]# git clone https://gitee.com/wujunze/nginx_module_echo.git
[root@localhost src]# ls
nginx-1.22.0.tar.gz  nginx_module_echo

[root@localhost src]# tar -xf nginx-1.22.0.tar.gz
[root@localhost src]# cd nginx-1.22.0/
[root@localhost nginx-1.22.0]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--add-module=../nginx_module_echo
#进行编译,但不要安装
[root@localhost nginx-1.22.0]# make
[root@localhost nginx-1.22.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
[root@localhost nginx-1.22.0]# ls objs/
addon         Makefile  nginx.8            ngx_auto_headers.h  ngx_modules.o
autoconf.err  nginx     ngx_auto_config.h  ngx_modules.c       src
[root@localhost nginx-1.22.0]# objs/nginx -V
nginx version: nginx/1.22.0
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --add-module=../nginx_module_echo

[root@localhost nginx-1.22.0]# cp /usr/local/nginx/sbin/nginx{,-bak};pkill nginx;\cp objs/nginx /usr/local/nginx/sbin/;systemctl start nginx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值