nginx平滑升级

一、平滑升级

1、查看nginx当前的版本

[root@node01 ~]# /usr/local/nginx/sbin/nginx  -V 
nginx version: nginx/1.26.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module

2、下载新版本的安装包

[root@node01 ~]# wget https://nginx.org/download/nginx-1.27.2.tar.gz 
--2024-10-29 11:35:29--  https://nginx.org/download/nginx-1.27.2.tar.gz
Resolving nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:5c0:2600::6, ...
Connecting to nginx.org (nginx.org)|52.58.199.22|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1258098 (1.2M) [application/octet-stream]
Saving to: ‘nginx-1.27.2.tar.gz’

100%[==============================================================>] 1,258,098   1.45MB/s   in 0.8s   

2024-10-29 11:35:30 (1.45 MB/s) - ‘nginx-1.27.2.tar.gz’ saved [1258098/1258098]

3、使用相同的参数编译新版本nginx

[root@node01 ~]# tar xf nginx-1.27.2.tar.gz 
[root@node01 ~]# cd nginx-1.27.2/
[root@node01 nginx-1.27.2]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module
[root@node01 nginx-1.27.2]# make

切记: 不要执行make install 
[root@node01 nginx-1.27.2]# ./objs/nginx -v
nginx version: nginx/1.27.2

4、将旧版本nginx备份,把新版本的nginx拷贝到原有的安装目录

[root@node01 nginx-1.27.2]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
[root@node01 nginx-1.27.2]# 
[root@node01 nginx-1.27.2]# cp objs/nginx /usr/local/nginx/sbin/
[root@node01 nginx-1.27.2]# 
[root@node01 nginx-1.27.2]# ls /usr/local/nginx/sbin/
nginx  nginx.bak

5、启动新版本nginx

// 查看到两套nginx进程启动
[root@node01 ~]# ps -elf | grep nginx 
1 S root       1036      1  0  80   0 - 12003 sigsus 09:04 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
5 S www        3066   1036  0  80   0 - 12296 ep_pol 10:45 ?        00:00:00 nginx: worker process
5 S www        3067   1036  0  80   0 - 12296 ep_pol 10:45 ?        00:00:00 nginx: worker process
5 S www        3068   1036  0  80   0 - 12296 ep_pol 10:45 ?        00:00:00 nginx: worker process
5 S www        3069   1036  0  80   0 - 12296 ep_pol 10:45 ?        00:00:00 nginx: worker process
5 S www        3070   1036  0  80   0 - 12296 ep_pol 10:45 ?        00:00:00 nginx: worker process
5 S www        3071   1036  0  80   0 - 12362 ep_pol 10:45 ?        00:00:00 nginx: worker process
5 S www        3072   1036  0  80   0 - 12296 ep_pol 10:45 ?        00:00:00 nginx: worker process
5 S www        3073   1036  0  80   0 - 12362 ep_pol 10:45 ?        00:00:00 nginx: worker process
0 S root       6518   1036  0  80   0 - 11793 sigsus 11:43 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
5 S www        6519   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6520   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6521   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6522   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6523   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6524   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6525   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6526   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
有两个nginx的pid文件  
[root@node01 ~]# ls /usr/local/nginx/logs/
nginx.pid   nginx.pid.oldbin

6、优雅的关闭旧版本的工作进程

[root@node01 ~]# kill -WINCH $(cat /usr/local/nginx/logs/nginx.pid.oldbin)

[root@node01 ~]# ps -elf | grep nginx 
1 S root       1036      1  0  80   0 - 12003 sigsus 09:04 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
0 S root       6518   1036  0  80   0 - 11793 sigsus 11:43 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
5 S www        6519   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6520   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6521   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6522   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6523   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6524   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6525   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6526   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process

7、手动清理旧版本的主进程,旧版本的命令

[root@node01 ~]# kill $(cat /usr/local/nginx/logs/nginx.pid.oldbin)

[root@node01 ~]# rm -rf /usr/local/nginx/sbin/nginx.bak 

[root@node01 ~]# ls /usr/local/nginx/sbin/
nginx
[root@node01 ~]# 
[root@node01 ~]# ps -elf | grep nginx
0 S root       6518      1  0  80   0 - 11793 sigsus 11:43 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
5 S www        6519   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6520   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6521   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6522   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6523   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6524   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6525   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
5 S www        6526   6518  0  80   0 - 12231 ep_pol 11:43 ?        00:00:00 nginx: worker process
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值