欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Nginx熱部署的實(shí)現(xiàn)

 更新時(shí)間:2021年12月22日 09:17:24   作者:ITKaven  
本文主要介紹了Nginx熱部署的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

跟著上面這篇博客進(jìn)行操作即可。關(guān)閉防火墻,讓本地可以通過(guò)瀏覽器訪問(wèn)Nginx服務(wù)。

[root@localhost ~]# systemctl stop firewalld

在這里插入圖片描述

信號(hào)量

查看信號(hào)量:

[root@localhost ~]# kill -l
 1) SIGHUP	 2) SIGINT	 3) SIGQUIT	 4) SIGILL	 5) SIGTRAP
 6) SIGABRT	 7) SIGBUS	 8) SIGFPE	 9) SIGKILL	10) SIGUSR1
11) SIGSEGV	12) SIGUSR2	13) SIGPIPE	14) SIGALRM	15) SIGTERM
16) SIGSTKFLT	17) SIGCHLD	18) SIGCONT	19) SIGSTOP	20) SIGTSTP
21) SIGTTIN	22) SIGTTOU	23) SIGURG	24) SIGXCPU	25) SIGXFSZ
26) SIGVTALRM	27) SIGPROF	28) SIGWINCH	29) SIGIO	30) SIGPWR
31) SIGSYS	34) SIGRTMIN	35) SIGRTMIN+1	36) SIGRTMIN+2	37) SIGRTMIN+3
38) SIGRTMIN+4	39) SIGRTMIN+5	40) SIGRTMIN+6	41) SIGRTMIN+7	42) SIGRTMIN+8
43) SIGRTMIN+9	44) SIGRTMIN+10	45) SIGRTMIN+11	46) SIGRTMIN+12	47) SIGRTMIN+13
48) SIGRTMIN+14	49) SIGRTMIN+15	50) SIGRTMAX-14	51) SIGRTMAX-13	52) SIGRTMAX-12
53) SIGRTMAX-11	54) SIGRTMAX-10	55) SIGRTMAX-9	56) SIGRTMAX-8	57) SIGRTMAX-7
58) SIGRTMAX-6	59) SIGRTMAX-5	60) SIGRTMAX-4	61) SIGRTMAX-3	62) SIGRTMAX-2
63) SIGRTMAX-1	64) SIGRTMAX	

64種信號(hào)量,以下是幾種常用的信號(hào)量:

  • SIGINT 、SIGTERM:快速關(guān)閉。
  • SIGQUIT:從容關(guān)閉(優(yōu)雅的關(guān)閉進(jìn)程,即等請(qǐng)求結(jié)束后再關(guān)閉)。
  • SIGHUP:平滑重啟,重新加載配置文件 (平滑重啟,修改配置文件之后不用重啟服務(wù)器)。
  • SIGUSR1 :重新讀取日志文件,在切割日志文件時(shí)用途較大。
  • SIGUSR2:平滑升級(jí)可執(zhí)行程序 ,nginx升級(jí)時(shí)候用。
  • SIGWINCH :從容關(guān)閉工作進(jìn)程。

Nginx熱部署

Nginx是一個(gè)多進(jìn)程的高性能反向代理服務(wù)器,包含一個(gè)master進(jìn)程和多個(gè)worker進(jìn)程(worker進(jìn)程的數(shù)量可以通過(guò)nginx.conf配置文件中的worker_processes參數(shù)進(jìn)行設(shè)置,默認(rèn)1個(gè)),這樣可以充分利用多核處理器。

在這里插入圖片描述

默認(rèn)1個(gè)worker進(jìn)程。

在這里插入圖片描述

并且master進(jìn)程和worker進(jìn)程是父子進(jìn)程關(guān)系。

在這里插入圖片描述

Nginx工作模式為多進(jìn)程,Nginx在啟動(dòng)之后會(huì)有一個(gè)master進(jìn)程和多個(gè)worker進(jìn)程(默認(rèn)1個(gè)),多個(gè)worker子進(jìn)程將監(jiān)聽(tīng)master父進(jìn)程監(jiān)聽(tīng)的端口(參考父子進(jìn)程的關(guān)系),并行處理請(qǐng)求。master父進(jìn)程主要用來(lái)管理worker子進(jìn)程(管理真正提供服務(wù)的worker進(jìn)程,向worker進(jìn)程發(fā)送信號(hào),監(jiān)控worker進(jìn)程的運(yùn)行狀態(tài),當(dāng)worker進(jìn)程異常退出后,會(huì)重新啟動(dòng)新的worker進(jìn)程),讀取并驗(yàn)證配置信息,master進(jìn)程不會(huì)對(duì)用戶請(qǐng)求提供服務(wù),而用戶請(qǐng)求是由worker進(jìn)程進(jìn)行處理。

Nginx是通過(guò)信號(hào)量來(lái)控制,比如停止和重啟Nginx。信號(hào)量是進(jìn)程間通信的一種機(jī)制,master主進(jìn)程控制多個(gè)worker子進(jìn)程,也是通過(guò)信號(hào)量。

在這里插入圖片描述

現(xiàn)在來(lái)演示Nginx是怎么實(shí)現(xiàn)熱部署的,博主通過(guò)修改Nginx的配置文件來(lái)模擬Nginx的升級(jí)(先copy一份副本)。

[root@localhost ~]# cd /usr/local/nginx/conf/
[root@localhost conf]# ll
總用量 68
-rw-r--r--. 1 root root 1077 12月 20 20:24 fastcgi.conf
-rw-r--r--. 1 root root 1077 12月 20 20:24 fastcgi.conf.default
-rw-r--r--. 1 root root 1007 12月 20 20:24 fastcgi_params
-rw-r--r--. 1 root root 1007 12月 20 20:24 fastcgi_params.default
-rw-r--r--. 1 root root 2837 12月 20 20:24 koi-utf
-rw-r--r--. 1 root root 2223 12月 20 20:24 koi-win
-rw-r--r--. 1 root root 5231 12月 20 20:24 mime.types
-rw-r--r--. 1 root root 5231 12月 20 20:24 mime.types.default
-rw-r--r--. 1 root root 2656 12月 20 21:26 nginx.conf
-rw-r--r--. 1 root root 2656 12月 20 20:24 nginx.conf.default
-rw-r--r--. 1 root root  636 12月 20 20:24 scgi_params
-rw-r--r--. 1 root root  636 12月 20 20:24 scgi_params.default
-rw-r--r--. 1 root root  664 12月 20 20:24 uwsgi_params
-rw-r--r--. 1 root root  664 12月 20 20:24 uwsgi_params.default
-rw-r--r--. 1 root root 3610 12月 20 20:24 win-utf
[root@localhost conf]# cp nginx.conf nginx_old.conf
[root@localhost conf]# vim nginx.conf

在這里插入圖片描述

由于還沒(méi)有給Nginx進(jìn)行熱部署,現(xiàn)在訪問(wèn)http://192.168.1.199/還是原來(lái)的Nginx頁(yè)面。

在這里插入圖片描述

查看Nginx的進(jìn)程:

[root@localhost conf]# ps -ef | grep nginx
root     14964     1  0 22:25 ?        00:00:00 nginx: master process ./nginx
nobody   14965 14964  0 22:25 ?        00:00:00 nginx: worker process
root     15016  1521  0 23:07 pts/0    00:00:00 grep --color=auto nginx

master進(jìn)程發(fā)送SIGUSR2信號(hào),讓Nginx平滑升級(jí)可執(zhí)行程序。可以看到Nginx重新啟動(dòng)了一組master進(jìn)程和worker進(jìn)程,而新master進(jìn)程是舊master進(jìn)程的子進(jìn)程(通過(guò)父子進(jìn)程的繼承關(guān)系,新master進(jìn)程可以很方便地繼承舊master進(jìn)程的相關(guān)資源)。

[root@localhost conf]# kill -s SIGUSR2 14964
[root@localhost conf]# ps -ef | grep nginx
root     14964     1  0 22:25 ?        00:00:00 nginx: master process ./nginx
nobody   14965 14964  0 22:25 ?        00:00:00 nginx: worker process
root     15019 14964  0 23:18 ?        00:00:00 nginx: master process ./nginx
nobody   15020 15019  0 23:18 ?        00:00:00 nginx: worker process
root     15022  1521  0 23:19 pts/0    00:00:00 grep --color=auto nginx

并且Nginx在日志目錄中存儲(chǔ)了新舊pid文件(保存了新舊master進(jìn)程的ID)。

[root@localhost conf]# ll ../logs
總用量 16
-rw-r--r--. 1 root root 2729 12月 20 23:20 access.log
-rw-r--r--. 1 root root  708 12月 20 23:18 error.log
-rw-r--r--. 1 root root    6 12月 20 23:18 nginx.pid
-rw-r--r--. 1 root root    6 12月 20 22:25 nginx.pid.oldbin
[root@localhost conf]# cat ../logs/nginx.pid
15019
[root@localhost conf]# cat ../logs/nginx.pid.oldbin 
14964

給舊master進(jìn)程發(fā)送SIGWINCH信號(hào),讓舊master進(jìn)程關(guān)閉舊worker進(jìn)程。

[root@localhost conf]# kill -s SIGWINCH 14964
[root@localhost conf]# ps -ef | grep nginx
root     14964     1  0 22:25 ?        00:00:00 nginx: master process ./nginx
root     15019 14964  0 23:18 ?        00:00:00 nginx: master process ./nginx
nobody   15020 15019  0 23:18 ?        00:00:00 nginx: worker process
root     15030  1521  0 23:27 pts/0    00:00:00 grep --color=auto nginx

現(xiàn)在訪問(wèn)http://192.168.1.199/,會(huì)響應(yīng)404。

在這里插入圖片描述

而訪問(wèn)http://192.168.1.199/nacos,會(huì)訪問(wèn)到Nacos服務(wù)。

在這里插入圖片描述

如果升級(jí)版本沒(méi)有問(wèn)題,就可以給舊master進(jìn)程發(fā)送SIGQUIT信號(hào),讓舊master進(jìn)程關(guān)閉,這樣就只剩下新master進(jìn)程和新worker進(jìn)程,實(shí)現(xiàn)了Nginx的熱部署。

[root@localhost conf]# kill -s SIGQUIT 14964
[root@localhost conf]# ps -ef | grep nginx
root     15019     1  0 23:18 ?        00:00:00 nginx: master process ./nginx
nobody   15020 15019  0 23:18 ?        00:00:00 nginx: worker process
root     15034  1521  0 23:31 pts/0    00:00:00 grep --color=auto nginx

如果升級(jí)版本有問(wèn)題,需要回滾到之前的版本,就可以給舊master進(jìn)程發(fā)送SIGHUP信號(hào),因?yàn)椴┲髦匦逻M(jìn)行了測(cè)試,所以進(jìn)程號(hào)都變了,但很顯然舊master進(jìn)程重新創(chuàng)建了舊worker進(jìn)程,并且進(jìn)行版本升級(jí)的masterworker進(jìn)程沒(méi)有被關(guān)閉。

[root@localhost conf]# kill -s SIGHUP 15084
[root@localhost conf]# ps -ef | grep nginx
root     15084     1  0 12月20 ?      00:00:00 nginx: master process ./nginx
root     15106 15084  0 12月20 ?      00:00:00 nginx: master process ./nginx
nobody   15107 15106  0 12月20 ?      00:00:00 nginx: worker process
nobody   15131 15084  0 00:02 ?        00:00:00 nginx: worker process
root     15141  1521  0 00:09 pts/0    00:00:00 grep --color=auto nginx

給新master進(jìn)程發(fā)送SIGQUIT信號(hào),讓新master進(jìn)程關(guān)閉,這樣就只剩下舊master進(jìn)程和新創(chuàng)建的舊worker進(jìn)程,實(shí)現(xiàn)了回滾。

[root@localhost conf]# kill -s SIGQUIT 15106
[root@localhost conf]# ps -ef | grep nginx
root     15084     1  0 12月20 ?      00:00:00 nginx: master process ./nginx
nobody   15131 15084  0 00:02 ?        00:00:00 nginx: worker process
root     15159  1521  0 00:25 pts/0    00:00:00 grep --color=auto nginx

回滾成功。

在這里插入圖片描述

還需要對(duì)版本回滾(即博主這里的配置文件回滾,不然下次重啟就會(huì)出問(wèn)題)。

[root@localhost conf]# cp -f nginx_old.conf nginx.conf
cp:是否覆蓋"nginx.conf"? y

為什么給舊master進(jìn)程發(fā)送SIGHUP信號(hào),舊master進(jìn)程重新創(chuàng)建的worker進(jìn)程沒(méi)有重新讀取配置文件?下面是官方的說(shuō)明:

Send the HUP signal to the old master process. The old master process will start new worker processes without re-reading the configuration. After that, all new processes can be shut down gracefully, by sending the QUIT signal to the new master process.

向舊master進(jìn)程發(fā)送SIGHUP信號(hào)。舊master進(jìn)程將啟動(dòng)新worker進(jìn)程,而無(wú)需重新讀取配置。之后,通過(guò)向新master進(jìn)程發(fā)送SIGQUIT信號(hào),所有新進(jìn)程都可以正常關(guān)閉。

如果不存在新進(jìn)程的情況下(只有一組masterworker進(jìn)程),修改配置文件,再向master進(jìn)程發(fā)送SIGHUP信號(hào),看是否會(huì)重新加載配置文件。

在這里插入圖片描述

[root@localhost conf]# kill -s SIGHUP 15084

很顯然配置文件被重新加載了,由于博主還沒(méi)有看源碼,只能猜測(cè)Nginx的實(shí)現(xiàn)(如果說(shuō)錯(cuò)了,請(qǐng)大家評(píng)論補(bǔ)充),Nginx應(yīng)該是根據(jù)當(dāng)前是否在進(jìn)行熱部署(存在新master進(jìn)程),來(lái)決定SIGHUP信號(hào)是否需要重新加載配置文件。

在這里插入圖片描述

到此這篇關(guān)于Nginx熱部署的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Nginx熱部署內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • nginx location匹配實(shí)例詳解

    nginx location匹配實(shí)例詳解

    這篇文章主要介紹了nginx location匹配實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • nginx設(shè)置超時(shí)時(shí)間的問(wèn)題及解決方案

    nginx設(shè)置超時(shí)時(shí)間的問(wèn)題及解決方案

    程序在處理大量數(shù)據(jù),接口超過(guò)1分鐘(默認(rèn)的)未返回?cái)?shù)據(jù),導(dǎo)致等待超時(shí),出現(xiàn)這種情況,我們可以先優(yōu)化程序,縮短執(zhí)行時(shí)間,可以調(diào)大nginx超時(shí)限制的參數(shù),使程序可以正常執(zhí)行,本文介紹nginx設(shè)置超時(shí)時(shí)間及504 Gateway Time-out的問(wèn)題解決方案,一起看看吧
    2024-02-02
  • Nginx基礎(chǔ)location語(yǔ)法及功能配置實(shí)例

    Nginx基礎(chǔ)location語(yǔ)法及功能配置實(shí)例

    這篇文章主要為大家介紹了Nginx基礎(chǔ)location語(yǔ)法及功能以及配置實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-03-03
  • Linux上搭載Nginx負(fù)載均衡配置使用案例詳解

    Linux上搭載Nginx負(fù)載均衡配置使用案例詳解

    這篇文章主要介紹了Linux上搭載Nginx負(fù)載均衡配置使用案例詳解,針對(duì)此情況而衍生出來(lái)的一種廉價(jià)有效透明的方法以擴(kuò)展現(xiàn)有網(wǎng)絡(luò)設(shè)備和服務(wù)器的帶寬、增加吞吐量、加強(qiáng)網(wǎng)絡(luò)數(shù)據(jù)處理能力、提高網(wǎng)絡(luò)的靈活性和可用性的技術(shù)就是負(fù)載均衡(Load?Balance),需要的朋友可以參考下
    2022-01-01
  • Linux系統(tǒng)下nginx日志每天定時(shí)切割的腳本寫法

    Linux系統(tǒng)下nginx日志每天定時(shí)切割的腳本寫法

    本篇文章給大家分享使用Linux系統(tǒng)自帶的命令logrotate對(duì)Nginx日志進(jìn)行切割的方法,對(duì)nginx日志切割腳本感興趣的朋友一起學(xué)習(xí)吧
    2016-11-11
  • nginx泛域名解析配置教程

    nginx泛域名解析配置教程

    這篇文章主要介紹了nginx泛域名解析配置教程,需要的朋友可以參考下
    2017-01-01
  • 為Nginx自定義404,502錯(cuò)誤頁(yè)面的方法

    為Nginx自定義404,502錯(cuò)誤頁(yè)面的方法

    為Nginx自定義404,502錯(cuò)誤頁(yè)面的方法,需要的朋友可以參考下。
    2010-12-12
  • 利用njs模塊在nginx配置中引入js腳本

    利用njs模塊在nginx配置中引入js腳本

    這篇文章主要給大家介紹了關(guān)于利用njs模塊在nginx配置中引入js腳本的相關(guān)資料,通過(guò)這個(gè)腳本實(shí)現(xiàn)一些更復(fù)雜的?nginx?配置功能,需要的朋友可以參考下
    2021-12-12
  • HipChat上傳文件報(bào)未知錯(cuò)誤的原因分析及解決方案

    HipChat上傳文件報(bào)未知錯(cuò)誤的原因分析及解決方案

    HipChat的功能類似于Campfire、Sazneo等在線協(xié)同工具,并且和Yammer以及Salesforce的Chatter等企業(yè)社交平臺(tái)有一定相似之處。你可以為單個(gè)項(xiàng)目或者小組搭建自有的聊天室,也可以很方便的發(fā)起一對(duì)一聊天
    2016-01-01
  • LNMP 解決Access Denied錯(cuò)誤詳細(xì)介紹

    LNMP 解決Access Denied錯(cuò)誤詳細(xì)介紹

    這篇文章主要介紹了LNMP 解決Access Denied錯(cuò)誤詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下
    2016-10-10

最新評(píng)論