nginx是个用起来很爽的webserver。今天介绍一下nginx的平滑升级。
为了验证nginx是真正的平滑升级,在升级过程中使用webbench进行压力测试,查看升级过程中nginx是否工作正常。
平滑升级完全参照张宴的nginx书操作,之前需要查看现有nginx版本、编译安装的参数、进程数据等;
查看版本、编译参数:
[root@test shell]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.2.7
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-54)
TLS SNI support disabled
configure arguments: --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
进程数据:
[root@test shell]# ps -ef |egrep -egrep|egrep nginx
root 14859 1 0 Oct22 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
appusr 16499 14859 0 Oct22 ? 00:00:00 nginx: worker process
appusr 16500 14859 0 Oct22 ? 00:00:00 nginx: worker process
appusr 16501 14859 0 Oct22 ? 00:00:00 nginx: worker process
appusr 16502 14859 0 Oct22 ? 00:00:00 nginx: worker process
下面进行平滑升级操作:
1、下载想要升级nginx版本,然后编译覆盖安装(默认新的nginx将继续安装在旧的nginx目录下)。为了体现出升级的不同我在编译时还增加了关于user、group的定义。
wget http://nginx.org/download/nginx-1.5.6.tar.gz
tar -zvxf nginx-1.5.6.tar.gz
cd nginx-1.5.6
./configure --user=appusr --group=appusr --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module && make && make install
2、执行
[root@test nginx-1.5.6]# kill -USR2 14859 【老版本的Nginx主进程号】
3、旧版本 nginx 的主进程将重命名它的 pid 文件例如 .oldbin(如:/usr/local/nginx/logs/nginx.pid.oldbin)
4、此时,新旧两个版本的nginx进程都在运行中(默认,新版本的nginx在安装后就自动运行。)此时运行 kill -WINCH 【老版本的Nginx主进程号】 使老版本的nginx 的worker process 逐步结束;
[root@test shell]# kill -WINCH 14859
[root@test shell]# ps -ef |egrep nginx
root 4906 14859 0 11:19 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
appusr 4907 4906 6 11:19 ? 00:00:04 nginx: worker process
appusr 4908 4906 6 11:19 ? 00:00:04 nginx: worker process
appusr 4909 4906 3 11:19 ? 00:00:02 nginx: worker process
appusr 4910 4906 6 11:19 ? 00:00:04 nginx: worker process
root 4978 29465 0 11:20 pts/0 00:00:00 egrep nginx
root 14859 1 0 Oct22 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
appusr 16499 14859 0 Oct22 ? 00:00:25 nginx: worker process is shutting down
appusr 16500 14859 0 Oct22 ? 00:00:27 nginx: worker process is shutting down
appusr 16502 14859 0 Oct22 ? 00:00:27 nginx: worker process is shutting down
可以看到nginx: worker process isshutting down,说明老版本的nginx worker process正在逐步关闭。
更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2013-10/91888p2.htm
推荐阅读:
CentOS 6.2实战部署Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm
使用Nginx搭建WEB服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm
搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm
CentOS 6.3下Nginx性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm
CentOS 6.3下配置Nginx加载ngx_pagespeed模块 http://www.linuxidc.com/Linux/2013-09/89657.htm
CentOS 6.4安装配置Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm
Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里
