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

python進(jìn)程管理工具supervisor安裝使用

 更新時(shí)間:2023年08月08日 11:19:40   作者:學(xué)無止境gwx  
supervisor是一個(gè)用python語言編寫的進(jìn)程管理工具,它可以很方便的監(jiān)聽、啟動(dòng)、停止、重啟一個(gè)或多個(gè)進(jìn)程,本文給大家介紹python進(jìn)程管理工具supervisor安裝使用配置教程,感興趣的朋友一起看看吧

1、概述

supervisor是一個(gè)用python語言編寫的進(jìn)程管理工具,它可以很方便的監(jiān)聽、啟動(dòng)、停止、重啟一個(gè)或多個(gè)進(jìn)程。當(dāng)一個(gè)進(jìn)程意外被殺死,supervisor監(jiān)聽到進(jìn)程死后,可以很方便的讓進(jìn)程自動(dòng)恢復(fù),不再需要程序員或系統(tǒng)管理員自己編寫代碼來控制。

2、架構(gòu):三大構(gòu)成要素

  • supervisord

supervisor的服務(wù)端:運(yùn)行supervisor時(shí)會(huì)啟動(dòng)一個(gè)進(jìn)程supervisord,它負(fù)責(zé)啟動(dòng)所管理的進(jìn)程,并將所管理的進(jìn)程作為自己的子進(jìn)程來啟動(dòng),而且可以在所管理的進(jìn)程出現(xiàn)崩潰時(shí)自動(dòng)重啟

  • supervisorctl

supervisor的客戶端:supervisorctl是命令行管理工具,可以用命令來進(jìn)行子進(jìn)程的管理,supervisorctl常見命令

命令含義
supervisorctl status查看所有子進(jìn)程服務(wù)狀態(tài)
supervisorctl restart重啟所有子進(jìn)程服務(wù)
supervisorctl restart name重啟子進(jìn)程名字為name的服務(wù)
supervisorctl start name開啟子進(jìn)程名字為name的服務(wù)
supervisorctl stop all關(guān)閉所有子進(jìn)程服務(wù)
supervisorctl stop name停止子進(jìn)程名字為name的服務(wù)
supervisorctl shutdown關(guān)閉所有子進(jìn)程服務(wù)
supervisorctl reload重載配置文件,重啟所有子進(jìn)程服務(wù)
supervisorctl update更新所有服務(wù),一般用在添加新服務(wù)后
supervisorctl update name更新子進(jìn)程名字為name服務(wù)
  • echo_supervisord_conf

默認(rèn)的配置文件,一般生成默認(rèn)文件為 supervisor.conf

3、安裝

3.1、supervisor是基于python寫的,所以使用pip來安裝即可。

pip install supervisor

3.2、默認(rèn)生成的幾個(gè)地址需要我們關(guān)注

# supervisord 路徑
/usr/local/bin/supervisord
# supervisorctl 路徑
/usr/local/bin/supervisorctl
# echo_supervisord_conf 路徑
/usr/local/bin/echo_supervisord_conf

如上路徑,我們也可以通過 whereis supervisord 、 whereis supervisorctl 、 whereis echo_supervisord_conf 得到

3.3、驗(yàn)證是否安裝成功

supervisorctl --help

4、配置

4.1、創(chuàng)建 /etc/supervisor 目錄

mkdir /etc/supervisor

???????4.2、創(chuàng)建并修改supervisord.conf文件

echo_supervisord_conf > /etc/supervisor/supervisord.conf

vi /etc/supervisor/supervisord.conf

# 將unix_http_server 下的 file 路徑改成如下內(nèi)容
[unix_http_server] 
file=/var/run/supervisor.sock  ; (the path to the socket file)
# 將supervisord 下的logfile 路徑 和 pidfile 路徑改成如下內(nèi)容
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file; default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile; default supervisord.pid)
[supervisorctl] 
serverurl=unix:///var/run/supervisor.sock ; (use a unix:// URL  for a unix socket)
# 將include 取消注釋并將其下的 files 路徑改成如下內(nèi)容。標(biāo)記著supervisor將會(huì)默認(rèn)運(yùn)行/etc/supervisor/conf.d的所有conf配置文件
[include]
files = /etc/supervisor/conf.d/*.conf

注:上面的路徑只是推薦路徑,你也可以根據(jù)自己的想法,指向不同路徑

4.3、創(chuàng)建并添加文件權(quán)限(上文提到的)

# 創(chuàng)建文件
#touch /var/run/supervisor.sock  # 依據(jù)配置文件自動(dòng)創(chuàng)建
mkdir /var/log/supervisor
touch /var/log/supervisor/supervisord.log
#touch /var/run/supervisord.pid  # 依據(jù)配置文件自動(dòng)創(chuàng)建
mkdir /etc/supervisor/conf.d
# 添加權(quán)限
#chmod 777 /var/run 
#chmod 777 /var/log

4.4、配置supervisor開機(jī)自動(dòng)啟動(dòng)服務(wù)(非必須,按需選擇)

4.4.1、編輯文件(一般自帶,不需要配置) vim /usr/lib/systemd/system/supervisord.service supervisord.service 文件內(nèi)容如下:

[Unit] 
Description=Supervisor daemon 
[Service] 
Type=forking ExecStart=/usr/local/bin/supervisord -c /etc/supervisor/supervisord.conf 
ExecStop=/usr/local/bin/supervisorctl shutdown 
ExecReload=/usr/local/bin/supervisorctl reload 
KillMode=process Restart=on-failure 
RestartSec=42s 
[Install] 
WantedBy=multi-user.target

4.4.2、使能服務(wù) systemctl enable supervisord

???????4.4.3、驗(yàn)證是否使能成功

方法一,出現(xiàn)enable說明成功

systemctl is-enabled supervisord

???????方法二,開關(guān)機(jī)驗(yàn)證

注:supervisor常用命令

命令含義
service supervisord start啟動(dòng)supervisor服務(wù)
service supervisord stop停止supervisor服務(wù)
service supervisord status查看supervisor狀態(tài)

5、如何配置新服務(wù)并系統(tǒng)控制?

假設(shè)服務(wù)名稱為test。啟動(dòng)文件為py類文件entry.py

5.1、創(chuàng)建test.conf并編輯配置文件

vi /etc/supervisor/conf.d/test.conf

[program:test]  # 服務(wù)名稱test
directory = /home/test_project        # 項(xiàng)目路徑,項(xiàng)目運(yùn)行前,會(huì)先切換到這個(gè)目錄
command= /home/test_project/entry.py  # 程序入口主文件絕對(duì)路徑 
autostart=true                        # 如果是true的話,子進(jìn)程將在supervisord啟動(dòng)后被自動(dòng)啟動(dòng),默認(rèn)就是true 
autorestart=true                      # 子進(jìn)程掛掉后自動(dòng)重啟的情況,有三個(gè)選項(xiàng),false,unexpected和true。false表示無論什么情況下,都不會(huì)被重新啟動(dòng);unexpected表示只有當(dāng)進(jìn)程的退出碼不在下面的exitcodes里面定義的退出碼的時(shí)候,才會(huì)被自動(dòng)重啟。當(dāng)為true的時(shí)候,只要子進(jìn)程掛掉,將會(huì)被無條件的重啟 
user=root                             # root用戶執(zhí)行 
redirect_stderr=true                  # 將stderr重定向stdout,默認(rèn)false,與stderr_logfile互斥
startsecs = 5                         # 子進(jìn)程啟動(dòng)多少秒之后,此時(shí)狀態(tài)如果是running,我們認(rèn)為啟動(dòng)成功了,默認(rèn)值1
startretries=5                        # 當(dāng)進(jìn)程啟動(dòng)失敗后,最大嘗試的次數(shù)。當(dāng)超過5次后,進(jìn)程的狀態(tài)變?yōu)镕AIL
stdout_logfile = None                 # 正常日志輸出文件,None表示不輸出
stderr_logfile = None                 # 錯(cuò)誤日志輸出文件,None表示不輸出

5.2、使用supervisorctl客戶端查看程序啟動(dòng)的狀態(tài)前需要先啟動(dòng)supervisor服務(wù)(使用supervisord)

supervisord -c /etc/supervisor/supervisord.conf  # 啟動(dòng)supervisor服務(wù)
# 如果出現(xiàn)
supervisorctl -c /etc/supervisor/supervisord.conf status  # 查看程序啟動(dòng)的狀態(tài)

6、便捷

6.1、如上所示,下載supervisor后,啟動(dòng)項(xiàng)目需要以下幾個(gè)步驟:

  • 編輯supervisor配置文件,如supervisord.conf
  • 創(chuàng)建文件夾及文件,如文件夾/var/log/supervisor、/etc/supervisor/conf.d,文件/var/run/supervisor.sock等
  • 賦值權(quán)限,如chmod 777 /var/run
  • 編輯程序配置文件,如/etc/supervisor/conf.d/test.conf
  • 啟動(dòng),如supervisord -c /etc/supervisor/supervisord.conf

而此時(shí)是有一個(gè)更好的方法,將①④合到一處。①中只關(guān)注重要的一些選項(xiàng)。④中照搬即可 vi /etc/supervisor/conf.d/test.conf

[unix_http_server]
file=/var/run/supervisor.sock  ; (the path to the socket file)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file; default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile; default supervisord.pid)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; (use a unix:// URL  for a unix socket)
[include]
files = /etc/supervisor/conf.d/*.conf
[program:test]  # 服務(wù)名稱test
directory = /home/test_project        # 項(xiàng)目路徑,項(xiàng)目運(yùn)行前,會(huì)先切換到這個(gè)目錄
command= /home/test_project/entry.py  # 程序入口主文件絕對(duì)路徑 
autostart=true                        # 如果是true的話,子進(jìn)程將在supervisord啟動(dòng)后被自動(dòng)啟動(dòng),默認(rèn)就是true 
autorestart=true                      # 子進(jìn)程掛掉后自動(dòng)重啟的情況,有三個(gè)選項(xiàng),false,unexpected和true。false表示無論什么情況下,都不會(huì)被重新啟動(dòng);unexpected表示只有當(dāng)進(jìn)程的退出碼不在下面的exitcodes里面定義的退出碼的時(shí)候,才會(huì)被自動(dòng)重啟。當(dāng)為true的時(shí)候,只要子進(jìn)程掛掉,將會(huì)被無條件的重啟 
user=root                             # root用戶執(zhí)行 
redirect_stderr=true                  # 將stderr重定向stdout,默認(rèn)false,與stderr_logfile互斥
startsecs = 5                         # 子進(jìn)程啟動(dòng)多少秒之后,此時(shí)狀態(tài)如果是running,我們認(rèn)為啟動(dòng)成功了,默認(rèn)值1
startretries=5                        # 當(dāng)進(jìn)程啟動(dòng)失敗后,最大嘗試的次數(shù)。當(dāng)超過5次后,進(jìn)程的狀態(tài)變?yōu)镕AIL
stdout_logfile = None                 # 正常日志輸出文件,None表示不輸出
stderr_logfile = None                 # 錯(cuò)誤日志輸出文件,None表示不輸出

6.2、此時(shí)需要做的步驟

  • 編輯系統(tǒng)配置文件與程序配置文件,6.1中已配置完畢
  • 創(chuàng)建文件夾及文件,參考上
  • 文賦值權(quán)限,參考上文
  • 啟動(dòng),此時(shí)的啟動(dòng)命令就由原來的 supervisord -c /etc/supervisor/supervisord.conf 變?yōu)楝F(xiàn)在的 supervisord -c /etc/supervisor/conf.d/test.conf

到此這篇關(guān)于python進(jìn)程管理工具supervisor安裝使用的文章就介紹到這了,更多相關(guān)python supervisor使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python numpy庫np.percentile用法說明

    python numpy庫np.percentile用法說明

    這篇文章主要介紹了python numpy庫np.percentile用法說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-06-06
  • Python3爬蟲里關(guān)于Splash負(fù)載均衡配置詳解

    Python3爬蟲里關(guān)于Splash負(fù)載均衡配置詳解

    在本篇文章里小編給大家分享了關(guān)于Python3爬蟲里關(guān)于Splash負(fù)載均衡配置的相關(guān)內(nèi)容,需要的朋友們可以學(xué)習(xí)參考下。
    2020-07-07
  • Python爬蟲實(shí)現(xiàn)的根據(jù)分類爬取豆瓣電影信息功能示例

    Python爬蟲實(shí)現(xiàn)的根據(jù)分類爬取豆瓣電影信息功能示例

    這篇文章主要介紹了Python爬蟲實(shí)現(xiàn)的根據(jù)分類爬取豆瓣電影信息功能,結(jié)合完整實(shí)例形式分析了Python針對(duì)電影信息分類抓取的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2019-09-09
  • KMP算法精解及其Python版的代碼示例

    KMP算法精解及其Python版的代碼示例

    KMP算法基本上被人們用作字符串的匹配操作,這里我們就來介紹KMP算法精解及其Python版的代碼示例,需要的朋友可以參考下
    2016-06-06
  • Python+OpenCV實(shí)現(xiàn)角度測量的示例代碼

    Python+OpenCV實(shí)現(xiàn)角度測量的示例代碼

    本文介紹如何使用python語言實(shí)現(xiàn)角度測量,程序包括鼠標(biāo)選點(diǎn)、直線斜率計(jì)算、角度計(jì)算三個(gè)子程序和一個(gè)主程序,感興趣的可以了解一下
    2022-03-03
  • 詳解Python中import機(jī)制

    詳解Python中import機(jī)制

    這篇文章主要介紹了Python中import機(jī)制的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)python,感興趣的朋友可以了解下
    2020-09-09
  • Python列表計(jì)數(shù)及插入實(shí)例

    Python列表計(jì)數(shù)及插入實(shí)例

    這篇文章主要介紹了Python列表計(jì)數(shù)及插入的用法,以實(shí)例形式對(duì)列表的計(jì)數(shù)與插入用法做了較為詳細(xì)的分析,需要的朋友可以參考下
    2014-12-12
  • 現(xiàn)代Python編程的四個(gè)關(guān)鍵點(diǎn)你知道幾個(gè)

    現(xiàn)代Python編程的四個(gè)關(guān)鍵點(diǎn)你知道幾個(gè)

    這篇文章主要為大家詳細(xì)介紹了Python編程的四個(gè)關(guān)鍵點(diǎn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-02-02
  • Python繪制土地利用和土地覆蓋類型圖示例詳解

    Python繪制土地利用和土地覆蓋類型圖示例詳解

    本文介紹了如何使用Python繪制土地利用和土地覆蓋類型圖,并提供了詳細(xì)的代碼示例,通過安裝所需的庫,準(zhǔn)備地理數(shù)據(jù),使用geopandas和matplotlib等庫,可以繪制出土地利用和覆蓋類型圖,感興趣的朋友一起看看吧
    2025-01-01
  • python中l(wèi)ist.copy方法用法詳解

    python中l(wèi)ist.copy方法用法詳解

    這篇文章主要給大家介紹了關(guān)于python中l(wèi)ist.copy方法使用的相關(guān)資料,文中還介紹了python?list.copy()?和?copy.deepcopy()區(qū)別,需要的朋友可以參考下
    2023-02-02

最新評(píng)論