nginx平滑升级

官网下载最新的安装版

下载地址
https://nginx.org/en/download.html
image

将下载的包上传到服务器后进行更新操作

解压

tar xf nginx-1.27.0.tar.gz -C /usr/src

查看当前nginx配置参数

nginx -v

nginx version: nginx/1.24.0
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_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-stream --with-stream_realip_module --with-stream_ssl_module

在新版本中进行编译

cd /usr/src/nginx-1.27.0/ && ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-stream --with-stream_realip_module --with-stream_ssl_module

make

无需make install

对原来的nginx进行备份

where nginx
cd /usr/local/nginx/sbin
mv nginx nginx-1.24.0old
cd /usr/src/nginx-1.27.0/objs
cp ./nginx /usr/local/nginx/sbin/
nginx -V

nginx version: nginx/1.27.0
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_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-stream --with-stream_realip_module --with-stream_ssl_module

进行平滑升级替换

ps aux|grep nginx
可看到当前有一个master进程
发送信号给老版本进程

kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`

向旧版本的 master 进程发送 WINCH 信号,并逐步关闭自己的工作进程(master 进程不退出),这时所有的用户请求都会由新版本的 master 进程处理。

kill -WINCH oldpid

然后平滑关闭老进程

kill -QUIT `more /usr/local/nginx/logs/nginx.pid.oldbin`

image

posted @ 2024-07-25 11:34  开心burukku  阅读(45)  评论(0)    收藏  举报