宅男在线永久免费观看网直播,亚洲欧洲日产国码无码久久99,野花社区在线观看视频,亚洲人交乣女bbw,一本一本久久a久久精品综合不卡

全部
常見問題
產(chǎn)品動(dòng)態(tài)
精選推薦

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常見命令

186da20230612144137810.png

  • 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 supervisorctlwhereis 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常用命令

934a7202306121444027380.png

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è)步驟:

  1. 編輯supervisor配置文件,如supervisord.conf
  2. 創(chuàng)建文件夾及文件,如文件夾/var/log/supervisor、/etc/supervisor/conf.d,文件/var/run/supervisor.sock等
  3. 賦值權(quán)限,如chmod 777 /var/run
  4. 編輯程序配置文件,如/etc/supervisor/conf.d/test.conf
  5. 啟動(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í)需要做的步驟

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


請(qǐng)登錄后查看

CRMEB-慕白寒窗雪 最后編輯于2023-06-12 14:46:01

快捷回復(fù)
回復(fù)
回復(fù)
回復(fù)({{post_count}}) {{!is_user ? '我的回復(fù)' :'全部回復(fù)'}}
排序 默認(rèn)正序 回復(fù)倒序 點(diǎn)贊倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level || item.bbs_level }}

作者 管理員 企業(yè)

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推薦': '推薦'}}
{{item.is_suggest == 1? '取消推薦': '推薦'}}
沙發(fā) 板凳 地板 {{item.floor}}#
{{item.user_info.title || '暫無簡介'}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
打賞
已打賞¥{{item.reward_price}}
{{item.like_count}}
{{item.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回復(fù) {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}
打賞
已打賞¥{{itemc.reward_price}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)
查看更多
打賞
已打賞¥{{reward_price}}
2412
{{like_count}}
{{collect_count}}
添加回復(fù) ({{post_count}})

相關(guān)推薦

快速安全登錄

使用微信掃碼登錄
{{item.label}} 加精
{{item.label}} {{item.label}} 板塊推薦 常見問題 產(chǎn)品動(dòng)態(tài) 精選推薦 首頁頭條 首頁動(dòng)態(tài) 首頁推薦
取 消 確 定
回復(fù)
回復(fù)
問題:
問題自動(dòng)獲取的帖子內(nèi)容,不準(zhǔn)確時(shí)需要手動(dòng)修改. [獲取答案]
答案:
提交
bug 需求 取 消 確 定
打賞金額
當(dāng)前余額:¥{{rewardUserInfo.reward_price}}
{{item.price}}元
請(qǐng)輸入 0.1-{{reward_max_price}} 范圍內(nèi)的數(shù)值
打賞成功
¥{{price}}
完成 確認(rèn)打賞

微信登錄/注冊(cè)

切換手機(jī)號(hào)登錄

{{ bind_phone ? '綁定手機(jī)' : '手機(jī)登錄'}}

{{codeText}}
切換微信登錄/注冊(cè)
暫不綁定
CRMEB客服

CRMEB咨詢熱線 咨詢熱線

400-8888-794

微信掃碼咨詢

CRMEB開源商城下載 源碼下載 CRMEB幫助文檔 幫助文檔
返回頂部 返回頂部
CRMEB客服