3分鐘學會如何上手supervisor看門狗
軟硬件環(huán)境
- centos7.6.1810 64bit
cat /etc/redhat-release #查看系統(tǒng)版本
- supervisor 3.4.0
- python 2.7.5
supervisor簡介
supervisor是一個用python語言編寫的進程管理工具,它可以很方便的監(jiān)聽、啟動、停止、重啟一個或多個進程。當一個進程意外被殺死,supervisor監(jiān)聽到進程死后,可以很方便的讓進程自動恢復,不再需要程序員或系統(tǒng)管理員自己編寫代碼來控制。
supervisord安裝
yum install -y epel-release yum install -y supervisor
啟動&開啟自啟
systemctl start supervisord systemctl enable supervisord
其他命令:
systemctl stop supervisord #停止啟動 systemctl start supervisord #啟動 systemctl status supervisord #啟動狀態(tài) systemctl reload supervisord #重載 systemctl restart supervisord #重啟
supervisor的web端
supervisor提供了基于web的控制,管理員可以通過在頁面上點點按鈕即可完成對進程的啟動、重啟等操作,甚是方便。
進入配置文件,開啟對web端的支持
vim /etc/supervisord.conf
如果提供給外部訪問,需要將port改為本機ip地址
#取消10-13行注釋,前面數(shù)字是行號 [inet_http_server] ; inet (TCP) server disabled by default port=192.168.26.121:9001 ; (ip_address:port specifier, *:port for all iface) username=user ; (default is no username (open server)) password=123 ; (default is no password (open server))
配置完成后重啟服務
systemctl restart supervisord
supervisord應用配置
進入supervisord配置文件
cat /etc/supervisord.conf
通過配置文件最后一行看到
[include] files = supervisord.d/*.ini
也就是說,我們所有的應用配置文件都保存在這個目錄下,以.ini格式命名保存的,可以自行修改地址,但不要修改后綴
那我們來創(chuàng)建一個受監(jiān)控的應用吧
創(chuàng)建測試python配置
創(chuàng)建一個名稱叫做python的應用程序配置
vim /etc/supervisord.d/python.ini
配置文件內容,其中command就是我們應用程序啟動需要執(zhí)行的命令
[program:python] #這里的python就是我們顯示在web前端以及終端的監(jiān)控名稱 command=python /tmp/supervisordtest/test.py #我們要監(jiān)控的文件地址 autostart=true autorestart=true startsecs=1 startretries=3 redirect_stderr=true stdout_logfile=/tmp/supervisordtest/access_python.log #日志地址,可自行配置目錄 stderr_logfile=/tmp/supervisordtest/error_python.log #日志地址,可自行配置目錄
創(chuàng)建test.py
mkdir /tmp/supervisordtest vim /tmp/supervisordtest/test.py
程序內容:開啟一個死循環(huán),不停的打印內容
while True: print(100)
重啟supervisord使配置文件生效
systemctl restart supervisord
查看應用是否正常啟動
1、命令查看
systemctl status supervisord
2、可視化web查看
web端可以重啟,停止,清理日志,查看日志等多個操作
supervisor相關的幾個命令
安裝完畢,會生成3個系統(tǒng)命令supervisorctl
、supervisord
和echo_supervisord_conf
1.supervisord
,運行supervisor
時會啟動一個進程supervisord
,它負責啟動所管理的進程,并將所管理的進程作為自己的子進程來啟動,而且可以在所管理的進程出現(xiàn)崩潰時自動重啟
2. supervisorctl是命令行管理工具,可以用來執(zhí)行 start
、stop
、restart
等命令,來對這些子進程進行管理, 如
sudo supervisorctl start demoweb
其中demoweb是進程的名稱, 詳細的命令及說明見下面的這張表
命令 | 說明 |
---|---|
supervisorctl start program_name | 啟動某個進程 |
supervisorctl stop program_name | 停止某個進程 |
supervisorctl restart program_name | 重啟某個進程 |
supervisorctl status program_name | 查看某個進程的狀態(tài) |
supervisorctl stop all | 停止全部進程 | \ |
supervisorctl reload | 載入最新的配置文件,重啟所有進程 |
supervisorctl update | 根據最新的配置,重啟配置更改過的進程,未更新的進程不受影響 |
3. echo_supervisord_conf
用來生成默認的配置文件(默認配置文件,內容非常齊全且都有注釋,適合用時查閱,用法是這樣的
echo_supervisord_conf > test.conf
到此這篇關于3分鐘學會如何上手supervisor看門狗的文章就介紹到這了,更多相關3分鐘學會如何上手supervisor內容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持本站!
版權聲明:本站文章來源標注為YINGSOO的內容版權均為本站所有,歡迎引用、轉載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網站,禁止在非www.sddonglingsh.com所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內容來源于網友推薦、互聯(lián)網收集整理而來,僅供學習參考,不代表本站立場,如有內容涉嫌侵權,請聯(lián)系alex-e#qq.com處理。