Nginx平滑升級(jí)的詳細(xì)操作方法
一、平滑升級(jí)概述
Nginx方便地幫助我們實(shí)現(xiàn)了平滑升級(jí)。其原理簡(jiǎn)單概括,就是:
(1)在不停掉老進(jìn)程的情況下,啟動(dòng)新進(jìn)程。
(2)老進(jìn)程負(fù)責(zé)處理仍然沒(méi)有處理完的請(qǐng)求,但不再接受處理請(qǐng)求。
(3)新進(jìn)程接受新請(qǐng)求。
(4)老進(jìn)程處理完所有請(qǐng)求,關(guān)閉所有連接后,停止。
這樣就很方便地實(shí)現(xiàn)了平滑升級(jí)。一般有兩種情況下需要升級(jí)Nginx,一種是確實(shí)要升級(jí)Nginx的版本,另一種是要為Nginx添加新的模塊。
二.、升級(jí)過(guò)程
具體的操作也很簡(jiǎn)單,如下:
(0)查看當(dāng)前版本
在存放Nginx的可執(zhí)行文件的目錄下輸入:
(1)下載新的Nginx版本并編譯。
tar zxvf nginx-1.0.11.tar.gz
cd nginx-1.0.11
./configure --add-module=/customized_module_0 --add-module=/customized_module_1
make
注意不要進(jìn)行make install
(2)備份老版本的可執(zhí)行文件
sudo cp nginx nginx.old
(3)修改配置文件
如果有必要的話,進(jìn)行配置文件的修改。
(4)拷貝新的可執(zhí)行文件
(5)升級(jí)
make upgrade
(6)清理多余文件
(7)查看Nginx版本
./nginx -V
三、觀察進(jìn)程變化
在我的機(jī)器上可以觀察到,我配置的是10個(gè)worker進(jìn)程,啟動(dòng)后觀察到:
nobody 6242 6241 2 10:51 ? 00:00:00 nginx: worker process
nobody 6243 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6244 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6245 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6246 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6247 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6248 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6249 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6250 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6251 6241 1 10:51 ? 00:00:00 nginx: worker process
nobody 6252 6241 0 10:51 ? 00:00:00 nginx: cache manager process
nobody 6253 6241 0 10:51 ? 00:00:00 nginx: cache loader process
luming 6310 25051 0 10:51 pts/1 00:00:00 grep --color=auto nginx
nobody 7995 10419 0 Jan12 ? 00:20:37 nginx: worker process is shutting down
nobody 7996 10419 0 Jan12 ? 00:20:11 nginx: worker process is shutting down
nobody 7998 10419 0 Jan12 ? 00:20:04 nginx: worker process is shutting down
nobody 8003 10419 0 Jan12 ? 00:20:12 nginx: worker process is shutting down
root 10419 1 0 Jan08 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
可見(jiàn)新的進(jìn)程有1個(gè)master和10個(gè)worker,另外還有1個(gè)老的master(可以從時(shí)間上看出)和4個(gè)worker(其他6個(gè)老的worker已經(jīng)處理完所有連接而shutdown了)。還有一個(gè)loader進(jìn)程。過(guò)幾秒種可以看到worker只有兩個(gè)了:
nobody 6242 6241 1 10:51 ? 00:00:00 nginx: worker process
nobody 6243 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6244 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6245 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6246 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6247 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6248 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6249 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6250 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6251 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6252 6241 0 10:51 ? 00:00:00 nginx: cache manager process
nobody 6253 6241 0 10:51 ? 00:00:00 nginx: cache loader process
luming 6430 25051 0 10:51 pts/1 00:00:00 grep --color=auto nginx
nobody 7996 10419 0 Jan12 ? 00:20:11 nginx: worker process is shutting down
nobody 8003 10419 0 Jan12 ? 00:20:12 nginx: worker process is shutting down
root 10419 1 0 Jan08 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
再過(guò)一小會(huì)兒觀察:
nobody 6242 6241 0 10:51 ? 00:00:01 nginx: worker process
nobody 6243 6241 0 10:51 ? 00:00:01 nginx: worker process
nobody 6244 6241 0 10:51 ? 00:00:01 nginx: worker process
nobody 6245 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6246 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6247 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6248 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6249 6241 0 10:51 ? 00:00:00 nginx: worker process
nobody 6250 6241 0 10:51 ? 00:00:01 nginx: worker process
nobody 6251 6241 0 10:51 ? 00:00:02 nginx: worker process
nobody 6252 6241 0 10:51 ? 00:00:00 nginx: cache manager process
luming 8680 25051 0 10:56 pts/1 00:00:00 grep --color=auto nginx
Congratulations! You can upgrade your Nginx server gracefully.
相關(guān)文章
Nginx開(kāi)源可視化配置工具NginxConfig使用教程
這篇文章主要為大家介紹了Nginx開(kāi)源可視化配置工具NginxConfig使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06
Nginx啟動(dòng)成功卻無(wú)法訪問(wèn)網(wǎng)頁(yè)的問(wèn)題分析和解決方案(完整的排除方案)
我是用的阿里云的服務(wù)器,所以我的問(wèn)題就在于阿里云服務(wù)器必須單獨(dú)開(kāi)端口,在找到這個(gè)問(wèn)題之前,我已經(jīng)把所有能試的方法試過(guò)了一遍都沒(méi)有問(wèn)題,在增加端口之后直接成功了,如果你也遇到了這樣的問(wèn)題,就和我一起排除吧2023-12-12
關(guān)于nginx proxy_set部分常見(jiàn)配置
這篇文章主要介紹了關(guān)于nginx proxy_set部分常見(jiàn)配置,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05
Nginx請(qǐng)求轉(zhuǎn)發(fā)配置指南
Nginx 是一款高性能的 HTTP 和反向代理服務(wù)器,也是一個(gè) IMAP/POP3/SMTP 代理服務(wù)器,本文檔將介紹如何使用 Nginx 配置請(qǐng)求轉(zhuǎn)發(fā),并解釋一些常用的配置參數(shù),需要的朋友可以參考下2024-10-10
教你利用Nginx 服務(wù)搭建子域環(huán)境提升二維地圖加載性能的步驟
這篇文章主要介紹了利用 Nginx 服務(wù)搭建子域環(huán)境提升二維地圖加載性能,本文分步驟通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2021-09-09
nginx rewrite 實(shí)現(xiàn)URL跳轉(zhuǎn)的方法
今天小編就為大家分享一篇nginx rewrite 實(shí)現(xiàn)URL跳轉(zhuǎn)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-08-08
Nginx+Tomcat實(shí)現(xiàn)動(dòng)靜分離的項(xiàng)目實(shí)踐
本文主要介紹了Nginx+Tomcat實(shí)現(xiàn)動(dòng)靜分離,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2025-01-01
Nginx域名轉(zhuǎn)發(fā)https訪問(wèn)的實(shí)現(xiàn)
這篇文章主要介紹了Nginx域名轉(zhuǎn)發(fā)https訪問(wèn)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10

