Nginx 平滑升级
1.查看旧版Nginx的编译参数
[[email protected] ~]# /usr/local/nginx/sbin/nginx -V
[[email protected] ~]# 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
[[email protected] ~]# tar xf nginx-1.16.0.tar.gz -C /usr/src
[[email protected] ~]# cd /usr/src/nginx-1.16.0/
[[email protected] 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. 备份二进制文件,用新版本的替换
[[email protected] nginx-1.16.0]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
[[email protected] nginx-1.16.0]# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
[[email protected] nginx-1.16.0]# cp objs/nginx /usr/local/nginx/sbin
4. 确保配置文件无报错
[[email protected] 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进程和对应工作进程,和旧版一起处理请求
[[email protected]~]# 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
[[email protected] ~]# kill -USR2 65388
6,发送WINCN信号
向旧的Nginx主进程(master)发送WINCH信号,他会逐步关闭自己的工作进程,这时所用请求都会有新版nginx处理
[[email protected]master ~]# kill -WINCH 65388
[[email protected]master~]# ps -ef |grep nginx |grep -v grep
root 65388 1 0 17:07 ? 00:00:00 nginx: master process nginx
现在查看部署已经升级完成,查看版本已经成功升级
[[email protected]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
原文地址:https://www.cnblogs.com/zc1741845455/p/10946476.html