搜尋
首頁運維Nginx如何在不影響業務的情況下升級nginx版本

如何在不影響業務的情況下升級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。如有侵權,請聯絡admin@php.cn刪除
使用NGINX:優化網站性能和可靠性使用NGINX:優化網站性能和可靠性May 09, 2025 am 12:19 AM

NGINX可通过以下方式提升网站性能和可靠性:1.作为Web服务器处理静态内容;2.作为反向代理服务器转发请求;3.作为负载均衡器分配请求;4.作为缓存服务器减轻后端压力。通过配置优化如启用Gzip压缩和调整连接池,NGINX能显著提高网站性能。

NGINX的目的:服務Web內容等NGINX的目的:服務Web內容等May 08, 2025 am 12:07 AM

nginxserveswebcontentandactsasareverseproxy,loadBalancer和more.1)效率高效的servesstaticContentLikeHtmlandImages.2)itfunctionsasareverseproxybalancer,and andginxenhanceperforfforfforfforfforfforffrenfcaching.4)

NGINX單元:簡化應用程序部署NGINX單元:簡化應用程序部署May 07, 2025 am 12:08 AM

NGINXUnit通過動態配置和多語言支持簡化應用部署。 1)動態配置無需重啟服務器即可修改。 2)支持多種編程語言,如Python、PHP、Java。 3)採用異步非阻塞I/O模型,提升高並發處理性能。

NGINX的影響:Web服務器及其他NGINX的影響:Web服務器及其他May 06, 2025 am 12:05 AM

NGINX起初解決C10K問題,現已發展為處理負載均衡、反向代理和API網關的全能選手。 1)它以事件驅動和非阻塞架構聞名,適合高並發。 2)NGINX可作為HTTP和反向代理服務器,支持IMAP/POP3。3)其工作原理基於事件驅動和異步I/O模型,提升了性能。 4)基本用法包括配置虛擬主機和負載均衡,高級用法涉及復雜負載均衡和緩存策略。 5)常見錯誤包括配置語法錯誤和權限問題,調試技巧包括使用nginx-t命令和stub_status模塊。 6)性能優化建議包括調整worker參數、使用gzip壓縮和

NGINX故障排除:診斷和解決常見錯誤NGINX故障排除:診斷和解決常見錯誤May 05, 2025 am 12:09 AM

Nginx常見錯誤的診斷與解決方法包括:1.查看日誌文件,2.調整配置文件,3.優化性能。通過分析日誌、調整超時設置和優化緩存及負載均衡,可以有效解決404、502、504等錯誤,提高網站穩定性和性能。

使用NGINX單元部署應用程序:指南使用NGINX單元部署應用程序:指南May 04, 2025 am 12:03 AM

nginxunitischosenfordEployingApplicationsDuetoItsflexibility flexibility,sisofuse,andability tohandledynamicApplications.1)itupportsmultProgramprogrogminglanguagesLikeLikeLikePython,php,node.js,andjava.2)

NGINX和Web託管:服務文件和管理流量NGINX和Web託管:服務文件和管理流量May 03, 2025 am 12:14 AM

NGINX可用於服務文件和管理流量。 1)配置NGINX服務靜態文件:定義監聽端口和文件目錄。 2)實現負載均衡和流量管理:使用upstream模塊和緩存策略優化性能。

NGINX與Apache:比較Web服務器技術NGINX與Apache:比較Web服務器技術May 02, 2025 am 12:08 AM

NGINX適合處理高並發和靜態內容,Apache適用於動態內容和復雜URL重寫。 1.NGINX採用事件驅動模型,適合高並發。 2.Apache使用進程或線程模型,適用於動態內容。 3.NGINX配置簡單,Apache配置複雜但更靈活。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用