共计 2906 个字符,预计需要花费 8 分钟才能阅读完成。
Linux 进程监控服务 Supervisor 快速入门
官网地址:http://www.supervisord.org/
准备
1、系统中需安装 Python 环境,我本机 python 为 2.6.6
2、下载安装 supervisor 所需软件
elementtree
meld3
setuptools
supervisor
安装
以上四个都为 python 相关插件,分别解压后,进入各自所在目录中,使用 python setup.py install
命令安装,其安装顺序依次为:
elementtree、meld3、setuptools、supervisor
⚠️在安装 setuptools 时需要先执行 python bootstrap.py
,然后执行python setup.py install
命令安装
添加配置文件
配置文件 /etc/supervisord.conf
配置内容如下:
[unix_http_server] | |
file = /var/run/supervisor.sock | |
chmod = 0777 | |
chown= root:root | |
[inet_http_server] | |
# Web 管理界面设定 | |
port=node03:9001 | |
;username = admin | |
;password = yourpassword | |
[supervisorctl] | |
; 必须和 'unix_http_server' 里面的设定匹配 | |
serverurl = unix:///var/run/supervisor.sock | |
[supervisord] | |
logfile=/var/log/supervisord/supervisord.log ; (main log file;default $CWD/supervisord.log) | |
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB) | |
logfile_backups=10 ; (num of main logfile rotation backups;default 10) | |
loglevel=info ; (log level;default info; others: debug,warn,trace) | |
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) | |
nodaemon=false ; (start in foreground if true;default false) | |
minfds=1024 ; (min. avail startup file descriptors;default 1024) | |
minprocs=200 ; (min. avail process descriptors;default 200) | |
user=root ; (default is current user, required if root) | |
childlogdir=/var/log/supervisord/ ; ('AUTO' child log dir, default $TEMP) | |
[rpcinterface:supervisor] | |
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface | |
; 管理的单个进程的配置,可以添加多个 program | |
[program:cat] | |
command=/bin/cat | |
autostart = true | |
startsecs = 5 | |
user = root | |
redirect_stderr = true | |
; 对这个 program 的 log 的配置,上面的 logfile_maxbytes 是 supervisord 本身的 log 配置 | |
stdout_logfile_maxbytes = 20MB | |
stdoiut_logfile_backups = 20 | |
stdout_logfile = /var/log/supervisord/cat.log |
启动服务
方式一:
# supervisord
方式二:
# supervisord -c /path/to/supervisord.conf
方式一启动时会自己寻找 /etc/supervisord.conf
文件;方式二通过 -c
参数指定配置文件所在路径
启动后可以通过 Web 界面查看服务运行情况,服务地址为:node1:9001
管理服务
使用 supervisorctl
命令进行服务管理操作:
[root@node1 zxm]# supervisorctl | |
chatdemon RUNNING pid 47457, uptime 0:07:38 | |
test RUNNING pid 47456, uptime 0:07:38 | |
supervisor> help | |
default commands (type help <topic>): | |
===================================== | |
add exit open reload restart start tail | |
avail fg pid remove shutdown status update | |
clear maintail quit reread signal stop version | |
supervisor> status | |
cat RUNNING pid 47555, uptime 0:00:08 | |
chatdemon RUNNING pid 47554, uptime 0:00:08 | |
test RUNNING pid 47553, uptime 0:00:08 |
[include]标签
可以使用 [include] 标签来指定应用程序配置文件,例如:
[zxm@node1 supervise-programs]# cat /etc/supervisord.conf | |
... ... | |
[include] | |
files= /home/zxm/works/supervise-programs/cat.conf |
/home/zxm/works/supervise-programs/cat.conf
内容如下:
[zxm@node1 supervise-programs]# cat cat.conf | |
[program:cat] | |
command=/bin/cat | |
autostart = true | |
startsecs = 5 | |
user = root | |
redirect_stderr = true | |
; 对这个 program 的 log 的配置,上面的 logfile_maxbytes 是 supervisord 本身的 log 配置 | |
stdout_logfile_maxbytes = 20MB | |
stdoiut_logfile_backups = 20 | |
stdout_logfile = /var/log/supervisord/cat.log |
supervisor 安装配置与使用 http://www.linuxidc.com/Linux/2015-04/116701.htm
CentOS7 下 Supervisor 安装与配置(Linux/Unix 进程管理工具)http://www.linuxidc.com/Linux/2017-02/140417.htm
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-03/141405.htm
