首頁  >  文章  >  運維  >  如何在不影響業務的情況下升級nginx版本

如何在不影響業務的情況下升級nginx版本

王林
王林轉載
2020-11-03 16:54:132810瀏覽

如何在不影響業務的情況下升級nginx版本

本文介紹了yum安裝的nginx的平滑升級的方法,如果原先的nginx是編譯安裝的,那麼在升級時要注意自己的實際設定。

(推薦教學:nginx教學

1、檢視yum安裝的nginx版本及現有設定

先記錄先前的配置,後面會用到

nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --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_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic’ --with-ld-opt=’-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E’ --add-module=/root/nginx-rtmp-module

configure arguments:後面,即為nginx現有的配置

2、下載需要的新版本的nginx的源碼包

wget http://nginx.org/download/nginx-1.14.2.tar.gz

3、將原先的nginx重要檔案備份(為了安全)

mv /usr/sbin/nginx /usr/sbin/nginx.back 
cp -rf /etc/nginx /etc/nginx.back

4、進行編譯

採用前面查到的配置,如有新模組要新增也可加入

tar xf  nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --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_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic’ --with-ld-opt=’-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E’ --add-module=/root/nginx-rtmp-module

5、make

由於原先已有nginx,所以不能執行make install,否則會覆寫先前的設定檔及內容

make
cp objs/nginx /usr/sbin/nginx

6、檢查是否成功

/usr/sbin/nginx -t

7、平滑切換

注意:要根據自己實際的編譯的設定內容,找出自己的pid檔的位置。文中原來的nginx為yum安裝,所以在 /var/run下。

其實也可在nginx-1.14.2目錄下,使用make update 升級,為了避免問題,建議全手動處理

kill -USR2 `cat /var/run/nginx.pid`              将旧版本Nginx的主进程将重命名为nginx.pid.oldbin,并执行新版本的Nginx可执行程序,启动新的主进程和新的工作进程,再次生成新的nginx.pid文件
kill -WINCH `cat /var/run/nginx.pid.oldbin`      平缓停止worker process(此步骤可省略)
kill -QUIT `cat /var/run/nginx.pid.oldbin`       平缓停止旧的Nginx服务进程

8、檢視

如何在不影響業務的情況下升級nginx版本

#文章補充:

Nginx支援的訊號

可以用來控制Nginx的活動

TERM,INT—快速關閉

QUIT          平滑關閉

HUP           平整重啟,重新載入設定檔

USR1          重新開啟設定檔

USR1              平滑關閉工作進程

以上是如何在不影響業務的情況下升級nginx版本的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:csdn.net。如有侵權,請聯絡admin@php.cn刪除