服务器环境:

[root@kafka60 supervisor-3.1.]# uname -a
Linux kafka60 2.6.-.el6.x86_64 # SMP Tue May :: UTC x86_64 x86_64 x86_64 GNU/Linux

1,介绍

Supervisor是一个进程管理工具

用途就是有一个进程需要每时每刻不断的跑,但是这个进程又有可能由于各种原因有可能中断。当进程中断的时候我希望能自动重新启动它,此时,我就需要使用到了Supervisor

这个工具主要就两个命令:

supervisord : supervisor的服务器端部分,启动supervisor就是运行这个命令

supervisorctl:启动supervisor的命令行窗口。

2,安装

yum install python-setuptools
easy_install supervisor   

easy_install是setuptools包里带的一个命令,使用easy_install实际上是在调用setuptools来完成安装模块的工作,所以安装setuptools即可。

在setup.py中规定meld3的版本要求

#如果执行完easy_install supervisor出现下面的meld3版本问题

Installing supervisord script to /usr/bin

Installed /usr/lib/python2./site-packages/supervisor-3.1.-py2..egg
Processing dependencies for supervisor==3.1.
Searching for meld3>=0.6.
Reading http://pypi.python.org/simple/meld3/
Couldn't find index page for 'meld3' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for meld3>=0.6.
error: Could not find suitable distribution for Requirement.parse('meld3>=0.6.5')

请参考下面解决方法:

 第一种方法:
可以修改requires.txt文件,注释掉这个meld3的版本要求,修改如下:
[online@kermit supervisor-3.3.]$ locate requires.txt
/opt/modules/download/supervisor-3.3./supervisor.egg-info/requires.txt
/usr/lib/python2./site-packages/supervisor-3.3.-py2..egg/EGG-INFO/requires.txt #然后编辑此文件:/usr/lib/python2./site-packages/supervisor-3.3.-py2..egg/EGG-INFO/requires.txt,将meld3 >= 0.6.5本行注释掉.
#meld3 >= 0.6.
[iterparse]
cElementTree >= 1.0. 第二种方法:
#下载meld
wget https://pypi.python.org/packages/45/a0/317c6422b26c12fe0161e936fc35f36552069ba8e6f7ecbd99bbffe32a5f/meld3-1.0.2.tar.gz#md5=3ccc78cd79cffd63a751ad7684c02c91
tar zxvf meld3-1.0..tar.gz
cd meld3-1.0.
python setup.py install

3,测试

#测试是否安装成功
echo_supervisord_conf

输出如下:

  ; Sample supervisor config file.

   [unix_http_server]
file=/var/run/supervisor/supervisor.sock ; socket 路径 ;chmod= ; socket 文件的权限
;chown=nobody:nogroup ; socket 所属用户及组
;username=user ; 用户名
;password= ; 密码 ;[inet_http_server] ; 是否启用服务,默认是关闭的(启用的话可以看到supervisor 管理的服务状态)
;port=127.0.0.1: ; 监听的IP及端口
;username=user ; 用户名
;password= ; 密码 [supervisord] ; supervisord 全局配置
logfile=/var/log/supervisor/supervisord.log ; supervisor 日志路径
logfile_maxbytes=50MB ; 单个日志文件最大数
logfile_backups= ; 保留多少个日志文件(默认10个)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; pid 文件路径
nodaemon=false ; 启动是否丢到前台,设置为false ,表示以daemon 的方式启动
minfds= ; 最小文件打开数,对应系统limit.conf 中的nofile ,默认最小为1024,最大为4096
minprocs= ; 最小的进程打开数,对应系统的limit.conf 中的nproc,默认为200
;umask= ; (process file creation umask;default )
;user=chrism ; 启动supervisord 服务的用户,默认为root
;identifier=supervisor ; (supervisord identifier, default is 'supervisor')
;directory=/tmp ; 这里的目录指的是服务的工作目录
;nocleanup=true ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp ; ('AUTO' child log dir, default $TEMP)
;environment=KEY=value ; (key value pairs to add to environment)
;strip_ansi=false ; (strip ansi escape codes in logs; def. false) ; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl]
serverurl=unix:///var/run/supervisor/supervisor.sock ; use a unix:// URL for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris ; should be same as http_username if set
;password= ; should be same as http_password if set
;prompt=mysupervisor ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history ; use readline history if available ; The below sample program section shows all possible program subsection values,
; create one or more 'real' program: sections to be able to control them under
; supervisor. ;[program:theprogramname] ; 定义一个守护进程 ,比如下面的elasticsearch
;command=/bin/cat ; 启动程序使用的命令,可以是绝对路径或者相对路径
;process_name=%(program_name)s ; 一个python字符串表达式,用来表示supervisor进程启动的这个的名称,默认值是%(program_name)s
;numprocs= ; Supervisor启动这个程序的多个实例,如果numprocs>,则process_name的表达式必须包含%(process_num)s,默认是1
;directory=/tmp ; supervisord在生成子进程的时候会切换到该目录
;umask= ; umask for process (default None)
;priority= ; 权重,可以控制程序启动和关闭时的顺序,权重越低:越早启动,越晚关闭。默认值是999
;autostart=true ; 如果设置为true,当supervisord启动的时候,进程会自动启动
;autorestart=true ; 设置为随 supervisord 重启而重启,值可以是false、true、unexpected。false:进程不会自动重启
;startsecs= ; 程序启动后等待多长时间后才认为程序启动成功,默认是10秒
;startretries= ; supervisord尝试启动一个程序时尝试的次数。默认是3
;exitcodes=, ; 一个预期的退出返回码,默认是0,。
;stopsignal=QUIT ; 当收到stop请求的时候,发送信号给程序,默认是TERM信号,也可以是 HUP, INT, QUIT, KILL, USR1, or USR2
;stopwaitsecs= ; 在操作系统给supervisord发送SIGCHILD信号时等待的时间
;user=chrism ; 如果supervisord以root运行,则会使用这个设置用户启动子程序
;redirect_stderr=true ; 如果设置为true,进程则会把标准错误输出到supervisord后台的标准输出文件描述符
;stdout_logfile=/a/path ; 把进程的标准输出写入文件中,如果stdout_logfile没有设置或者设置为AUTO,则supervisor会自动选择一个文件位置
;stdout_logfile_maxbytes=1MB ; 标准输出log文件达到多少后自动进行轮转,单位是KB、MB、GB。如果设置为0则表示不限制日志文件大小
;stdout_logfile_backups= ; 标准输出日志轮转备份的数量,默认是10,如果设置为0,则不备份
;stdout_capture_maxbytes=1MB ; 当进程处于stderr capture mode模式的时候,写入FIFO队列的最大bytes值,单位可以是KB、MB、GB
;stdout_events_enabled=false ; 如果设置为true,当进程在写它的stderr
;stderr_logfile=/a/path ; 把进程的错误日志输出一个文件中,除非redirect_stderr参数被设置为true
;stderr_logfile_maxbytes=1MB ; 错误log文件达到多少后自动进行轮转,单位是KB、MB、GB。如果设置为0则表示不限制日志文件大小
;stderr_logfile_backups= ; 错误日志轮转备份的数量,默认是10,如果设置为0,则不备份
;stderr_capture_maxbytes=1MB ; 当进程处于stderr capture mode模式的时候,写入FIFO队列的最大bytes值,单位可以是KB、MB、GB
;stderr_events_enabled=false ; 如果设置为true,当进程在写它的stderr到文件描述符的时候,PROCESS_LOG_STDERR事件会被触发
;environment=A=,B= ; 一个k/v对的list列表
;serverurl=AUTO ; 是否允许子进程和内部的HTTP服务通讯,如果设置为AUTO,supervisor会自动的构造一个url ; The below sample eventlistener section shows all possible
; eventlistener subsection values, create one or more 'real'
; eventlistener: sections to be able to handle event notifications
; sent by supervisor.
#这个地方是自定义一个守护进程
[program:elasticsearch] ; 定义一个守护进程 elasticsearch
environment=ES_HOME=/usr/local/elasticsearch ; 设置ES_HOME 环境变量
user=elk ; 启动elasticsearch 的用户
directory=/usr/local/elasticsearch ; 进入到这个目录中
command=/usr/local/elasticsearch/bin/elasticsearch ; 执行启动命令
numprocs= ; Supervisor启动这个程序的多个实例,如果numprocs>,则process_name的表达式必须包含%(process_num)s,默认是1
autostart=true ; 设置为随 supervisord 启动而启动
autorestart=true ; 设置为随 supervisord 重启而重启
startretries= ; 设置elasticsearch 重启的重试次数
priority= ; 权重,可以控制程序启动和关闭时的顺序,权重越低:越早启动,越晚关闭。默认值是999 ;[eventlistener:theeventlistenername]
;command=/bin/eventlistener ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs= ; number of processes copies to start (def )
;events=EVENT ; event notif. types to subscribe to (req'd)
;buffer_size= ; event buffer queue size (default )
;directory=/tmp ; directory to cwd to before exec (def no cwd)
;umask= ; umask for process (default None)
;priority=- ; the relative start priority (default -)
;autostart=true ; start at supervisord start (default: true)
;autorestart=unexpected ; restart at unexpected quit (default: unexpected)
;startsecs= ; number of secs prog must stay running (def. )
;startretries= ; max # of serial start failures (default )
;exitcodes=, ; 'expected' exit codes for process (default ,)
;stopsignal=QUIT ; signal used to kill process (default TERM)
;stopwaitsecs= ; max num secs to wait b4 SIGKILL (default )
;user=chrism ; setuid to this UNIX account to run the program
;redirect_stderr=true ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups= ; # of stdout logfile backups (default )
;stdout_events_enabled=false ; emit events on stdout writes (default false)
;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups ; # of stderr logfile backups (default )
;stderr_events_enabled=false ; emit events on stderr writes (default false)
;environment=A=,B= ; process environment additions
;serverurl=AUTO ; override serverurl computation (childutils) ; The below sample group section shows all possible group values,
; create one or more 'real' group: sections to create "heterogeneous"
; process groups. ;[group:thegroupname] ; 服务组管理,可以将多个服务名写到这里管理(组名自定义)
;programs=progname1,progname2 ; 上面配置好的服务名,比如elasticsearch,kibana,logstash
;priority= ; the relative start priority (default ) ; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves. [include]
files = supervisord.d/*.ini

注:分号(;)开头的配置表示注释

#创建配置文件
echo_supervisord_conf > /etc/supervisord.conf       ##这个配置文件默认是不存在的,需要自己导入,运行echo_supervisord_conf打印出一个配置文件的样本

4,启动

确定supervisord 服务并设置为随机启动:

通过easy_install 安装的supervisor运行supervisord 运行:

supervisord 

或者加载的时候需要,supervisord -c /etc/supervisord.conf这样就可以了。

5.web界面操作

需要在supervisor的配置文件里添加[inet_http_server]选项组:之后可以通过http://10.0.0.80:9001来访问控制子线程的管理。

编辑 vim  /etc/supervisord.conf
约18-21行
[inet_http_server] ; inet (TCP) server disabled by default
port=10.0.0.80: ; (ip_address:port specifier, *:port for all iface)
username=user ; (default is no username (open server))
password= ; (default is no password (open server))

修改完配置后,重启supervisor

[root@kafka60 supervisor-3.1.]# supervisorctl reload
Restarted supervisord

登录浏览器效果:

supervisor安装篇的更多相关文章

  1. k8s入门系列之扩展组件(一)DNS安装篇

    DNS (domain name system),提供域名解析服务,解决了难于记忆的IP地址问题,以更人性可读可记忆可标识的方式映射对应IP地址. Cluster DNS扩展插件用于支持k8s集群系统 ...

  2. supervisor安装和配置

    直接命令 easy_install supervisor 如果报错先安装 yum install python-setuptools,再上面一条命令: 安装成功后显示finished,我们再次进行py ...

  3. Linux负载均衡软件LVS之二(安装篇)[转]

    Linux负载均衡软件LVS之二(安装篇) 2011-04-26 16:01:47 标签:lvs安装配置 linux lvs 休闲 linux高可用 原创作品,允许转载,转载时请务必以超链接形式标明文 ...

  4. 开源文档管理系统LogicalDOC测试报告---安装篇

    开源文档管理系统LogicalDOC测试报告---安装篇 分类: Linux2011-06-22 15:40 7436人阅读 评论(3) 收藏 举报 文档管理测试mysql数据库installerja ...

  5. MongoDB安装篇-Win7 X64

    介绍 MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库 ...

  6. Supervisor 安装及配置管理uwsgi进程

    Supervisor介绍 Supervisor 允许其用户在UNIX类操作系统上控制多个进程. 块如下: 方便 需要为每个进程实例编写rc.d脚本通常是不方便的. rc.d脚本是进程初始化/自动启动/ ...

  7. Flow简易教程——安装篇

    .mydoc_h1{ margin: 0 0 1em; } .mydoc_h1_a{ color: #2c3e50; text-decoration: none; font-size: 2em; } ...

  8. Ubuntu 16.04 RabbitMq 安装与运行(安装篇)

    Ubuntu 16.04 RabbitMq 安装与运行(安装篇) 2018年08月15日 15:05:24 我跟吴彦祖四六开 阅读数:1966   前言 目前公司用阿里云 + redis 的方式实现的 ...

  9. mac下supervisor安装及简单配置

    supervisor是一个用 Python 写的进程管理工具,可以很方便的用来启动.重启.关闭进程(守护进程).可以用他来管理自己的“服务程序”. 安装 首先安装Python,Mac系统好像自带. 执 ...

随机推荐

  1. flume-kafka-storm日志处理经验

    转自:http://www.aboutyun.com/thread-9216-1-1.html 使用Storm处理事务型实时计算需求时的几处难点: http://blog.sina.com.cn/s/ ...

  2. html测试代码框工具

    Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --& ...

  3. selenium测试(Java)-- 验证信息(八)

    package com.test.validationinfor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.f ...

  4. 【Android实战】Android中处理崩溃异常

    public class MainActivity extends ActionBarActivity { public CrashApplication application; @Override ...

  5. par函数的bg参数-控制图片的背景色

    bg 参数用于控制图片的背景色,默认为白色 代码示例: par(bg = "pink") plot(1:5, 1:5, main = "title", xlab ...

  6. 利用kseq.h parse fasta/fastq 文件

    在分析中经常需要统计fasta/fastq文件的序列数和碱基数, 但是没有找到一些专门做这件事的小工具,可能是这个功能太简单了: 之前用自己写的perl的脚本统计这些信息, 当fastq文件非常大时, ...

  7. 微软ASP.NET网站部署指南(2):部署SQL Server Compact数据库

    1. 综述 对于数据库訪问,Contoso University程序要求以下的软件必须随程序一起部署.由于不属于.NET Framework: SQL Server Compact (数据库引擎) A ...

  8. hadoop基础学习---基本概念

    1.组成部分HDFS和MapReduce 2.HDFS这几架构

  9. linux ,cron定时任务 备份mysql数据库

    cron 定时任务执行备份脚本文件 backup.sh #!/bin/bash USER="root" PASSWORD="xxxxx" DATABASE=&q ...

  10. 使用 MVVMLight 绑定数据

    如果你还不知道如何在VS中加入MVVMLight的引用,那么建议你先翻阅这篇文章:在VS中安装/使用 MVVMLight 这篇文章主要是介绍如何使用MVVMLight来绑定数据到界面中(View),以 ...