當需要將正在執行的nginx公升級、新增或刪除服務模組時,可以在不中斷服務的情況下,更新公升級,重新編譯nginx替換舊版本。
[root@ ~]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.5.7
built by gcc 4.4.7 20120313 (red hat 4.4.7-4) (gcc)
tls sni support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_auth_request_module --add-module=/data/src/nginx-upstream-fair-master
編譯 nginx/1.10.2,具體的編譯選項根據業務需要來,這裡只是做版本公升級。[root@ src]# tar xf nginx-1.10.2.tar.gz
[root@ src]# make && make install
編譯完後,舊版的二進位制檔案已經被替換為新版的。這時讓新的程序也啟動:[root@ nginx-1.10.2]# kill -usr2 `cat /usr/local/nginx/logs/nginx.pid` && sleep 1s
此時,系統中存在新舊兩類nginx程序
nginx 19571 www 9u ipv4 30087 0t0 tcp *:http (listen)舊版的nginxpid檔案會被命名為nginx.pid.oldbin,這時候從容關閉舊的nginx 子程序,再關閉舊ningx主程序
[root@ nginx-1.10.2]# kill -winch `cat /usr/local/nginx/logs/nginx.pid.oldbin` #關閉舊的子程序
[root@ nginx-1.10.2]# kill -quit `cat /usr/local/nginx/logs/nginx.pid.oldbin` #關閉舊ningx主程序
nginx 19571 www 9u ipv4 30087 0t0 tcp *:http (listen)
回滾
在執行關閉舊子程序前可以停留幾分鐘,或者在執行關閉舊子程序後停留幾分鐘,觀察新程序是否正常。如果有異常可以進行回滾
[root@ nginx-1.10.2]# kill -hup `cat /usr/local/nginx/logs/nginx.pid.oldbin` #重新啟動舊子程序
[root@ nginx-1.10.2]# kill -quit `cat /usr/local/nginx/logs/nginx.pid` #退出新ningx主程序
nginx平滑公升級
先來說下我今天要實驗nginx平滑公升級的環境,從nginx.1.8.0公升級到nginx1.9.5 大概的流程 nginx的程序分為master主程序和work工作程序,master程序主要管理事件訊號接受和分發,所有的請求處理都由work程序處理並返回結 果,nginx的平滑重啟或過載配置檔案等...
Nginx平滑公升級
原文 來自nginx官網 如果想要公升級nginx版本 或者在原本版上增加 刪除模組 同時保持服務不間斷,採用如下方式可滿足要求。1.使用新的二進位制檔案替換老的二進位制檔案,這需要注意的是nginx原始碼在執行make編譯後,不要直接make install,否則可能會覆蓋其他配置檔案,命令如下 ...
Nginx平滑公升級
有時,我們需要對我們的伺服器進行公升級更高版本。此時,如果我們強行將伺服器停止然後直接公升級,這樣原來在伺服器上執行著的程序就會被影響。如何解決這個問題呢?可以通過平滑公升級的方式來解決。平滑公升級時,不會停掉在執行著的程序,這些程序會繼續處理請求,但不會再接受新請求,在這些老程序在處理完還在處理的...