nginx平滑升级
当需要将正运行的Nginx升级,可以在不中断服务的情况下进行,具体步骤如下:
1、下载新的Nginx,重新编译到旧版本的安装路径中。重编译之前,先备份一下旧的可执行文件。
2、查询原来安装配置信息
# netstat -unlatp | grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2410/nginx tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 2410/nginx # /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.8.1built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module
3、编译新版本(现最新的稳定版为1.10.3)
# tar -xvf nginx-1.10.2.tar.gz
# cd nginx-1.10.23 ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module4 make
# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx-low #备份原版本
# cp objs/nginx /usr/local/nginx/sbin/ #cp新的启动程序到sbin目录
# make upgrade #执行升级
# /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
# kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
# sleep 1
# test -f /usr/local/nginx/logs/nginx.pid.oldbin
# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
注:执行kill -USR2指令,他将存储有旧版本主进程ID的文件重命名为.oldbin:
命令格式:kill -USR2 旧版本的Nginx主进程号
一般情况下是这样的:kill -USR2 `cat /usr/local/nginx/nginx.pid`
4、验证新版本并启动Nginx程序。
# ./sbin/nginx -V
nginx version: nginx/1.10.2 ……………………
# netstat -unlatp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 18308/nginx tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 18308/nginx
# ulimit -SHn 65535
# /usr/local/nginx/sbin/nginx
本文出自 “墨” 博客,请务必保留此出处http://jinyudong.blog.51cto.com/10990408/1911531
原文地址:http://jinyudong.blog.51cto.com/10990408/1911531