linux Nginx1.12.0平滑升级到新版本nginx-1.13.3

本篇演示生产环境:Centos7.3 64位 最小化安装版。

1.查看当前Nginx版本信息。代码如下:

# /usr/local/nginx/sbin/nginx -V
 nginx version: nginx/1.12.0
 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
 built with OpenSSL 1.0.1e-fips 11 Feb 2013
 TLS SNI support enabled
 configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-pcre --with-http_v2_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_image_filter_module --with-mail --with-threads --with-mail_ssl_module --with-stream_ssl_module

2.下载nginx-1.13.3版本到/usr/local/下,解压并进入解压后的目录。代码如下:

 # cd /usr/local/
 # wget http://nginx.org/download/nginx-1.13.3.tar.gz
 # wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz //下载最新openssl
 # tar zxvf openssl-1.1.0e.tar.gz //解压文件
 # tar zxvf nginx-1.13.3.tar.gz
 # cd nginx-1.13.3

3.查看nginx版本的时候,configure后面有一大串模块,这也是你第一次安装nginx时所指定的模块,升级的时候也要同时指定,也可以添加其他模块。代码如下:

./configure \
 --prefix=/usr/local/nginx \
 --user=www \
 --group=www \
 --with-pcre \
 --with-openssl=/tmp/openssl-1.1.0e \
 --with-http_ssl_module \
 --with-http_v2_module \
 --with-http_realip_module \
 --with-http_addition_module \
 --with-http_sub_module \
 --with-http_dav_module \
 --with-http_flv_module \
 --with-http_mp4_module \
 --with-http_gunzip_module \
 --with-http_gzip_static_module \
 --with-http_random_index_module \
 --with-http_secure_link_module \
 --with-http_stub_status_module \
 --with-http_auth_request_module \
 --with-http_image_filter_module \
 --with-mail \
 --with-threads \
 --with-mail_ssl_module \
 --with-stream_ssl_module \
 # make

4.注意:make完以后,执行下面代码。不需要执行make install,否则会覆盖安装,nginx服务会出现各种问题。

不中断nginx web服务器的正常运行称之为平滑升级,先重命名之前的nginx二进制文件。代码如下:

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

拷贝刚编译新生产的Nginx二进制文件到/usr/local/nginx/sbin/目录;代码如下:

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

5.开始执行升级命令。代码如下:

# cd /usr/local/nginx-1.13.3
 # make upgrade
 /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
 kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
 sleep 1
 test -f /usr/local/nginx/logs/nginx.pid.oldbin
 kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`

6.再次查看nginx升级后的版本信息。代码如下:

# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.13.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
built with OpenSSL 1.1.0e 16 Feb 2017
TLS SNI support enabled

可以看到已经成功升级到1.13.3,本文教程可用于生产环境当中。希望能帮到大家。转载请注明!