Supervisor是由python语言编写,基于linux操作系统的一款服务器管理工具,
用以监控服务器的运行,发现问题能立即自动预警及自动重启等功能。
Supervisor类似于monit,
monit和supervisor的一个比较大的差异是supervisor管理的进程必须由supervisor来启动,
monit可以管理已经在运行的程序;
supervisor还要求管理的程序是非daemon程序,supervisord会帮你把它转成daemon程序,
因此如果用supervisor来管理nginx的话,必须在nginx的配置文件里添加一行设置daemon off让nginx以非daemon方式启动。
一、Supervisor的组成
1. supervisord
The server piece of supervisor is named supervisord.
It is responsible for starting child programs at its own invocation,
responding to commands from clients, restarting crashed or exited subprocesseses,
logging its subprocess stdout and stderr output, and generating and handling “events”
corresponding to points in subprocess lifetimes.
The server process uses a configuration file. This is typically located in /etc/supervisord.conf.
This configuration file is an “Windows-INI” style config file.
It is important to keep this file secure via proper filesystem permissions
because it may contain unencrypted usernames and passwords.
2. supervisorctl
The command-line client piece of the supervisor is named supervisorctl.
It provides a shell-like interface to the features provided by supervisord. From supervisorctl,
a user can connect to different supervisord processes, get status on the subprocesses controlled by,
stop and start subprocesses of, and get lists of running processes of a supervisord.
The command-line client talks to the server across a UNIX domain socket or an internet (TCP) socket.
The server can assert that the user of a client should present authentication credentials before it allows him to perform commands.
The client process typically uses the same configuration file as the server but any configuration file with a [supervisorctl]
section in it will work.
3. Web Server
A (sparse) web user interface with functionality comparable to supervisorctl may be accessed via a browser
if you start supervisord against an internet socket.
Visit the server URL (e.g. http://localhost:9001/) to view and control process status through
the web interface after activating the configuration file’s [inet_http_server] section.
4. XML-RPC Interface
The same HTTP server which serves the web UI serves up an XML-RPC interface that can be used to interrogate
and control supervisor and the programs it runs. See XML-RPC API Documentation.
Platform Requirements
二、Supervisor安装
首先必须安装好python环境,linux自带python,但建议安装2.7.0以上的版本。
Supervisor可以通过
$ sudo easy_install supervisor
安装。安装成功后显示finished, 可以再次进入python环境,
输入"import supervisor", 如果没有提示错误,则表示安装成功。
当然也可以通过Supervisor官网下载后setup.py install安装。
出现错误提示:
Installed /usr/local/python2.7.3/lib/python2.7/site-packages/supervisor-4.0.0_dev-py2.7.egg
Processing dependencies for supervisor==4.0.0-dev
Searching for meld3>=1.0.0
Reading https://pypi.python.org/simple/meld3/
Download error on https://pypi.python.org/simple/meld3/: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed -- Some packages may not be found!
Couldn't find index page for 'meld3' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed -- Some packages may not be found!
No local packages or download links found for meld3>=1.0.0
error: Could not find suitable distribution for Requirement.parse('meld3>=1.0.0')
解决办法:
上网查询了问题原因: 是curl的证书太老了需要下载最新的证书:
下载最新的证书文件 、
$ wget http://curl.haxx.se/ca/cacert.pem
更名为ca-bundle.crt放置到默认目录
$ mv cacert.pem ca-bundle.crt
$ mv ca-bundle.crt /etc/pki/tls/certs
下载并安装好证书后, 还是出现上述的问题,
根据证书过期联想到时间, 输入date命令查看时间, 原来是时间太小了,
用date -s 修改时间后,就可以正常的easy_install了。
三、Supervisor配置
接下来是对supervisor配置,首先要生成配置文件,在shell终端输入:
$ echo_supervisord_conf > /etc/supervisord.conf
可以通过文本编辑器修改这个文件,
$ vim /etc/supervisord.conf
下面是一个示例的配置文件:
;/etc/supervisord.conf
[unix_http_server]
file = /var/run/supervisor.sock
chmod = 0777
chown= root:root
[inet_http_server]
# Web管理界面设定
port=9001
;username = admin
;password = yourpassword
[supervisorctl]
; 必须和'unix_http_server'里面的设定匹配
serverurl = unix:///var/run/supervisord.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=true ; (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:chatdemon]
command=python /home/felinx/demos/chat/chatdemo.py
autostart = true
startsecs = 5
user = felinx
redirect_stderr = true
; 对这个program的log的配置,上面的logfile_maxbytes是supervisord本身的log配置
stdout_logfile_maxbytes = 20MB
stdoiut_logfile_backups = 20
stdout_logfile = /var/log/supervisord/chatdemo.log
[program:app]
command=python app.py --port=61000
directory=/opt/test/supervisor ; 先进入到这个目录,再执行command, 对于程序环境要在当前目录的程序很有用
autostart=true ; start at supervisord start (default: true)
autorestart=unexpected ; whether/when to restart (default: unexpected)
startsecs=1 ; number of secs prog must stay running (def. 1)
user=root
; 配置一组进程,对于类似的program可以通过这种方式添加,避免手工一个个添加
[program:groupworker]
command=python /home/felinx/demos/groupworker/worker.py
numprocs=24
process_name=%(program_name)s_%(process_num)02d
autostart = true
startsecs = 5
user = felinx
redirect_stderr = true
stdout_logfile = /var/log/supervisord/groupworker.log
;(更多配置说明请参考:http://supervisord.org/configuration.html)
编辑完成后保存退出.
使用命令启动supervisor:
$ supervisord
$ supervisorctl
用ps命令查看运行情况,应用现在已经自动运行了。
四、Supervisord管理
Supervisord安装完成后有两个可用的命令行supervisord和supervisorctl,
命令使用解释如下:
? supervisord, 初始启动Supervisord,启动、管理配置中设置的进程。
? supervisorctl stop programxxx, 停止某一个进程(programxxx),programxxx为[program:chatdemon]里配置的值,这个示例就是chatdemon。
? supervisorctl start programxxx, 启动某个进程
? supervisorctl restart programxxx,重启某个进程
? supervisorctl stop groupworker: ,重启所有属于名为groupworker这个分组的进程(start,restart同理)
? supervisorctl stop all, 停止全部进程,注:start、restart、stop都不会载入最新的配置文件。
? supervisorctl reload, 载入最新的配置文件,停止原有进程并按新的配置启动、管理所有进程。
? supervisorctl update, 根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启。
注意:显示用stop停止掉的进程,用reload或者update都不会自动重启。
五、页面管理
supervisor自带有Web Server, 可以通过页面来管理进程,
前提是开启配置文件中的[inet_http_server]项。
如果服务器是单网卡,可以修改如下:
[inet_http_server] ; inet (TCP) server disabled by default
port=127.0.0.1:51000 ; (ip_address:port specifier, *:port for all iface)
;username=user ; (default is no username (open server))
;password=123 ; (default is no password (open server))
如果是多网卡,则需要指定一张网卡:
[inet_http_server] ; inet (TCP) server disabled by default
port=192.168.2.13:51000 ; (ip_address:port specifier, *:port for all iface)
;username=user ; (default is no username (open server))
;password=123 ; (default is no password (open server))
在浏览器地址栏中输入:
http://192.168.2.13:51000
就可以进行页面化的管理了。
转自:http://blog.chinaunix.net/uid-26000296-id-4759916.html
相关推荐
RPC调用服务器上的supervisord系统,以达到管理服务的目的
supervisord配置,用于守护服务进程,以及数据库进程,防止进程奔溃
python脚本supervisord是很多人用来管理进程的强大工具
开源项目-ochinchina-supervisord.zip,Go中的主管实施
可供初学者在学习过程中参考。少走几次度娘就能配置好supervisor
supervisor是一个用 Python 写的进程管理工具,可以很方便的用来在 UNIX-like 系统(不支持 Windows)下启动、重启(自动重启程序)、关闭进程(不仅仅是 Python 进程)。 语法格式: supervisord [参数] 常用参数...
# superdash 用于通过 supervisord 管理多个服务器的仪表板
适合基于ssh秘钥的中小公司环境, 代码逻辑简单, 需要运维兄弟会一点python, 自定义与公司业务相关的功能,自行发挥.
vps,用nginx+tornado+supervisord+python部署多站点网站, 主要:nginx做反向代理服务器,负载均衡,torndao做后端服务器 用supervisor管理多进程
Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor...
本文实例讲述了Python使用Supervisor来管理进程的方法。分享给大家供大家参考。具体分析如下: Supervisor可以启动、停止、重启*nix系统中的程序。也可以重启崩溃的程序。 supervisord的一个守护进程,用于将指定的...
Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor...
Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启。目前Supervisor可以运行在大多数Unix系统上,但不支持在Windows系统上运行。...
Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台...supervisor还提供了一个功能,可以为supervisord或者每个子进程,设置一个非root的user,这个user就可以管理它对应的进程。
对于Docker容器基本映像使用supervisord管理服务。 用法 该映像不包含任何服务,因为它被认为是其他容器的基础映像。 要在Dockerfile使用它,只需使用: FROM odarriba/supervisord:latest 然后,您可以通过在/...
Supervisor 是一个用 Python 实现的进程管理工具,可以很方便地启动,关闭,重启,查看,以及监控进程,当进程由于某种原因崩溃或者被误杀后,可以自动重启并发送事件通知。Supervisor 可谓运维利器,使用 ...
这个 Dockerfile 将构建一个 Ubuntu 14.04.1 容器,带有 Nginx 和 HHVM,在 supervisord 下运行。 安装 将此存储库克隆到安装了 Docker 的机器上。 运行docker build -t nginx-hhvm:base . 在那个文件夹中。 用法 ...
安装包(含):supervisor-3.4.0.tar.gz, 依赖包(含):meld3-2.0.0-py2.py3-none-any.whl、pip-19.3.1.tar.gz、setuptools-40.7.3-py2.py3-none-any.whl 依赖环境(亲测):RedHat7.* ,python2.7
$s = new Supervisord('127.0.0.1', 9001, 'username', 'password'); print_r( $s->getAllProcessInfo() ); 如何贡献 拉取请求 分叉存储库 为每个功能或改进创建一个新分支 从每个功能分支向开发分支发送拉取请求 将...
同步方案:采用inotify监听文件变化,触发rsync实时同步,并且用supervisor监控inotify进程,莫明死掉后会立即重新启动。 需求:adminweb上的/data/www/user下的代码要同步到web1\2\3上 172.40.0.203:web1 172.40.0...