Nginx平滑公升級

2021-08-04 07:43:50 字數 1970 閱讀 9873

原文 來自nginx官網 :

如果想要公升級nginx版本(或者在原本版上增加、刪除模組),同時保持服務不間斷,採用如下方式可滿足要求。

1. 使用新的二進位制檔案替換老的二進位制檔案,這需要注意的是nginx原始碼在執行make編譯後,不要直接make install,否則可能會覆蓋其他配置檔案,命令如下:

cd /usr/local/nginx/sbin

mv nginx nginx.old

cp ***/nginx .

2. 向老的master程序傳送sigusr2訊號,這一步操作將會引起以下變動:

- 將老的nginx.pid 重新命名為nginx.pid.oldbin 命令如下:

- 執行新的二進位制檔案,啟動master程序,並啟動worker程序

此時,檢視nginx應有兩個master程序及二倍的worker程序

: pid  ppid user    %cpu   vsz wchan  command

33126

1 root 0.0 1164 pause nginx: master process /usr/local/nginx/sbin/nginx

33134

33126 nobody 0.0 1368 kqread nginx: worker process (nginx)

33135

33126 nobody 0.0 1380 kqread nginx: worker process (nginx)

33136

33126 nobody 0.0 1368 kqread nginx: worker process (nginx)

36264

33126 root 0.0 1148 pause nginx: master process /usr/local/nginx/sbin/nginx

36265

36264 nobody 0.0 1364 kqread nginx: worker process (nginx)

36266

36264 nobody 0.0 1364 kqread nginx: worker process (nginx)

36267

36264 nobody 0.0 1364 kqread nginx: worker process (nginx)

命令如下:

kill -s sigusr2 `cat /usr/local/nginx/logs/nginx.pid`

3. 將老的nginx程序優雅的關閉

kill -s sigquit `cat /usr/local/nginx/logs/nginx.pid.oldbin`

此時檢視nginx程序只有乙個master程序了

: pid  ppid user    %cpu   vsz wchan  command

: 36264

1 root 0.0 1148 pause nginx: master process /usr/local/nginx/sbin/nginx

: 36265

36264 nobody 0.0 1364 kqread nginx: worker process (nginx)

: 36266

36264 nobody 0.0 1364 kqread nginx: worker process (nginx)

: 36267

36264 nobody 0.0 1364 kqread nginx: worker process (nginx)

4. 至此 nginx公升級完成,可以檢視下版本是否公升級成功

/usr/local/nginx/sbin/nginx -v

nginx平滑公升級

先來說下我今天要實驗nginx平滑公升級的環境,從nginx.1.8.0公升級到nginx1.9.5 大概的流程 nginx的程序分為master主程序和work工作程序,master程序主要管理事件訊號接受和分發,所有的請求處理都由work程序處理並返回結 果,nginx的平滑重啟或過載配置檔案等...

Nginx平滑公升級

有時,我們需要對我們的伺服器進行公升級更高版本。此時,如果我們強行將伺服器停止然後直接公升級,這樣原來在伺服器上執行著的程序就會被影響。如何解決這個問題呢?可以通過平滑公升級的方式來解決。平滑公升級時,不會停掉在執行著的程序,這些程序會繼續處理請求,但不會再接受新請求,在這些老程序在處理完還在處理的...

nginx平滑公升級

nginx在編譯安裝完成之後,出於以下兩種考慮都需要進行公升級 而nginx所採用的平滑公升級可以保證在不停止服務的情況下解決以上問題。我們以動態增加 with http stub status module模組為例,步驟如下 1.檢視nginx版本號及已安裝模組 root foundation7 ...