.Net?Core?進(jìn)程守護(hù)之Supervisor使用詳解
介紹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腳本來控制。
1、執(zhí)行下列命令安裝supervisor
wget https://mirrors.tuna.tsinghua.edu.cn/epel/epel-release-latest-7.noarch.rpm rpm -ivh epel-release-latest-7.noarch.rpm yum install supervisor -y
2、安裝完成之后,我們到配置目錄去添加兩個(gè)配置文件
文件名可以自定義 ,因?yàn)槲乙渴饂ebUI和webAPI兩個(gè)應(yīng)用程序,所以新建了兩個(gè)配置文件
cd /etc/supervisord.d vi WebApplication.WebUI.ini vi WebApplication.WebAPI.ini
WebApplication.WebUI.ini配置文件
# 冒號(hào)后面為應(yīng)用名稱 [program:WebApplication.WebUI] # 應(yīng)用啟動(dòng)命令,需要dotnet的完整路徑 command=dotnet WebApplication.WebUI.dll --urls http://0.0.0.0:8888 # 進(jìn)程名稱 process_name=%(program_name)s # 應(yīng)用啟動(dòng)的目錄,否則應(yīng)用會(huì)報(bào)找不到文件的錯(cuò)誤 directory=/data/apps/WebApplication.WebUI/ # .net core 應(yīng)用環(huán)境變量,表明是哪個(gè)環(huán)境 environment=ASPNETCORE_ENVIRONMENT=Development # 執(zhí)行用戶 user=root stopsignal=INT # 掉線是否自動(dòng)重啟 autostart=true autorestart=true startsecs=3 priority=1 # 日志輸出路徑,該路徑自定義(路徑不存在需要手動(dòng)創(chuàng)建文件目錄) stderr_logfile=/data/logs/supervisor/log/%(program_name)s_error.log stderr_logfile_maxbytes=50MB stderr_logfile_backups=10 # 日志輸出路徑,該路徑自定義(路徑不存在需要手動(dòng)創(chuàng)建文件目錄) stdout_logfile=/data/logs/supervisor/log/%(program_name)s_error.log stdout_logfile_maxbytes=50MB stdout_logfile_backups=10
WebApplication.WebAPI.ini配置文件
# 冒號(hào)后面為應(yīng)用名稱 [program:WebApplication.WebAPI] # 應(yīng)用啟動(dòng)命令,需要dotnet的完整路徑 command=dotnet WebApplication.WebAPI.dll --urls http://0.0.0.0:7777 # 進(jìn)程名稱 process_name=%(program_name)s # 應(yīng)用啟動(dòng)的目錄,否則應(yīng)用會(huì)報(bào)找不到文件的錯(cuò)誤 directory=/data/apps/WebApplication.WebAPI/ # .net core 應(yīng)用環(huán)境變量,表明是哪個(gè)環(huán)境 environment=ASPNETCORE_ENVIRONMENT=Development # 執(zhí)行用戶 user=root stopsignal=INT # 掉線是否自動(dòng)重啟 autostart=true autorestart=true startsecs=3 priority=1 # 日志輸出路徑,該路徑自定義(路徑不存在需要手動(dòng)創(chuàng)建文件目錄) stderr_logfile=/data/logs/supervisor/log/%(program_name)s_error.log stderr_logfile_maxbytes=50MB stderr_logfile_backups=10 # 日志輸出路徑,該路徑自定義(路徑不存在需要手動(dòng)創(chuàng)建文件目錄) stdout_logfile=/data/logs/supervisor/log/%(program_name)s_error.log stdout_logfile_maxbytes=50MB stdout_logfile_backups=10
3、啟動(dòng)Supervisor
注意:WebApplication.WebUI和WebApplication.WebAPI 應(yīng)用程序需要放在對(duì)應(yīng)目錄下/data/apps
# 啟動(dòng)Supervisor supervisord -c /etc/supervisord.conf #查看狀態(tài) supervisorctl status # 防火墻開放端口(作者兩個(gè)應(yīng)用端口號(hào)分別是7777、8888) firewall-cmd --add-port=8888/tcp --permanent firewall-cmd --add-port=7777/tcp --permanent
4、Supervisor 后臺(tái)管理頁面設(shè)置
vi /etc/supervisord.conf
取消截圖部分注釋
訪問supervsior 后臺(tái)管理頁面,http://192.168.140.129:9001/
5、bash終端控制
#啟動(dòng)Supervisor supervisord -c /etc/supervisor/supervisord.conf # 查看狀態(tài) supervisorctl status # 停止某個(gè)服務(wù) supervisorctl stop WebApplication1 # 停止所有服務(wù) supervisorctl stop all # 開始某個(gè)服務(wù) supervisorctl start WebApplication1 # 開始所有服務(wù) supervisorctl start all # 重啟某個(gè)服務(wù) supervisorctl restart WebApplication1 # 重啟所有服務(wù) supervisorctl restart all # 重啟Supervisor supervisorctl reload # 修改Supervisor supervisorctl update
6、將supervsior 配置設(shè)置為開機(jī)自啟動(dòng)服務(wù)
vi /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 # 驗(yàn)證是否為開機(jī)自啟動(dòng) systemctl is-enabled supervisord
7、supervisord操作命令
# 停止 systemctl stop supervisord # 啟動(dòng) systemctl start supervisord # 狀態(tài) systemctl status supervisord # 重載 systemctl reload supervisord # 重啟 systemctl restart supervisord
參考鏈接:
https://www.cnblogs.com/chenxi001/p/13614831.html
https://www.jianshu.com/p/9d3b993556b2
到此這篇關(guān)于.Net Core 進(jìn)程守護(hù)之Supervisor使用的文章就介紹到這了,更多相關(guān).Net Core Supervisor使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
asp.net基于HashTable實(shí)現(xiàn)購物車的方法
這篇文章主要介紹了asp.net基于HashTable實(shí)現(xiàn)購物車的方法,涉及asp.net中HashTable結(jié)合session實(shí)現(xiàn)購物車功能的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-12-12Asp.net利用JQuery AJAX實(shí)現(xiàn)無刷新評(píng)論思路與代碼
Asp.net利用JQuery AJAX實(shí)現(xiàn)無刷新評(píng)論,此功能是每一個(gè)從事asp.net開發(fā)者的朋友都希望實(shí)現(xiàn)的,本文利用閑暇時(shí)間整理了一些,有需要的朋友可以參考下2012-12-12深入Lumisoft.NET組件POP3郵件接收與刪除操作的使用詳解
本篇文章對(duì)Lumisoft.NET組件POP3郵件接收與刪除操作的使用進(jìn)行了詳細(xì)的介紹。需要的朋友參考下2013-05-05asp.net生成高質(zhì)量縮略圖通用函數(shù)(c#代碼),支持多種生成方式
這兩天正在研究報(bào)表中餅圖的繪圖方法,文章中的某些做法值得參考.2008-08-08Asp.net response對(duì)象與request對(duì)象使用介紹
這篇文章主要介紹了Asp.net response對(duì)象與request對(duì)象使用,需要的朋友可以參考下2014-04-04C# 進(jìn)制轉(zhuǎn)換的實(shí)現(xiàn)(二進(jìn)制、十六進(jìn)制、十進(jìn)制互轉(zhuǎn))
這篇文章主要介紹了C# 進(jìn)制轉(zhuǎn)換的實(shí)現(xiàn)(二進(jìn)制、十六進(jìn)制、十進(jìn)制互轉(zhuǎn)),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01