首页 » nginx » 正文

nginx不间断服务平滑升级

操作系统: CentOS 8
nginx升级前版本: 1.14.2
nginx升级后版本: 1.16.1

1、查看旧版本的编译选项

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

configure arguments: --prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--lock-path=/usr/local/nginx/run/nginx.lock \
--pid-path=/usr/local/nginx/run/nginx.pid \
--error-log-path=/usr/local/nginx/log/nginx.error.log \
--http-log-path=/usr/local/nginx/log/nginx.access.log \
--modules-path=/usr/local/nginx/modules \
--http-client-body-temp-path=/usr/local/nginx/cache/temp/client_temp \
--http-proxy-temp-path=/usr/local/nginx/cache/temp/proxy_temp \
--http-fastcgi-temp-path=/usr/local/nginx/cache/temp/fastcgi_temp \
--http-uwsgi-temp-path=/usr/local/nginx/cache/temp/uwsgi_temp \
--http-scgi-temp-path=/usr/local/nginx/cache/temp/scgi_temp \
--user=nginx --group=nginx \
--with-compat \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-openssl=/usr/local/src/openssl-1.1.1d \
--with-http_gzip_static_module \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-pcre=/usr/local/src/pcre-8.43 \
--with-mail \
--with-mail_ssl_module \
--with-http_v2_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_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_ssl_preread_module \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_slice_module \
--with-http_realip_module \
--with-ld-opt=-ljemalloc

2、备份旧的nginx应用程序

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.ord

3、编译新版本nginx程序

./configure --prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--lock-path=/usr/local/nginx/run/nginx.lock \
--pid-path=/usr/local/nginx/run/nginx.pid \
--error-log-path=/usr/local/nginx/log/nginx.error.log \
--http-log-path=/usr/local/nginx/log/nginx.access.log \
--modules-path=/usr/local/nginx/modules \
--http-client-body-temp-path=/usr/local/nginx/cache/temp/client_temp \
--http-proxy-temp-path=/usr/local/nginx/cache/temp/proxy_temp \
--http-fastcgi-temp-path=/usr/local/nginx/cache/temp/fastcgi_temp \
--http-uwsgi-temp-path=/usr/local/nginx/cache/temp/uwsgi_temp \
--http-scgi-temp-path=/usr/local/nginx/cache/temp/scgi_temp \
--user=nginx --group=nginx \
--with-compat \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-openssl=/usr/local/src/openssl-1.1.1d \
--with-http_gzip_static_module \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-pcre=/usr/local/src/pcre-8.43 \
--with-mail \
--with-mail_ssl_module \
--with-http_v2_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_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_ssl_preread_module \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_slice_module \
--with-http_realip_module \
--with-ld-opt=-ljemalloc

make
make install

4、检查新版本是否兼容旧版本nginx配置文件

/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

5、切换新旧版nginx程序工作进程

发送USR2信号给旧版本主进程号,使nginx的旧版本停止接收请求,用nginx新版本接替,且老进程处理完所有请求,关闭所有连接后,停止运行旧版nginx程序工作进程
kill -USR2 `cat /usr/local/nginx/run/nginx.pid`
关闭旧的nginx进程
kill -QUIT `cat /usr/local/nginx/run/nginx.pid.oldbin`
如果是yum安装或者rpm包方式直接安装的nginx的话,分别执行yum update nginxrpm -Uvh nginx-{version}.rpm即可

发表评论