nginx是一个非常好用的web服务器。 今天介绍nginx的顺利升级。
为了确保nginx确实是平稳的升级,请在升级过程中使用webbench进行压力测试,以验证nginx在升级过程中是否正常运行。
顺利升级应完整参考张宴的nginx本操作,以前需要查看现有的nginx版本、编译安装参数、流程数据等;
查看版本,编译参数: [ root @ test shell ] #/usr/local/nginx/sbin/nginx-v
nginx version: nginx/1.2.7
builtbygcc 4.1.220080704 (red hat 4.1.2-54 ) )。
TLS sni支持禁用
configure arguments 3360-- with-http _ stub _ status _ module-- with-http _ realip
流程数据: [ root @ test shell ] # PS-ef|egrep-egrep|egrep nginx
root 14859 1 0 Oct22? 0:00:00 nginx : master process/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf
appusr 16499 14859 0 Oct22? 03360000336000 nginx :工作器流程
appusr 16500 14859 0 Oct22? 03360000336000 nginx :工作器流程
appusr 16501 14859 0 Oct22? 03360000336000 nginx :工作器流程
appusr 16502 14859 0 Oct22? 03360000336000 nginx :工作器流程
进行顺利的升级操作。
1、下载想要升级nginx版本的东西,编译后覆盖安装。 (默认的新nginx继续安装在旧的nginx目录中。 为了体现升级的差异,在编译时还添加了user、group的定义。
wget 3358 nginx.org/download/nginx-1.5.6.tar.gz
tar -zvxf nginx-1.5.6.tar.gz
cd nginx-1.5.6
./configure-- user=app usr-- group=app usr-- with-http _ stub _ status _ module-- with-http _ SSL _ module
2、[ root @ test nginx-1.5.6 ] # kill-usr 214859【运行旧版本的nginx主进程号】
3、旧版本nginx的主过程,对其pid文件进行重命名,例如. oldbin。 (例如/usr/local/nginx/logs/nginx.PID.old bin ) )。
4、此时,新旧版本的nginx进程正在运行(默认情况下,新版本的nginx会在安装后自动运行)。 )此时,运行kill -WINCH【旧版本的Nginx主进程号】,逐步结束旧版本的Nginx工作器进程; [ root @ test shell ] # kill-winch 14859
[ root @ test shell ] # PS-ef|egrep nginx
root 4906 14859 0 11:19? 0:00:00 nginx : master process/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf
appusr 4907 4906 6 11:19? 0336000336004 nginx :工作器流程
appusr 4908 4906 6 11:19? 0336000336004 nginx :工作器流程
appusr 4909 4906 3 11:19? 0336000336002 nginx :工作器流程
appusr 4910 4906 6 11:19? 0336000336004 nginx :工作器流程
root 497829465011:20 pts/000336000336000 egrep nginx
root 14859 1 0 Oct22? 0:00:00 nginx : master process/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf
appusr 16499 14859 0 Oct22? 0336000336025 nginx : workerprocessisshuttingdown
appusr 16500 14859 0 Oct22? 0336000336027 nginx : workerprocessisshuttingdown
appusr 16502 14859 0 Oct22? 0336000336027 nginx : workerprocessisshuttingdown
可以看到nginx : workerprocessisshuttingdown。 这表明旧版本的nginx工作器进程正在逐渐关闭。
5、等待所有旧版本的工作器进程全部结束,
您输入的请求只通过新的工作流程进行了处理。 使用kill -QUIT14859【旧版本的Nginx主进程编号】,轻松关闭旧版本的主进程编号。 完成版本升级。
此时,检查nginx的版本信息、编译信息和进程信息。
[ root @ test nginx-1.5.6 ] #/usr/local/nginx/sbin/nginx-v
nginx : nginx/1.5.6
builtbygcc 4.1.220080704 (red hat 4.1.2-54 ) )。
TLS sni支持禁用
configure arguments 3360-- user=app usr-- group=app usr---with-http _ stub _ status _ module-with-http _ Sr
以下是新版本的进程信息
[ root @ test shell ] # PS-ef|egrep nginx
root 4906 1 0 11:19? 0:00:00 nginx : master process/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf
appusr 4907 4906 8 11:19? 0336000336015 nginx :工作器流程
appusr 4908 4906 8 11:19? 0336000336015 nginx :工作器流程
appusr 4909 4906 8 11:19? 0336000336015 nginx :工作器流程
appusr 4910 4906 9 11:19? 0336000336016 nginx :工作器流程
root 508229465011:22 pts/000336000336000 egrep nginx
让我们来看看开头提到的webbench测试。 我在总共10分钟内同时请求了1000个总共88万个请求,结果失败了。 证明这次顺利升级没有影响在线服务。