WEB开发网
开发学院服务器WEB服务器Nginx Nginx的“安静”升级 阅读

Nginx的“安静”升级

 2012-05-22 15:43:14 来源:WEB开发网   
核心提示: 前言:众所周知,开源软件的升级是快的没得商量,Nginx的“安静”升级,Nginx也不例外,在网上铺天盖地的0.7、0.8版本的使用、升级、优化的方法的时候,旧的工作进程(worker process)处理了所有已连接的请求后退出,仅由新的工作进程来处理输入的请求了:# ps -ef | grep nginx ro

 前言:
众所周知,开源软件的升级是快的没得商量。Nginx也不例外,在网上铺天盖地的0.7、0.8版本的使用、升级、优化的方法的时候,Nginx官方5.15号已经更新到了1.3.0(开发版)。对于线上的Nginx服务器,Nginx提供了很好的升级解决方案,可以在不中断服务的情况下,使用新版本、添加/删除服务器模块等,这也是我今天要写的主题《Nginx的“安静”升级》。
------------------------------------------------------------------------------------
步骤如下:
1)Nginx的旧版本的安装。(线上的服务器应该先已经安装Nginx的比较旧的版本)
2)查看一下当前的Nginx版本。
# nginx -v
nginx version: nginx/0.7.69
3)使用新的可执行程序替换旧的可执行程序,对于编译安装的Nginx,可以将新版本编译安装到旧版本的Nginx安装路径中,替换之前,您最好备份一下旧的可执行文件。
# cp /usr/local/sbin/nginx ~/
# tar zxf nginx-1.3.0.tar.gz
# cd nginx-1.3.0
# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/sbin/nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module
# make && make install
4)查看一下当前的主进程号是多少,然后执行命令:kill -USR2 旧的版本的Nginx主进程号 。
# ps -ef | grep nginx
root 21421 1 0 20:37 ? 00:00:00 nginx: master process nginx
nobody 24021 21421 0 20:49 ? 00:00:00 nginx: worker process
root 28765 24076 0 22:04 pts/1 00:00:00 grep nginx
# kill -USR2 21421
5)旧的版本Nginx的主进程将重命名它的.pid文件为.oldbin(例如:/usr/local/nginx/logs/nginx.pid.oldbin),然后执行新的版本的Nginx可执行程序,依次启动新的主进程和新的工作进程。
# /usr/local/sbin/nginx
# ps -ef | grep nginx
root 21421 1 0 20:37 ? 00:00:00 nginx: master process nginx
nobody 24021 21421 0 20:49 ? 00:00:00 nginx: worker process
root 28768 21421 0 22:04 ? 00:00:00 nginx: master process nginx
nobody 28769 28768 0 22:04 ? 00:00:00 nginx: worker process
root 28786 24076 0 22:11 pts/1 00:00:00 grep nginx
6)此时,新、旧版本的Nginx实例会同时运行,共同处理输入的请求。要逐步停止旧版本的Nginx实例,您必须发送WINCH信号给旧的主进程,然后,它的工作进程就将开始从容关闭。
# kill -WINCH `cat /usr/local/nginx/logs/nginx.pid.oldbin`
7)一段时间后,旧的工作进程(worker process)处理了所有已连接的请求后退出,仅由新的工作进程来处理输入的请求了:
# ps -ef | grep nginx
root 21421 1 0 20:37 ? 00:00:00 nginx: master process nginx
root 28768 21421 0 22:04 ? 00:00:00 nginx: master process nginx
nobody 28769 28768 0 22:04 ? 00:00:00 nginx: worker process
root 28799 24076 0 22:15 pts/1 00:00:00 grep nginx
8)发送QUIT信号给旧的主进程,使其退出而只留下新的Nginx服务器运行。
# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
# ps -ef | grep nginx
root 28768 1 0 22:04 ? 00:00:00 nginx: master process nginx
nobody 28769 28768 0 22:04 ? 00:00:00 nginx: worker process

1 2  下一页

Tags:Nginx 安静 升级

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接