简介
supervisor可以保证程序崩溃后,可以重新把程序启动起来等相关功能。
安装
yum install -y supervisor
安装好后在/etc/会生成一个supervisord.conf文件及一个supervisord.d文件目录
查看supervisor是否安装成功
supervisord --version
![fc5808709e6f04d3dfc8ed6cb59f4249.png](https://img-blog.csdnimg.cn/img_convert/fc5808709e6f04d3dfc8ed6cb59f4249.png)
启动
supervisord -c /etc/supervisord.conf
查看supervisor是否启动成功
ps -ef|grep supervisord
![4f9b5e27938be78135fcb444f9223dac.png](https://img-blog.csdnimg.cn/img_convert/4f9b5e27938be78135fcb444f9223dac.png)
设置supervisor 开机启动
systemctl enable supervisord
检查是否是开机启动
systemctl is-enabled supervisord
![5d9e4be2995384718c5c6cf06ad3655c.png](https://img-blog.csdnimg.cn/img_convert/5d9e4be2995384718c5c6cf06ad3655c.png)
启动服务
systemctl start supervisord
启动时可能会报错:Another program is already listening on a port that one of our HTTP servers is config...rvisord.
![bbee96183c462fd1e371bdd6ba9381eb.png](https://img-blog.csdnimg.cn/img_convert/bbee96183c462fd1e371bdd6ba9381eb.png)
解决方案:
执行命令 find / -name supervisor.sock 然后 unlink /路径/supervisor.sock 最后再执行启动命令 systemctl start supervisord
查看状态
systemctl status supervisord.service
![911e51ef2f9a2dbf1e9a57f194ec6a43.png](https://img-blog.csdnimg.cn/img_convert/911e51ef2f9a2dbf1e9a57f194ec6a43.png)
配置supervisor ,web管理页面
修改配置信息,supervisor 默认配置文件,放在 /etc/supervisord.conf 路径中:
[inet_http_server] ; HTTP 服务器,提供 web 管理界面port=*:9001 ; Web 管理后台运行的 IP 和端口username=user ; 登录管理后台的用户名password=1234 ; 登录管理后台的密码
[include] files = supervisord.d/*.ini ;配置文件夹
修改完之后重启:
supervisorctl reload
![0763b9e24f1310033a1b46e54cbd9cbc.png](https://img-blog.csdnimg.cn/img_convert/0763b9e24f1310033a1b46e54cbd9cbc.png)
然后通过http://ip:9001/访问web界面,账户名密码就是你配置的,效果如下:
![0fc3c3971987e5572140c87b43cfd87f.png](https://img-blog.csdnimg.cn/img_convert/0fc3c3971987e5572140c87b43cfd87f.png)
创建配置文件
创建一个.ini文件,放在目录supervisord.d下
[program:demo] ;程序名称command=dotnet demo.dll ; 运行命令directory=/web/publish;目录environment=ASPNETCORE_ENVIRONMENT=Production;环境变量user=root;用户stopsignal=INTautostart=true;如果是true的话,子进程将在supervisord启动后被自动启动autorestart=true;进程死掉后自动重启的情况stderr_logfile=/var/log/demo/demo.err.log;错误日志文件stdout_logfile=/var/log/demo/demo.out.log;输出日志文件
![0ec29758127c0cf2b5a50a7301160e4b.png](https://img-blog.csdnimg.cn/img_convert/0ec29758127c0cf2b5a50a7301160e4b.png)
重启
systemctl restart supervisord
查看是否生效
supervisorctl status
![c1e748bf79f7ed52aa039267f020dbcc.png](https://img-blog.csdnimg.cn/img_convert/c1e748bf79f7ed52aa039267f020dbcc.png)
然后把Xshell关了,浏览器中输入:http://ip:8080/api/values,也能看到以下页面:
![74b5d0ccde80bc64633488d4adc56868.png](https://img-blog.csdnimg.cn/img_convert/74b5d0ccde80bc64633488d4adc56868.png)
supervisorctl 常用命令
查看任务状态:supervisorctl status
启动任务:supervisorctl start
停止任务:supervisorctl stop
重启任务:supervisorctl restart
清除日志文件:supervisorctl clear
清除多个日志文件:supervisorctl clear
清除所有日志文件:supervisorctl clear all
移除任务:supervisorctl remove
Nginx代理配置
安裝nginx:Linux - CentOS 7 通过Yum源安装 Nginx
修改nginx.conf
添加一个服务
server { listen 80; server_name 47.106.98.252; location / { root html; index index.html index.htm; proxy_pass http://localhost:8080; } }
检查配置文件是否成功
nginx -t
![bbc225b46e2b534231f29b019a651dd6.png](https://img-blog.csdnimg.cn/img_convert/bbc225b46e2b534231f29b019a651dd6.png)
成功之后重启Nginx服务
systemctl restart nginx.service
测试
浏览器输入http://ip:/api/values,效果是一样的:
![ae4a052bbce469db3347503cfbe30b23.png](https://img-blog.csdnimg.cn/img_convert/ae4a052bbce469db3347503cfbe30b23.png)