nginx平滑升级
平滑升级:升级版本、增加新功能
1.获取老版本的编译信息
2.老版本备份
3.编译新版本或者新功能(不能执行make install)
4.手动替换新版本并重启
5.验证新版本
添加echo模块
[root@RHEL8 ~]# ls //老版本为1.22.1
anaconda-ks.cfg php-8.2.9 php-8.2.9.tar.xz nginx-1.22.1 uploadnginx-1.22.1.tar.gz
nginx-1.24.0.tar.gz
//下载1.24.0作为升级版本
[root@RHEL8 ~]# wget http://nginx.org/download/nginx-1.24.0.tar.gz
进入github.com下载更新模块
[root@RHEL8 ~]# yum -y install git
//克隆模块
[root@RHEL8 ~]# git clone https://github.com/openresty/echo-nginx-module.git
Cloning into 'echo-nginx-module'...
remote: Enumerating objects: 3061, done.
remote: Counting objects: 100% (43/43), done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 3061 (delta 21), reused 30 (delta 12), pack-reused 3018
Receiving objects: 100% (3061/3061), 1.18 MiB | 1.75 MiB/s, done.
Resolving deltas: 100% (1645/1645), done.
[root@RHEL8 ~]# ls
anaconda-ks.cfg php-8.2.9 php-8.2.9.tar.xz
echo-nginx-module nginx-1.22.1
uploadnginx-1.22.1.tar.gz nginx-1.24.0.tar.gz
[root@RHEL8 ~]# tar xf nginx-1.24.0.tar.gz
[root@RHEL8 nginx-1.24.0]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
//查看老版本编译参数
[root@RHEL8 nginx-1.24.0]# 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
[root@RHEL8 nginx-1.24.0]# ./configure --help | grep add-module
--add-module=PATH enable external module //添加模块
[root@RHEL8 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
//备份老版本
[root@RHEL8 ~]# cp /usr/local/nginx/sbin/nginx /opt/nginx-20231020
[root@RHEL8 nginx-1.24.0]# make //编译
[root@RHEL8 nginx-1.24.0]# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
[root@RHEL8 nginx-1.24.0]# cd objs/
[root@RHEL8 objs]# ls
addon nginx(主程序在这里) ngx_auto_headers.h src
autoconf.err nginx.8 ngx_modules.c
Makefile ngx_auto_config.h ngx_modules.o
//查看主程序大小
[root@RHEL8 objs]# ll /usr/local/nginx/sbin/nginx
-rwxr-xr-x. 1 root root 6192528 Oct 16 22:45 /usr/local/nginx/sbin/nginx
[root@RHEL8 objs]# ll objs/nginx
-rwxr-xr-x. 1 root root 6740696 Oct 20 23:22 objs/nginx
[root@RHEL8 objs]# nginx -s stop; \cp nginx /usr/local/nginx/sbin/nginx;nginx
[root@RHEL8 objs]# nginx -v //平滑升级新版本成功
nginx version: nginx/1.24.0
[root@RHEL8 objs]# vim /usr/local/nginx/conf/nginx.conf
location / {
echo "hello world";
root html;
index index.php index.html index.htm;
}
[root@RHEL8 objs]# nginx -t //echo模块添加成功
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful