随着 nginx 越来越流行,并且 nginx 的优势也越来越明显,nginx 的版本迭代也来时加速模式,1.9.0版本的nginx更新了许多新功能,例如 stream 四层代理功能,伴随着 nginx 的广泛应用,版本升级必然越来越快,线上业务不能停,此时 nginx 的升级就是运维的工作了
①获取老版本编译信息
②获取新版本安装包或添加功能包
③配置新版本或功能,配置是加上老版本的编译信息和新版本或功能(–add-module)
④编译,编译完后不能执行安装操作
⑤备份老版本程序,停掉老版本程序的进程,将新版本程序复制到老版本所在位置后,替换老版本
具体操作:
//下载nginx-1.22.0
[root@nginx ~]# wget https://nginx.org/download/nginx-1.22.0.tar.gz
//解压nginx-1.22.0
[root@nginx ~]# tar xf nginx-1.22.0.tar.gz
//进入nginx-1.22.0解压目录
[root@nginx ~]# cd nginx-1.22.0
[root@nginx nginx-1.22.0]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
//gitee获取nginx_module_echo模块
[root@nginx ~]# yum -y install git
[root@nginx ~]# git clone https://gitee.com/wujunze/nginx_module_echo.git
//编译(只能编译,不能安装!!!)
[root@nginx 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 --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --add-module=/root/nginx_module_echo
[root@nginx nginx-1.22.0]# make
[root@nginx nginx-1.22.0]# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
//进行平滑升级
[root@nginx ~]# pkill nignx;\cp /usr/local/nginx/sbin/nginx{,bak};\cp /root/nginx-1.22.0/objs/nginx /usr/local/nginx/sbin/nginx;systemctl start nginx
//查看nginx版本
[root@nginx ~]# nginx -v
nginx version: nginx/1.22.0
//查看新增nginx_module_echo模块
[root@nginx ~]# 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 --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --add-module=/root/nginx_module_echo/