3分鐘學(xué)會如何上手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)聽到進程死后,可以很方便的讓進程自動恢復(fù),不再需要程序員或系統(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))
配置完成后重啟服務(wù)
systemctl restart supervisord
supervisord應(yīng)用配置
進入supervisord配置文件
cat /etc/supervisord.conf
通過配置文件最后一行看到
[include] files = supervisord.d/*.ini
也就是說,我們所有的應(yīng)用配置文件都保存在這個目錄下,以.ini格式命名保存的,可以自行修改地址,但不要修改后綴
那我們來創(chuàng)建一個受監(jiān)控的應(yīng)用吧
創(chuàng)建測試python配置
創(chuàng)建一個名稱叫做python的應(yīng)用程序配置
vim /etc/supervisord.d/python.ini
配置文件內(nèi)容,其中command就是我們應(yīng)用程序啟動需要執(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
程序內(nèi)容:開啟一個死循環(huán),不停的打印內(nèi)容
while True: print(100)
重啟supervisord使配置文件生效
systemctl restart supervisord
查看應(yīng)用是否正常啟動
1、命令查看
systemctl status supervisord
2、可視化web查看
web端可以重啟,停止,清理日志,查看日志等多個操作
supervisor相關(guān)的幾個命令
安裝完畢,會生成3個系統(tǒng)命令supervisorctl
、supervisord
和echo_supervisord_conf
1. supervisord
,運行supervisor
時會啟動一個進程supervisord
,它負責(zé)啟動所管理的進程,并將所管理的進程作為自己的子進程來啟動,而且可以在所管理的進程出現(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 | 根據(jù)最新的配置,重啟配置更改過的進程,未更新的進程不受影響 |
3. echo_supervisord_conf
用來生成默認的配置文件(默認配置文件,內(nèi)容非常齊全且都有注釋,適合用時查閱,用法是這樣的
echo_supervisord_conf > test.conf
到此這篇關(guān)于3分鐘學(xué)會如何上手supervisor看門狗的文章就介紹到這了,更多相關(guān)3分鐘學(xué)會如何上手supervisor內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Linux用戶自定義at、cron計劃任務(wù)執(zhí)行的方法
今天小編就為大家分享一篇Linux用戶自定義at、cron計劃任務(wù)執(zhí)行的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-07-07linux上TCP connection timeout問題解決辦法
這篇文章主要介紹了 linux上TCP connection timeout問題解決辦法的相關(guān)資料,需要的朋友可以參考下2017-04-04Linux Apache+Proftpd構(gòu)建虛擬主機時要注意的幾個安全問題
Linux下Apache+Proftpd構(gòu)建虛擬主機時要注意的幾個安全問題,大家可以參考下,有其它未完整的地方,大家可以補充下。2009-08-08