Supervisor的安装部署(Centos7)

Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor管理的进程,当一个进程意外被杀死,supervisort监听到进程死后,会自动将它重新拉起,很方便的做到进程自动恢复的功能,不再需要自己写shell脚本来控制。

因为Supervisor是Python开发的,注意 supervidor 依赖python2.4-2.7 python3下 使用pip无法安装 使用python3 pip安装会报错 。
下面以CentOS7,Python2.7版本环境下,介绍Supervisor的安装与配置步聚:

一、安装选择

supervisor为python编写,可以选择pip安装,也可以用linux的包管理工具安装,本文采用pip方式安装。

pip install supervisor
#一条命令即可安装完毕!

二、相关命令

supervisord
启动supervisor服务端

supervisorctl
与服务端交互

ps aux|grep supervisord
查看进程

service supervisor start
启动supervisor服务

service supervisor stop
停止supervisor服务

supervisorctl shutdown
关闭所有任务

supervisorctl stop|start program_name
启动/停止任务

supervisorctl status
查看任务状态

三、配置文件
supervisor安装成功之后,没有提供默认的配置文件,我们手动生成配置文件

echo_supervisord_conf>/etc/supervisord.conf
查看配置文件

修改[unix_http_server]
取消[inet_http_server]。。。和port。。。两行前的注释

修改[supervisorctl]
取消serververurl = http://ip前的注释

给前一行加注释

修改[include]
添加包含的配置文件路径

files = conf.d/*.conf

四、配置supervisord开机启动
创建文件supervisord.service

vim /usr/lib/systemd/system/supervisor.service
文件内容:

[Unit]
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-failing
ResstartSec=42s

[Install]
WantedBy=multi-user.target

启动系统service

systemctl enable supervisord
五、问题
基本都是出现在配置文件

配置文件启动时,报错unlink stale 。。。。

unlink /tmp/supervisor.sock 或
unlink /var/run/supervisor.sock
可解决

作者:阁中悟剑
链接:https://www.jianshu.com/p/e2b98733da0b
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

猜你喜欢

转载自blog.51cto.com/qiangsh/2153185
今日推荐