Skip to content

Latest commit

 

History

History
80 lines (58 loc) · 1.78 KB

5-1.md

File metadata and controls

80 lines (58 loc) · 1.78 KB

1. 当前环境

# system
cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
 
# nginx
./nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
configure arguments: --prefix=/home/tomcat/app/nginx

2. 下载

# 下载新版的 nginx,版本为 1.23.3
wget -P /alidata/soft http://nginx.org/download/nginx-1.23.3.tar.gz

3. 升级

# 解压到指定文件夹下
tar -zxf nginx-1.23.3.tar.gz -C /alidata/server/
 
# 到解压目录下
cd /alidata/server/nginx-1.23.3

# 预编译,老版用到了什么模块,这里也要加上的,我前一版预编译也是这样进行的 
./configure --prefix=/alidata/server/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module

微信截图_20230317163741.png

出现这样的提示信息后就可以进行编译了

# 编译
make

注意不要 make install ,因为这会覆盖安装新版本的 nginx。 做完上面的步骤就可以开始升级了 首先我们要将老版的 nginx 备份

cd /alidata/server/nginx/sbin

# 打开 nginx 服务
./nginx

# 备份
mv nginx nginx_bak

然后将新版的执行文件复制到这个文件夹下

cd /alidata/server/nginx-1.23.3/objs
cp nginx /alidata/server/nginx/sbin

现在就可以进行平滑升级操作了

# 查看当前 nginx 进程号
ps -ef | grep nginx
 
# 平滑开启新的 nginx 服务,此时新的 master 进程已经正常开启,但老的 work 进程也存在
kill -USR2 主进程号

# 将老的 work 进程平滑停止
kill -WINCH 老版worker 进程号

# 关闭老的 nginx master进程
kill -QUIT 老版主进程号

至此,平滑升级结束