nginx平滑升级实战

                     Nginx 平滑升级

1.查看旧版Nginx的编译参数

[root@master ~]# /usr/local/nginx/sbin/nginx -V

[root@master ~]# ll nginx*

-rw-r--r--. 1 root root 1015384 3月  19 10:45 nginx-1.14.2.tar.gz

-rw-r--r--. 1 root root 1032345 5月  29 19:42 nginx-1.16.0.tar.gz

 

2. 编译新版本Nginx源码包,安装路径需要与旧版一致,注意:不要执行make install

[root@master ~]# tar xf nginx-1.16.0.tar.gz -C /usr/src

[root@master ~]# cd /usr/src/nginx-1.16.0/

[root@master nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module && make

 

3. 备份二进制文件,用新版本的替换

[root@master nginx-1.16.0]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old

[root@master nginx-1.16.0]# ls

auto     CHANGES.ru  configure  html     Makefile  objs    src

CHANGES  conf        contrib    LICENSE  man       README

[root@master nginx-1.16.0]# cp objs/nginx /usr/local/nginx/sbin

 

4. 确保配置文件无报错

[root@master nginx-1.16.0]# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

 

5. 发送USR2信号

向主进程(master)发送USR2信号,Nginx会启动一个新版本的master进程和对应工作进程,和旧版一起处理请求

[root@master~]# ps -ef |grep nginx |grep -v grep

root      65388      1  0 17:07 ?        00:00:00 nginx: master process nginx

nginx     65389  65388  0 17:07 ?        00:00:00 nginx: worker process

[root@master ~]# kill -USR2 65388

 

6,发送WINCN信号

向旧的Nginx主进程(master)发送WINCH信号,他会逐步关闭自己的工作进程,这时所用请求都会有新版nginx处理

[root@master ~]# kill -WINCH 65388

[root@master~]# ps -ef |grep nginx |grep -v grep

root      65388      1  0 17:07 ?        00:00:00 nginx: master process nginx

现在查看部署已经升级完成,查看版本已经成功升级

[root@master~]# /usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.16.0

built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (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_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module

 

7发送QUIT信号退出进程(等服务器不繁忙时可以相当于重启)

Kill -QUIT 65388

 

posted @ 2019-05-29 21:44  #赵程#  阅读(236)  评论(0编辑  收藏  举报