一、平滑升级
1、查看nginx当前的版本
[ root@node01 ~]
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 ~]
--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 ~]
[ root@node01 ~]
[ root@node01 nginx-1.27.2]
[ root@node01 nginx-1.27.2]
切记: 不要执行make install
[ root@node01 nginx-1.27.2]
nginx version: nginx/1.27.2
4、将旧版本nginx备份,把新版本的nginx拷贝到原有的安装目录
[ root@node01 nginx-1.27.2]
[ root@node01 nginx-1.27.2]
[ root@node01 nginx-1.27.2]
[ root@node01 nginx-1.27.2]
[ root@node01 nginx-1.27.2]
nginx nginx.bak
5、启动新版本nginx
// 查看到两套nginx进程启动
[ root@node01 ~]
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 ~]
nginx.pid nginx.pid.oldbin
6、优雅的关闭旧版本的工作进程
[ root@node01 ~]
[ root@node01 ~]
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 ~]
[ root@node01 ~]
[ root@node01 ~]
nginx
[ root@node01 ~]
[ root@node01 ~]
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