下载setuptools 46.2.0离线包
参考:installing
1 2 3 4 5 6 7 8 9
| unzip -o -d setuptools-46.2.0 setuptools-46.2.0.zip
cd setuptools-46.2.0
python setup.py install
|
需要安装 uzip 命令:
1 2
| yum install zip yum install unzip
|
从pip下载supervisor
下载supervisor 4.2.0离线包
参考:installing
进入文件所在目录:
1 2 3 4 5 6
| tar -zxvf supervisor-4.2.0.tar.gz cd supervisor-4.2.0
python setup.py install
|
验证安装是否成功
配置supervisor
1 2 3 4 5 6 7 8
| mkdir /etc/supervisord.d/
echo_supervisord_conf > /etc/supervisord.conf
vim /etc/supervisord.conf
|
在 [include]
标签中添加 /etc/supervisord.d/*.conf
1 2
| [include] files = relative/directory/*.ini /etc/supervisord.d/*.conf
|
长时间运行会报错 unix:///tmp/supervisor.sock no such file
,参考
解决unix-tmp-supervisor-sock-no-such-file
测试supervisor
常用命令
1 2 3 4 5 6 7
| supervisord -c /etc/supervisord.conf supervisorctl shutdown supervisord -c /etc/supervisord.conf supervisorctl -c /etc/supervisord.conf status supervisorctl -c /etc/supervisord.conf reload supervisorctl -c /etc/supervisord.conf start [all]|[x] supervisorctl -c /etc/supervisord.conf stop [all]|[x]
|
部署测试站点
新建 WebApplication1.conf
:
1 2
| touch /etc/supervisord.d/WebApplication1.conf vim /etc/supervisord.d/WebApplication1.conf
|
内容:
注意:supervisor配置文件中的注释使用英文分号 ;
配置文件名需要与program标签内名称一致!!!
asp net core 站点:
1 2 3 4 5 6 7
| [program:WebApplication1] command=/root/dotnet/dotnet WebApplication1.dll directory=/test/webapi environment=ASPNETCORE_ENVIRONMENT=Production stopsignal=INT stderr_logfile=/var/log/WebApplication1/WebApplication1.err.log stdout_logfile=/var/log/WebApplication1/WebApplication1.out.log
|
注意:如果配置Linux开机启动服务报错,则需要配置 dotnet
命令全路径:/root/dotnet/dotnet
supervisor FATAL can't find command 'dotnet'
webapp 站点,使用 npm http-server
:
1 2 3 4 5 6
| [program:webapp] command=http-server /test/webapp -p 8013 directory=/test/webapp stopsignal=INT stderr_logfile=/var/log/webapp/webapp.err.log stdout_logfile=/var/log/webapp/webapp.out.log
|
详细命令参考:Configuration File
查看站点日志:
1 2
| vim /var/log/WebApplication1.err.log vim /var/log/WebApplication1.out.log
|
配置防火墙
注意:针对各种云,因为有专门策略,所以不需要操作防火墙;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| firewall-cmd --zone=public --add-port=5000/tcp --permanent firewall-cmd --zone=public --add-port=5001/tcp --permanent firewall-cmd --reload
firewall-cmd --query-port=5000/tcp
netstat -lnpt
firewall-cmd --zone=public --remove-port=5000/tcp --permanent
firewall-cmd --zone=public --list-ports
|
测试站点
1 2 3 4 5 6 7
| curl -X GET "http://localhost:5000/weatherforecast" -H "accept: application/json" curl -X GET "https://127.0.0.1:5001/weatherforecast" -H "accept: application/json" curl -X GET "http://192.125.30.82:5000/weatherforecast" -H "accept: application/json"
curl -o /dev/null -s -w %{http_code} -X GET "192.125.30.82:5100/weatherforecast" -H "accept: application/json" curl -o /dev/null -s -w %{http_code} -X GET "192.125.30.82:8013/pages/tsjb/djsl.html" -H "accept: text/html"
|
开机启动
脚本:centos-systemd-etcs
1 2 3 4 5 6 7 8 9
| [root@host supervisor-4.2.0] [root@host supervisor-4.2.0] [root@host supervisor-4.2.0] Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service. [root@host supervisor-4.2.0] enabled [root@host supervisor-4.2.0] [root@host supervisor-4.2.0] [root@host supervisor-4.2.0]
|
supervisord.service:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
[Unit] Description=Supervisor daemon
[Service] Type=forking ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown ExecReload=/usr/bin/supervisorctl $OPTIONS reload KillMode=process Restart=on-failure RestartSec=42s
[Install] WantedBy=multi-user.target
|
设置成功后,可以使用下列命令:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| supervisorctl restart <application name>
supervisorctl stop <application name>
supervisorctl start <application name>
supervisorctl status
supervisorctl restart all
supervisorctl stop all
supervisorctl start all
|
参考:
Installing
Supervisor离线安装、管理