nginx平滑升级
nginx平滑升级就是指在服务不停的情况下,进行nginx版本更新,即使升级过程中用户还在访问网站,也不会受到服务更行带来的影响。
1、获取老版本的编译信息
# 使用nginx -V 查看老版本编译参数
[root@localhost ~]# nginx -V
nginx version: nginx/1.22.1
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 --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log
2、备份老版本
# 将安装路径下的nginx目录复制到其他位置,备份服务原件,方便回滚
[root@localhost ~]# cp /usr/local/nginx/sbin/nginx /opt/nginx.old
3、编译新版本并在其中添加新功能
# 在官网上找到nginx二进制的压缩包,将其上传至服务器(或者在服务器上使用wget进行下载并解压)
# 进入解压后的目录,编译nginx 并将要添加的新模块一起编译
[root@localhost nginx-1.24.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 --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --add-module=../echo-nginx-module-master
[root@localhost nginx-1.24.0]# make
# 编译完成后切记不能执行make install 如果执行会将原先安装的nginx配置文件进行覆盖,需要手动将nginx主程序进行替换
4、手动替换新版本并重启服务
# 将老版本服务停止,将编译好的新版本复制到老版本安装位置,将服务重启这一系列操作集成为一条命令执行
[root@localhost nginx-1.24.0]# /usr/local/nginx/sbin/nginx -s stop;\cp -f objs/nginx /usr/local/nginx/sbin/nginx;nginx
5、验证编译
# 老版本号
[root@localhost ~]# nginx -v
nginx version: nginx/1.22.1
#:更新后版本号
[root@localhost nginx-1.24.0]# nginx -v
nginx version: nginx/1.24.0