NGINX熱部署


備份二進制文件:

cp /usr/bin/nginx nginx.old

把編譯好的新版Nginx的二進制文件覆蓋舊版本。objs目錄為編譯過程中的中間文件目錄。

cp -r /new_nginx/objs/nginx /usr/bin/ -f 

向正在運行Nginx的master進程發送熱部署信號:

ps -ef | grep nginx
root       6668      1  0 19:50 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www        6674   6668  0 19:50 ?        00:00:00 nginx: worker process
www        6677   6668  0 19:50 ?        00:00:00 nginx: worker process
root       9256   7671  0 20:49 pts/0    00:00:00 grep --color=auto nginx
kill -USR2 6668

Nginx將會建立一個新的master和多個worker進程,新的請求新的連接將會發送到新的nginx進程中。舊的nginx進程已不再使用。

root       6668      1  0 19:50 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www        6674   6668  0 19:50 ?        00:00:00 nginx: worker process
www        6677   6668  0 19:50 ?        00:00:00 nginx: worker process
root       9285   6668  0 21:00 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www        9286   9285  7 21:00 ?        00:00:00 nginx: worker process
www        9287   9285  7 21:00 ?        00:00:00 nginx: worker process
root       9289   7671  0 21:00 pts/0    00:00:00 grep --color=auto nginx

關閉舊Nginx進程,注意進程狀態。

kill -WINCH 6668
root       6668      1  0 19:50 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
root       9285   6668  0 21:00 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www        9286   9285  0 21:00 ?        00:00:00 nginx: worker process
www        9287   9285  0 21:00 ?        00:00:00 nginx: worker process
root       9305   7671  0 21:06 pts/0    00:00:00 grep --color=auto nginx

舊的Nginx中worker進程已被銷毀,而master進程還在。用於在新版本的Nginx中若遇到問題,可以重新reload舊版本的nginx進程拉起worker進程,用於保留版本回退,顧舊版本的Nginx主進程不會自動關閉。


Nginx安裝包解壓后的根目錄中有contrib目錄,把contrib/vim下的所有文件復制到~/.vim目錄下以使Nginx的配置文件代碼高亮。

cp -r contrib/vim/* ~/.vim/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM