Nginx 1.8.0不间断平滑升级到1.10.1

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

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

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文件:
[root@Nginx ~]#cd /usr/local/nginx/logs
[root@Nginx 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. 升级完成,最后在看一下升级后的版本。
[root@Nginx~]# 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
 
[root@Nginx ~]# 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
[root@Nginx ~]#

Nginx 的详细介绍请点这里
Nginx 的下载地址请点这里

猜你喜欢

转载自www.linuxidc.com/Linux/2017-07/145396.htm