nginx平滑升级并且保持不间断服务

1. 开始之前先查看一下当前使用的版本。

[root@teddy nginx-1.10.2]# /application/nginx-1.10.2/sbin/nginx -V
nginx version: nginx/1.10.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/application/nginx-1.10.2 --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --with-http_realip_module --add-module=/root/ngx_pagespeed-latest-stable

2.下载新版本:
wget http://nginx.org/download/nginx-1.11.5.tar.gz
tar xf nginx-1.11.5.tar.gz
cd nginx-1.11.5

./configure \
 --prefix=/application/nginx-1.10.2 \ 
 --with-http_stub_status_module \
 --with-http_ssl_module \
 --with-http_v2_module \
 --with-http_gzip_static_module \
 --with-http_flv_module \
 --with-http_mp4_module \
 --with-http_realip_module \
 --add-module=/root/ngx_pagespeed-latest-stable

make

3. 执行完后,这里不用在 make install 了,接下来重名/sbin/nginx为nginx.old
mv /application/nginx-1.10.2/sbin/nginx /application/nginx-1.10.2/sbin/nginx.old

4. 复制编译后objs目录下的nginx文件到nginx的安装目录sbin/下
cp objs/nginx /application/nginx-1.10.2/sbin/

5. 测试一下新复制过来文件生效情况:
[root@teddy nginx-1.11.5]# /application/nginx-1.10.2/sbin/nginx -t
nginx: the configuration file /application/nginx-1.10.2/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.10.2/conf/nginx.conf test is successful

6. 让nginx把nginx.pid文件修改成nginx.pid.oldbin,随即启动nginx,实现不间断
kill -USR2 `cat /application/nginx-1.10.2/logs/nginx.pid` 
kill -QUIT `cat /application/nginx-1.10.2/logs/nginx.pid.oldbin`
7. 升级完成了,最后在看一下升级后的版本
[root@teddy nginx-1.11.5]# /application/nginx-1.10.2/sbin/nginx -V
nginx version: nginx/1.11.5
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/application/nginx-1.10.2 --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --with-http_realip_module --add-module=/root/ngx_pagespeed-latest-stable

note:大家可以在升级期间,可以测试一下网站的访问是否有被中断过。

nginx平滑升级并且保持不间断服务
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Scroll to top
0
Would love your thoughts, please comment.x
()
x