安裝
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)配置中的所有程序