- 当前版本
[root@nginx ~]# nginx -V
nginx version: nginx/1.15.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/opt/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream
- 准备新版本
地址:http://nginx.org/download/
[root@nginx ~]# wget http://nginx.org/download/nginx-1.19.0.tar.gz
- 备份旧版本信息
[root@nginx ~]# mv /opt/data/nginx/sbin/nginx{,.bak}
[root@nginx ~]# cp -rf /etc/nginx/ /etc/nginx.back
- 打开一个测试机器,不断测试nginx是否正常运行
[root@nginx1 ~]# while true; do curl 192.168.10.11; sleep 5; done
This is a test from 192.168.10.11
This is a test from 192.168.10.11
This is a test from 192.168.10.11
- 安装新版本nginx
[root@nginx nginx-1.19.0]# nginx -V nginx version: nginx/1.15.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/opt/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream
[root@nginx nginx-1.19.0]# ./configure --prefix=/opt/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream
[root@nginx nginx-1.19.0]# echo $?
0
[root@nginx nginx-1.19.0]# make
[root@nginx nginx-1.19.0]# echo $?
0
[root@nginx nginx-1.19.0]# make install
[root@nginx nginx-1.19.0]# echo $?
0
- 向主进程发送USR2信号
启动新版本的主进程,和旧版本一起处理请求,旧版本的请求逐渐减少,直到完全没有请求,退出
[root@nginx nginx-1.19.0]# ps -ef | grep nginx
root 8961 1 0 16:40 ? 00:00:00 nginx: master process /opt/data/nginx/sbin/nginx -c /opt/data/nginx/conf/nginx.conf
nginx 8962 8961 0 16:40 ? 00:00:00 nginx: worker process
# 向主进程发送USR2信号
[root@nginx nginx-1.19.0]# kill -USR2 8961
[root@nginx nginx-1.19.0]# ps -ef | grep nginx
root 8961 1 0 16:40 ? 00:00:00 nginx: master process /opt/data/nginx/sbin/nginx -c /opt/data/nginx/conf/nginx.conf
nginx 8962 8961 0 16:40 ? 00:00:00 nginx: worker process
root 12285 8961 0 16:50 ? 00:00:00 nginx: master process /opt/data/nginx/sbin/nginx -c /opt/data/nginx/conf/nginx.conf
nginx 12286 12285 0 16:50 ? 00:00:00 nginx: worker process
root 12298 7923 0 16:50 pts/0 00:00:00 grep --color=auto nginx
# 发送WINCH信号
[root@nginx nginx-1.19.0]# kill -WINCH 8961
[root@nginx nginx-1.19.0]# ps -ef | grep nginx
root 8961 1 0 16:40 ? 00:00:00 nginx: master process /opt/data/nginx/sbin/nginx -c /opt/data/nginx/conf/nginx.conf
root 12285 8961 0 16:50 ? 00:00:00 nginx: master process /opt/data/nginx/sbin/nginx -c /opt/data/nginx/conf/nginx.conf
nginx 12286 12285 0 16:50 ? 00:00:00 nginx: worker process
root 12438 7923 0 16:52 pts/0 00:00:00 grep --color=auto nginx
# 关闭旧进程
[root@nginx nginx-1.19.0]# kill 8961
[root@nginx nginx-1.19.0]# ps -ef | grep nginx
root 12285 1 0 16:50 ? 00:00:00 nginx: master process /opt/data/nginx/sbin/nginx -c /opt/data/nginx/conf/nginx.conf
nginx 12286 12285 0 16:50 ? 00:00:00 nginx: worker process
root 12450 7923 0 16:53 pts/0 00:00:00 grep --color=auto nginx
- 查看监控端
并没有断开,nginx平滑升级完成 - 再次查看nginx版本,确保没出错误
[root@nginx ~]# nginx -V
nginx version: nginx/1.19.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/opt/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream
------------------------------------------------------------------------------------------------------- 返回目录