linux进程管理工具supervisor部署配置

Supervisor是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。它可以很方便的监听、启动、停止、重启一个或多个进程。

因为supervisor依赖python,所以确保我们环境中装有python,接下来我看下这个工具的部署配置和使用方法

首先我们需要安装python和pip工具,我们本地操作系统是centos7

yum install -y python3 python3-pip

接着使用python的pip管理工具进行安装

pip3 install supervisor

接着生成supervisor默认配置文件

echo_supervisord_conf > /etc/supervisord.conf

接着我们就需要编辑这个配置文件了,这个文件内容又臭又长,我们不需要全部看一遍,直接修改我们需要的地方就行

找到[inet_http_server]这段,如果需要用页面来管理的话可以把这一段的注释打开

[inet_http_server]         ; inet (TCP) server disabled by default
port=0.0.0.0:9001          ; ip_address:port specifier, *:port for all iface
username=admin             ; default is no username (open server)
password=admin             ; default is no password (open server)

打开以后我们可以先启动看看效果

supervisord -c /etc/supervisord.conf

然后可以通过IP+9001访问这个页面了。

微信截图_20240131145505.png

supervisorctl常用命令如下
supervisorctl shutdown # 关闭supervisord
supervisorctl reload # 重新载入配置
supervisorctl update # 更新

管理supervisor的服务的常用命令如下

supervisorctl start [all|service_name] #启动所有/某个服务
supervisorctl stop [all|service_name] #停止所有/某个服务
supervisorctl status [|service_name] #查看所有/某个服务状态
supervisorctl restart [all|service_name] #重启所有/某个服务

刚才介绍完一些命令,接着我们再看如何将supervisor配置为系统服务

cat >/usr/lib/systemd/system/supervisord.service<<EOF
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/local/bin/supervisord -c /etc/supervisord.conf
ExecStop=/usr/local/bin/supervisorctl shutdown
ExecReload=/usr/local/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
EOF

配置supervisor开机启动,并启动该服务

systemctl enable supervisord
systemctl start supervisord
#如果需要停止可以使用以下命令
systemctl stop supervisord

后面有空,我们再学习下使用supervior配置来管理程序。


内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://sulao.cn/post/971.html

我要评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。