nginx的平滑升级

nginx的平滑升级

方案(一)
1. 查看原编译参数
[root@anonymous ~]# nginx -V
[root@anonymous ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.16.1
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 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module

2. 解压缩,进入软件安装目录,添加echo-nginx-module模块
预编译/编译/安装:
[root@anonymous ~]# tar xf nginx-1.20.1.tar.gz
[root@anonymous ~]# cd nginx-1.20.1
[root@anonymous nginx-1.20.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --add-module=/usr/src/echo-nginx-module
root@anonymous nginx-1.20.1]# make && make install
3. 直接升级:make upgrade

方案(二)
1. 查看原编译参数
[root@anonymous ~]# nginx -V
[root@anonymous ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.16.1
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 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module

2. 解压缩,进入软件安装目录,添加echo-nginx-module模块
预编译/编译/安装:
[root@anonymous ~]# tar xf nginx-1.20.1.tar.gz
[root@anonymous ~]# cd nginx-1.20.1
[root@anonymous nginx-1.20.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --add-module=/usr/src/echo-nginx-module
root@anonymous nginx-1.20.1]# make && make install
3. 生成新的master进程:
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
[root@node3 nginx-1.16.0]# ps -ef |grep "[n]ginx"
root   8054   1 0 21:07 ?    00:00:00 nginx: master process
/usr/local/nginx/sbin/nginx
nginx   8097 8054 0 21:09 ?    00:00:00 nginx: worker process
nginx   8098 8054 0 21:09 ?    00:00:00 nginx: worker process
root   8134 8054 0 21:13 ?    00:00:00 nginx: master process
/usr/local/nginx/sbin/nginx
nginx   8135 8134 0 21:13 ?    00:00:00 nginx: worker process
nginx   8136 8134 0 21:13 ?    00:00:00 nginx: worker process
4. 优雅退出老worker进程:
# 向老的master进程发信号:
[root@anonymous nginx-1.20.1]# kill -WINCH 8054
[root@anonymous nginx-1.20.1]# ps -ef |grep "[n]ginx"
root   8054   1 0 21:07 ?    00:00:00 nginx: master process
/usr/local/nginx/sbin/nginx
root   8134 8054 0 21:13 ?    00:00:00 nginx: master process
/usr/local/nginx/sbin/nginx
nginx   8135 8134 0 21:16 ?    00:00:00 nginx: worker process
nginx   8136 8134 0 21:16 ?    00:00:00 nginx: worker process
5. 抉择:
5.1 回滚:
5.1.1 重新拉起老的worker进程:
[root@anonymous nginx-1.20.1]# kill -HUP 8054
[root@anonymous nginx-1.20.1]# ps -ef |grep "[n]ginx"
root   8054   1 0 21:07 ?    00:00:00 nginx: master process
/usr/local/nginx/sbin/nginx
root   8134 8054 0 21:13 ?    00:00:00 nginx: master process
/usr/local/nginx/sbin/nginx
nginx   8135 8134 0 21:16 ?    00:00:00 nginx: worker process
nginx   8136 8134 0 21:16 ?    00:00:00 nginx: worker process
nginx   8154 8054 1 21:19 ?    00:00:00 nginx: worker process
nginx   8155 8054 1 21:19 ?    00:00:00 nginx: worker process
5.1.2 退出新的master进程:
[root@anonymous nginx-1.20.1]# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid`
[root@anonymous nginx-1.20.1]# ps -ef |grep "[n]ginx"
root   8054   1 0 21:07 ?    00:00:00 nginx: master process
/usr/local/nginx/sbin/nginx
nginx   8154 8054 0 21:19 ?    00:00:00 nginx: worker process
nginx   8155 8054 0 21:19 ?    00:00:00 nginx: worker process
5.2 新生:
# 经过一段时间测试,服务器没问题,退出老的master:
root@anonymous nginx-1.20.1]# kill -QUIT 8054
root@anonymous nginx-1.20.1]# ps -ef |grep "[n]ginx"
root   8134   1 0 21:24 ?    00:00:00 nginx: master process
/usr/local/nginx/sbin/nginx
nginx   8135 8134 0 21:24 ?    00:00:00 nginx: worker process
nginx   8136 8134 0 21:24 ?    00:00:00 nginx: worker process

posted @ 2021-08-13 00:07  Linux刀客  阅读(157)  评论(0编辑  收藏  举报