supervisor簡(jiǎn)單使用

安裝

yum -y install supervisor
echo_supervisord_conf   //查看是否安裝成功 如果有內(nèi)容輸出的話代表安裝成功

生成配置文件

echo_supervisord_conf > /etc/supervisor/supervisord.conf  

配置項(xiàng)目

修改supervisord.conf文件,去掉最后兩行的注釋并配置項(xiàng)目目錄

[include]

files = supervisord.d/*.ini

配置php-fpm項(xiàng)目示例(注:需要修改php-fpm.conf,設(shè)置daemonize = no,默認(rèn)是yes) /etc/supervisor/supervisord.d/php-fpm.ini

[program:php-fpm]
#腳本目錄
directory=/usr/sbin/
#腳本執(zhí)行命令
command=/usr/sbin/php-fpm
#supervisor啟動(dòng)的時(shí)候是否隨著同時(shí)啟動(dòng),默認(rèn)True
autostart=true
#當(dāng)程序exit的時(shí)候,這個(gè)program不會(huì)自動(dòng)重啟,默認(rèn)unexpected,設(shè)置子進(jìn)程掛掉后自動(dòng)重啟的情況,有三個(gè)>選項(xiàng),false,unexpected和true。如果為false的時(shí)候,無(wú)論什么情況下,都不會(huì)被重新>啟動(dòng),如果為unexpected,只有當(dāng)進(jìn)程的退出碼不在下面的exitcodes里面定義的
autorestart=true
#子進(jìn)程啟動(dòng)多少秒之后,此時(shí)狀態(tài)如果是running,則我們認(rèn)為啟動(dòng)成功了。默認(rèn)值為1
startsecs=1
#腳本運(yùn)行的用戶(hù)身份
user = root
#日志輸出 
stderr_logfile=/var/log/supervisor/php-fpm_stderr.log
stdout_logfile=/var/log/supervisor/php-fpm_stdout.log
#把stderr重定向到stdout,默認(rèn) false
redirect_stderr = true
#stdout日志文件大小,默認(rèn) 50MB
stdout_logfile_maxbytes = 20MB
#stdout日志文件備份數(shù)
stdout_logfile_backups = 20

啟動(dòng)supervisor

supervisord -c /etc/supervisor/supervisord.conf

從下圖可以看到我們kill掉php-fpm后立馬有新的php-fpm進(jìn)程被拉起,說(shuō)明supervisor已經(jīng)監(jiān)聽(tīng)php-fpm成功了


image.png

常用命令

supervisorctl status        //查看所有進(jìn)程的狀態(tài)
supervisorctl stop nginx       //停止nginx
supervisorctl start nginx      //啟動(dòng)nginx
supervisorctl start all      //啟動(dòng)全部配置程序
supervisorctl restart       //重啟es
supervisorctl update        //配置文件修改后使用該命令加載新的配置
supervisorctl reload        //重新啟動(dòng)配置中的所有程序
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容