Nginx1.8.0不间断平滑升级到1.10.1

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx1.8.0不间断平滑升级到1.10.1相关的知识,希望对你有一定的参考价值。

nginx1.8.0平滑升级到1.10.1,不间断服务


1. 先查看当前的版本及原来安装编译时候的参数路径文件信息。

#/usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.8.0

built by gcc 4.1.2 20080704 (Red Hat 4.1.2-50)

built with OpenSSL 1.0.1c 10 May 2012

TLS SNI support enabled

configure arguments: --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=-1.0.1c --with-pcre=/soft/pcre-8.21 --with-zlib=/soft/zlib-1.2.8 --with-http_stub_status_module --with-threads -l_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-bodyar/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi


※这是以前编译的参数。编辑新版本需要用到。


2.下载新版本:http://nginx.org/en/download.html解压、编译

# tar -zxvf nginx-1.10.1.tar.gz

# cd nginx-1.10.1

# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/soft/openssl-1.0.1c --with-pcre=/soft/pcre-8.21 --with-zlib=/soft/zlib-1.2.8 --with-http_stub_status_module --with-threads --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi

# make


编译安装后可以执行echo $?查看是否成功,返回值为0说明正确。


3. 执行完后,不要make install,重名/sbin/nginx为nginx.old

# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old


4. 复制编译后objs目录下的nginx文件到nginx的安装目录sbin下

# cp objs/nginx /usr/local/nginx/sbin/


5. 测试一下新复制过来文件生效情况:

# /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


6. 让nginx把nginx.pid文件修改成nginx.pid.oldbin,随即启动nginx,实现不间断服务。

# kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`  此时查看nginx进程,可以看到新建立的进程和以前的进程同时存在.

查看进程pid文件:

[[email protected] ~]#cd /usr/local/nginx/logs

[[email protected] logs]# ls

access.log  error.log  nginx.pid  nginx.pid.oldbin


结束nginx.pid.oldbin:

# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`

结束后查看nginx进程,此时可以看到nginx进程是新建立的进程,之前的进程已结束。


【QUIT表示处理完当前请求后没关闭进程;

  HUP表示重新加载配置,也就是关闭原有进程,并开启新的工作进程,不会中断用户访问,可以平滑重启nginx;

  USR1用于nginx日志切换,即重新打开一个日志文件;

  USR2用于平滑升级可执行程序;

  WINCH从容关闭工作进程】


7. 升级完成,最后在看一下升级后的版本。

[[email protected]~]# nginx -tv

nginx version: nginx/1.10.1

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


[[email protected] ~]# nginx -V

nginx version: nginx/1.10.1

built by gcc 4.1.2 20080704 (Red Hat 4.1.2-50)

built with OpenSSL 1.0.1c 10 May 2012

TLS SNI support enabled

configure arguments: --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/soft/openssl-1.0.1c --with-pcre=/soft/pcre-8.21 --with-zlib=/soft/zlib-1.2.8 --with-http_stub_status_module --with-threads --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi

[[email protected] ~]# 


本文出自 “花之旭的博客” 博客,请务必保留此出处http://huazhixu123.blog.51cto.com/1591874/1943498

以上是关于Nginx1.8.0不间断平滑升级到1.10.1的主要内容,如果未能解决你的问题,请参考以下文章

Nginx1.8.0版本平滑升级新版本1.9.7

nginx不间断服务平滑升级

Nginx 平滑升级(不需要关闭Nginx升级)

centos6.8下安装部署LNMP(备注:nginx1.8.0+php5.6.10+mysql5.6.12)

nginx1.8.0安装

nginx1.8.0安装