下载升级的版本软件包
# 官网下载地址,选择自己想要的版本
https://nginx.org/en/download.html
解压到新文件夹
cd /server
tar -zxvf nginx-1.26.2.tar.gz
编译
# 查询旧版本参数
[root@hcss-ecs-df46 nginx-1.26.2]# /usr/local/nginx/sbin/nginx -V
# 编译
[root@hcss-ecs-df46 nginx-1.26.2]# ./configure 添加上原来的参数(如果没有直接执行)
[root@hcss-ecs-df46 nginx-1.26.2]# make
备份和迁移
#旧版本备份
[root@hcss-ecs-df46 nginx-1.26.2]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_old#新版本迁移
[root@hcss-ecs-df46 nginx-1.26.2]# cp /server/nginx-1.26.2/objs/nginx /usr/local/nginx/sbin/#测试新版本是否正常
[root@hcss-ecs-df46 nginx-1.26.2]# /usr/local/nginx/sbin/nginx -t#出现以下代表正常
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
给nginx发送平滑迁移信号
[root@hcss-ecs-df46 nginx-1.26.2]# kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
查看nginx pid,会出现一个nginx.pid.oldbin
[root@hcss-ecs-df46 nginx-1.26.2]# ll /usr/local/nginx/logs/nginx.pid*
-rw-r--r-- 1 root root 6 Dec 25 11:55 /usr/local/nginx/logs/nginx.pid
-rw-r--r-- 1 root root 6 Mar 29 2024 /usr/local/nginx/logs/nginx.pid.oldbin
关闭旧的Nginx进程
[root@hcss-ecs-df46 nginx-1.26.2]# kill -WINCH `cat /usr/local/nginx/logs/nginx.pid.oldbin`
此时不重载配置启动旧的工作进程
[root@hcss-ecs-df46 nginx-1.26.2]# kill -HUP `cat /usr/local/nginx/logs/nginx.pid.oldbin`
结束工作进程,完成此次升级
[root@hcss-ecs-df46 nginx-1.26.2]# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
验证Nginx是否升级成功
[root@hcss-ecs-df46 nginx-1.26.2]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.26.2
built by gcc 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)
configure arguments:
[root@hcss-ecs-df46 nginx-1.26.2]# ps aux | grep nginx
root 22681 0.0 0.0 20588 1684 ? S 11:55 0:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf
nobody 22682 0.0 0.0 21000 1380 ? S 11:55 0:00 nginx: worker process
nobody 22775 0.0 0.0 21180 1552 ? S 11:56 0:00 nginx: worker process
root 22838 0.0 0.0 112816 984 pts/1 S+ 11:57 0:00 grep --color=auto nginx
参考文章
https://blog.csdn.net/weixin_60250117/article/details/138199492