nginx的平滑升级

  1. 当前版本
[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
  1. 准备新版本
    地址:http://nginx.org/download/
[root@nginx ~]# wget http://nginx.org/download/nginx-1.19.0.tar.gz
  1. 备份旧版本信息
[root@nginx ~]# mv /opt/data/nginx/sbin/nginx{,.bak}
[root@nginx ~]# cp -rf /etc/nginx/ /etc/nginx.back
  1. 打开一个测试机器,不断测试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
  1. 安装新版本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
  1. 向主进程发送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
  1. 查看监控端
    在这里插入图片描述
    并没有断开,nginx平滑升级完成
  2. 再次查看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

------------------------------------------------------------------------------------------------------- 返回目录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值