1、介紹supervisor
Supervisor是用Python開發(fā)的一個(gè)client/server服務(wù),是Linux/Unix系統(tǒng)下的一個(gè)進(jìn)程管理工具,不支持Windows系統(tǒng)。它可以很方便的監(jiān)聽、啟動(dòng)、停止、重啟一個(gè)或多個(gè)進(jìn)程。用Supervisor管理的進(jìn)程,當(dāng)一個(gè)進(jìn)程意外被殺死,supervisort監(jiān)聽到進(jìn)程死后,會(huì)自動(dòng)將它重新拉起,很方便的做到進(jìn)程自動(dòng)恢復(fù)的功能,不再需要自己寫shell腳本來控制。
2、安裝環(huán)境
# 安裝 python環(huán)境
yum install python-setuptools
# 安裝 Supervisor
easy_install supervisor
3、配置Supervisor
# 新建配置目錄命令:
mkdir /etc/supervisor
#生成supervisor的初始化配置文件 :
echo_supervisord_conf > /etc/supervisor/supervisord.conf
編輯配置supervisord.conf
vim supervisord.conf
主要是打開網(wǎng)絡(luò)訪問、默認(rèn)啟動(dòng)配置目錄


# 創(chuàng)建配置目錄
mkdir /etc/supervisor/conf.d
# 進(jìn)入目錄
cd conf.d
#創(chuàng)建一個(gè)WebApplication1.conf配置
vi WebApplication1.conf
# 創(chuàng)建程序啟動(dòng)配置
# 進(jìn)程名稱
[program:WebApplication1]
# 執(zhí)行命令
command=dotnet WebApplication1.dll
# 執(zhí)行目錄
directory=/root/aspnetcoreapi
# 掉線是否自動(dòng)重啟
autorestart=true
# 日志信息
stderr_logfile=/var/log/WebApplication1.err.log
stdout_logfile=/var/log/WebApplication1.out.log
# 環(huán)境.Net core
environment=ASPNETCORE_ENVIRONMENT=Production
# 執(zhí)行用戶
user=root
stopsignal=INT
4、啟動(dòng)Supervisor
# 啟動(dòng)Supervisor
supervisord -c /etc/supervisor/supervisord.conf
#查看狀態(tài)
supervisorctl status

5、bash終端控制
#啟動(dòng)Supervisor
supervisord -c /etc/supervisor/supervisord.conf
# 查看狀態(tài)
supervisorctl status
# 停止某個(gè)服務(wù)
supervisorctl stop WebApplication1
# 開始某個(gè)服務(wù)
supervisorctl start WebApplication1
# 重啟某個(gè)服務(wù)
supervisorctl restart WebApplication1
# 重啟Supervisor
supervisorctl reload
# 修改Supervisor
supervisorctl update
6、將supervisor配置為開機(jī)自啟動(dòng)服務(wù)
# 編輯服務(wù)文件
vim /usr/lib/systemd/system/supervisord.service
# 內(nèi)容
[Unit]
Description=Supervisor
[Service]
Type=forking
PIDFile=/var/run/supervisord.pid
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
# 保存退出 啟動(dòng)服務(wù)
systemctl enable supervisord
# 查看啟動(dòng)狀態(tài) 返回enabled成功
systemctl is-enabled supervisord
#成功之后,就可以使用如下命令管理supervisor服務(wù)了
# 停止
systemctl stop supervisord
# 啟動(dòng)
systemctl start supervisord
# 狀態(tài)
systemctl status supervisord
# 重載
systemctl reload supervisord
# 重啟
systemctl restart supervisord
我們最后也可以看到我們將進(jìn)程殺死之后馬上會(huì)啟動(dòng)一個(gè)新的進(jìn)程啟動(dòng)程序

最后我們可以通過我們配置的網(wǎng)絡(luò)地址訪問了,可以看到所有的程序方便管理

|