Centos7.x 安装 Supervisord
【环境】
系统:Centos 7.3
软件:supervisord
【安装Supervisord】
yum install epel-release yum install -y supervisor
【设置开启自启】
systemctl enable supervisord
【Supervisord管理命令】
systemctl stop supervisord
systemctl start supervisord
systemctl status supervisord
systemctl reload supervisord
systemctl restart supervisord
【修改配置文件,使Supervisord可以在web端显示】
vim /etc/supervisord.conf
#取消10-13行注释,前面数字是行号 10 [inet_http_server] ; inet (TCP) server disabled by default 11 port=127.0.0.1:9001 ; (ip_address:port specifier, *:port for all iface) 12 username=user ; (default is no username (open server)) 13 password=123 ; (default is no password (open server))
【监控】
然后设置监控文件以及脚本等
比如我们创建一个死循环,让脚本来监控,这里拿python来说吧
在home目录下创建一个while循环的py文件
vim /home/test.py
while True: print(100)
这个文件一直打印100,如果不强制终止,则不会停止,接下来配置supervisord。我们可以通过配置文件最后一行看到
cat /etc/supervisord.conf
[include] files = supervisord.d/*.ini
也就是说,我们所有的配置文件都保存在这个目录下,以.ini格式命名保存的,可以自行修改地址,但不要修改后缀,那我们来创建supervisor文件吧
【创建Supervisord文件】
vim /etc/supervisord.d/python.ini
[program:python] #这里的python就是我们显示在web前端以及终端的监控名称 command=python /home/test.py #我们要监控的文件地址 autostart=true autorestart=true startsecs=1 startretries=3 redirect_stderr=true stdout_logfile=/etc/supervisord.log/access_python.log #日志地址,可自行配置目录 stderr_logfile=/etc/supervisord.log/error_python.log #日志地址,可自行配置目录
【启动Supervisord】
systemctl start supervisord
查看是否启动
systemctl status supervisord
注:如果启动成功后无法登陆web端,则允许9001端口通过防火墙或者关闭防火墙,关闭selinux,把supervisord.conf中的port=127.0.0.1:9001中的127.0.0.1修改成IP地址重启服务进行访问
【Web端登陆】
【登陆成功】
登陆之后,会出现如下界面,可以对该文件进行一些操作,打开、停止、查看日志、清除日志
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?