Nginx 平滑升级

Posted by Sunday on 2018-10-12

有时候,我们需要对服务器进行编译添加模块或升级更高版本,此时我们将强制停止服务器,然后在原来基础上升级,这样会关闭之前正在运行的进程。

平滑升级正是解决这个问题的,平滑升级时,不会停掉在运行着的进程,这些进程会继续处理请求,但是不会再接收新的请求,在这些老进程处理完还在处理的请求后,停止。此平滑升级的过程中,新开的进程会被处理。他不会影响我们的进程处理。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar xf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure --prefix=/usr/local/nginx --with-file-aio --with-poll_module \
--with-http_realip_module --with-http_image_filter_module \
--with-http_gzip_static_module --with-http_addition_module \
--with-http_sub_module --with-http_dav_module \
--with-http_flv_module --with-http_slice_module \
--with-http_mp4_module --with-http_random_index_module \
--with-http_secure_link_module --with-http_degradation_module \
--with-http_ssl_module --with-http_stub_status_module \
--with-http_v2_module \
--add-module=../ngx_cache_purge-2.3/
make #注意不要make install
1
2
3
4
5
6
7
8
9
10
11
cp /usr/local/nginx/sbin/nginx{,.bak1012}
cp objs/nginx /usr/local/nginx/sbin/
nginx -t
nginx -v

现在的版本直接reload即可
nginx -s reload

非常低版本操作
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`