备份Nginx1.14.0目录

1
tar -zcvf nginx-old.tar.gz /usr/local/nginx/ -C .

执行以下脚本安装Nginx-1.16.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
export NGINX_VERSION=1.16.0 \
&& export OPENSSL_VERSION=1.1.1 \
&& cd ~ \
&& yum -y install gcc wget perl-devel perl-ExtUtils-Embed pcre-devel zlib-devel\
&& wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \
&& tar -zxvf nginx-${NGINX_VERSION}.tar.gz \
&& wget https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz \
&& tar -zxvf openssl-${OPENSSL_VERSION}.tar.gz -C /usr/local/src/ \
&& cd nginx-${NGINX_VERSION} \
&& ./configure --prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_perl_module \
--with-http_ssl_module \
--with-openssl=/usr/local/src/openssl-${OPENSSL_VERSION} \
--with-http_v2_module \
--with-stream \
--with-stream_ssl_module \
&& make \
&& make install \
&& rm -rf ~/openssl-${OPENSSL_VERSION}.tar.gz \
&& rm -rf ~/nginx-${NGINX_VERSION} \
&& rm -rf ~/nginx-${NGINX_VERSION}.tar.gz \
&& cd ~ \
&& /usr/local/nginx/sbin/nginx -V

启动Nginx-1.16.0

1
kill -USR2 $(cat $(find /usr/local/nginx/ -name nginx.pid))

此时新旧版本Master/Worker进程并存,都会参与负载

关闭Nginx-1.14.0的Worker进程

1
kill -WINCH $(cat $(find /usr/local/nginx/ -name nginx.pid.oldbin))

此时旧版Nginx退出负载,但Master进程依然存在

确认Nginx-1.16.0正常后可完全关闭Nginx-1.14.0

1
kill -QUIT $(cat $(find /usr/local/nginx/ -name nginx.pid.oldbin))

如Nginx-1.16.0启动后出现异常,需要立即回滚旧版本Nginx可使用以下命令

1
2
kill -HUP $(cat $(find /usr/local/nginx/ -name nginx.pid.oldbin))
kill -QUIT $(cat $(find /usr/local/nginx/ -name nginx.pid))

完全回滚Nginx-1.14.0建议重新编译安装,执行如下命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export NGINX_VERSION=1.14.0 \
&& export OPENSSL_VERSION=1.1.1 \
&& cd ~ \
&& yum -y install gcc wget perl-devel perl-ExtUtils-Embed pcre-devel zlib-devel\
&& wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \
&& tar -zxvf nginx-${NGINX_VERSION}.tar.gz \
&& wget https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz \
&& tar -zxvf openssl-${OPENSSL_VERSION}.tar.gz -C /usr/local/src/ \
&& cd nginx-${NGINX_VERSION} \
&& ./configure --prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_perl_module \
--with-http_ssl_module \
--with-openssl=/usr/local/src/openssl-${OPENSSL_VERSION} \
--with-http_v2_module \
--with-stream \
--with-stream_ssl_module \
&& make \
&& make install \
&& rm -rf ~/openssl-${OPENSSL_VERSION}.tar.gz \
&& rm -rf ~/nginx-${NGINX_VERSION} \
&& rm -rf ~/nginx-${NGINX_VERSION}.tar.gz \
&& cd ~ \
&& /usr/local/nginx/sbin/nginx -V \
&& kill -USR2 $(cat $(find /usr/local/nginx/ -name nginx.pid)) \
&& kill -QUIT $(cat $(find /usr/local/nginx/ -name nginx.pid.oldbin))