環境:html
Centos 7python
已安裝.Net core 2.0.0 .Net core 1.1.2bootstrap
一、Supervisor安裝vim
yum install supervisorbash
(阿里雲驗證經過)post
若是yum安裝沒法找到資源,能夠經過easy_installui
wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py -O - | sudo python阿里雲
安裝supervisorurl
easy_install supervisorspa
二、配置supervisor
mkdir -m 700 -p /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf
vim /etc/supervisor/supervisord.conf
在文件末尾添加,注意首尾需無空格,需頂格
[include]
files=/etc/supervisor/conf.d/*.conf
mkdir -m 700 /etc/supervisor/conf.d
三、建立進程配置文件
vim /etc/supervisor/conf.d/MyDotNetName.conf
"MyDotNetName"能夠爲dotnet core 入口dll文件名字 ,插入內容,注意首尾需無空格,需頂格:
[program:MyDotNetName] command=/bin/bash -c "dotnet MyDotNetName.dll" directory=/usr/PublishOutput/
stderr_logfile=/var/log/MyDotNetName.error.log stdout_logfile=/var/log/MyDotNetName.stdout.log
environment=ASPNETCORE_ENVIRONMENT=Production
user=root
stopsignal=INT autostart=true
autorestart=true startsecs=3
[program:MyDotNetName] ;顯示名稱
command=/bin/bash -c "dotnet MyDotNetName.dll" ;運行命令,啓動dotnet進程
directory=/usr/PublishOutput/ ;MyDotNetName目錄
stderr_logfile=/var/log/MyDotNetName.error.log ;錯誤日誌文件
stdout_logfile=/var/log/MyDotNetName.stdout.log ;日誌文件
environment=ASPNETCORE_ENVIRONMENT=Production ;進程環境變量
user=root ;進程執行用戶
autostart=true ;自動啓動 autorestart=true ;是否自動重啓
startsecs=3 ;自動重啓間隔時間
四、建立supervisor 自啓動服務
vim /etc/systemd/system/supervisor.service
編輯內容:
[Unit] Description=supervisor [Service] Type=forking ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf ExecStop=/usr/bin/supervisorctl shutdown ExecReload=/usr/bin/supervisorctl reload KillMode=process Restart=on-failure RestartSec=42s [Install] WantedBy=multi-user.target
使配置生效
systemctl daemon-reload
設置服務開機啓動,即設置enable
systemctl enable supervisor.service
啓動服務
systemctl start supervisor.service
五、驗證dotnet進程是否啓動
使用命令「ps -ef | grep dotnet」查看dotnet 是否運行
[root@machine ~]# ps -ef | grep dotnet root 2281 2280 0 15:27 ? 00:00:00 dotnet MyDotNetName.dll root 2302 2217 0 15:30 pts/0 00:00:00 grep --color=auto dotnet
六、supervisor遠程管理
使用命令「vim /etc/supervisor/supervisord.conf」修改配置文件,以下設置
;[inet_http_server] ; inet (TCP) server disabled by default ;port=127.0.0.1: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))
;如下內容開啓http服務 [inet_http_server] port=192.168.1.71:9001 ;ip 加端口 username=admin ;登錄帳號,能夠不設 password=123456 ;登錄帳戶,能夠不設
重啓服務,就能夠訪問了
注意防火牆是否對端口9001例外
可能遇到的問題:
supervisor 啓動dotnet.core 報「 too many start retries too quickly」