Nginx平滑升级
Nginx平滑升级流程:
- 获取原版本的编译信息可使用
nginx -V
命令 - 获取新版本或功能包
- 配置新版本或功能,预编译时带上原版本的编译信息+新版本或新功能(–add-module)
- make进行编译,但不能执行make install(安装)操作
- 下面几步建议一条命令串完成,耗时短让网站访客无感知到更新
命令串为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