所谓的平滑升级就是在不停止业务的前提下,实现对Nginx软件版本的
升级
现有的nginx版本
# sbin/nginx -v
nginx version: nginx/1.12.2
平滑升级
停止正在运行的nginx,在以原生的nginx方式启动
# systemctl stop nginx
# cd /usr/local/nginx
# sbin/nginx -c /usr/local/nginx/conf/nginx.conf
安装新版本nginx
# tar -zxvf nginx-1.20.2.tar.gz
# cd nginx-1.20.2
# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --withhttp_stub_status_module --with-http_realip_module
# make && make install
查看正在提供服务的nginx版本
# curl -I http://localhost
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Sat, 20 Nov 2021 07:56:39 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sat, 20 Nov 2021 04:05:27 GMT
Connection: keep-alive
ETag: "61987407-264"
Accept-Ranges: bytes
同时启动两个nginx
查看正在运行的nginx版本
# ps -ef |grep nginx
root 13066 1 0 15:55 ? 00:00:00 nginx: master process sbin/nginx.old
www 13100 13066 0 15:59 ? 00:00:00 nginx: worker process
root 13102 5965 0 15:59 pts/1 00:00:00 grep --color=auto nginx
平滑的升级nginx二进制文件 拉起一个新的主进程 旧主进程
不停止
# kill -USR2 13066
优雅的关闭worker进程
kill -EINCH 13066
优雅退出,执行完当前的请求后退出
kill -QUIT 13066
再次查看正在提供服务的nginx版本
# curl -I http://localhost
HTTP/1.1 200 OK
Server: nginx/1.20.2
Date: Sat, 20 Nov 2021 08:01:44 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sat, 20 Nov 2021 04:05:27 GMT
Connection: keep-alive
ETag: "61987407-264"
Accept-Ranges: bytes
版权声明:本文为weixin_45939085原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。