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

前言
supervisor管理的进程必须由supervisor来启动
supervisor还要求管理的程序是非daemon程序,supervisord会帮你把它转成daemon程序,因此如果用supervisor来管理nginx的话,必须在nginx的配置文件里添加一行设置daemon off让nginx以非daemon方式启动。
supervisor工具包括4个组成部分:supervisord,supervisorctl,Web Server,XML-RPC Interface。

supervisord
它负责在自己的调用启动子程序,响应客户端的命令,重新启动崩溃或退出的子进程,记录其子进程stdout和stderr输出

supervisorctl
supervisord的命令行客户端,是一个shell界面,可以操作supervisord提供的操作功能。从supervisorctl,用户可以连接到不同的supervisord进程,获得每个子进程的状态,以及停止和启动子进程。
它通过UNIX socker或TCP socket和服务端进行连接。

Web Server
在浏览器中执行supervisorctl的各种操作

XML-RPC Interface
和HTTP服务相似,这是提供了一个XML-RPC接口。你可以通过该接口去执行supervisorctl的操作。

其中最重要的是supervisord和supervisorctl。

操作如下:

1、  安装Supervisor

执行以下命令:

yum install python-setuptools
easy_install supervisor

或者

如果easy_install不好使就从官方下载:
wget https://pypi.python.org/packages/80/37/964c0d53cbd328796b1aeb7abea4c0f7b0e8c7197ea9b0b9967b7d004def/supervisor-3.3.1.tar.gz
然后通过python安装:
tar zxf supervisor-3.3.1.tar.gz
cd supervisor
python setup.py install

 

2、 配置Supervisor

a.创建文件夹和配置文件

mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf

b.修改/etc/supervisor/supervisord.conf文件内容

; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Note: shell expansion ("~" or "$HOME") is not supported. Environment
; variables can be expanded using this syntax: "%(ENV_HOME)s". [unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
;chmod= ; socket file mode (default )
;chown=nobody:nogroup ; socket file uid:gid owner
;username=user ; (default is no username (open server))
;password= ; (default is no password (open server)) ;[inet_http_server] ; inet (TCP) server disabled by default
;port=127.0.0.1: ; (ip_address:port specifier, *:port for all iface)
;username=user ; (default is no username (open server))
;password= ; (default is no password (open server)) [supervisord]
logfile=/var/log/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups= ; (num of main logfile rotation backups;default )
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= ; (min. avail startup file descriptors;default )
minprocs= ; (min. avail process descriptors;default )
;umask= ; (process file creation umask;default )
;user=chrism ; (default is current user, required if root)
;user=root ; (default is current user, required if root)
;password=rootpasswd ; (default is no password (open server))
;identifier=supervisor ; (supervisord identifier, default is 'supervisor')
;directory=/tmp ; (default is not to cd during start)
;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.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]
;command=/bin/cat ; 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 )
;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 ; whether/when to restart (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 )
;stopasgroup=false ; send stop signal to the UNIX process group (default false)
;killasgroup=false ; SIGKILL the UNIX process group (def false)
;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_capture_maxbytes=1MB ; number of bytes in 'capturemode' (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_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default )
;stderr_events_enabled=false ; emit events on stderr writes (default false)
;environment=A=,B= ; process environment additions (def no adds)
;serverurl=AUTO ; override serverurl computation (childutils) ; 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. ;[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 ; whether/when to restart (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 )
;stopasgroup=false ; send stop signal to the UNIX process group (default false)
;killasgroup=false ; SIGKILL the UNIX process group (def false)
;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 ; each refers to 'x' in [program:x] definitions
;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 = conf.d/*.conf [program:printdate]
command=python testvisor.py
directory=/home
autostart=true
autorestart=true
startsecs=3
stdout_logfile=/var/log/supervisor/printdate.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10 [program:redis]
command=redis-server
autostart=true
autorestart=true
startsecs=3

3、 运行supervisord,查看是否生效,执行以下命令:

supervisord -c /etc/supervisor/supervisord.conf
ps -ef | grep ProjectName

返回

root         : ?        :: redis-server
root : pts/ :: grep --color=auto ProjectName

supervisorctl reload #载入最新的配置文件,停止原有进程,按新的配置文件启动、管理所有进程

supervisorctl update #启动新的配置文件或有改动的进程

supervisorctl status  查看状态

启动全部进程:supervisorctl start all

错误提示:

Unlinking stale socket /tmp/supervisor.sock
unlink /tmp/supervisor.sock

unix:///run/supervisor.sock no such file

重新启动就好

ERROR: [1] bootstrap checks failed
[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]

编辑 /etc/security/limits.conf

root soft nofile 65536
root hard nofile 65536
elastic soft nofile 65536
elastic hard nofile 65536

 

安装及使用supervisor的更多相关文章

  1. Ubuntu 安装和使用 Supervisor(进程管理)

    服务器版本 Ubuntu 16.04 LTS. Supervisor 是一个用 Python 写的进程管理工具,可以很方便的对进程进行启动.停止.重启等操作. 安装命令: $ apt-get inst ...

  2. Ubuntu安装守护进程supervisor

    Supervisor安装与配置(Linux/Unix进程管理工具) asp.net core 负载均衡集群搭建(centos7+nginx+supervisor+kestrel) 为了保证服务能够稳定 ...

  3. Storm 安装时 部分supervisor启动成功,并不在web ui上显示

    今天帮公司搭建集群时,发现启动了三个Supervisor 发现只有一个显示在Web UI 上. 于是我就简单地检查了下另外两台没有启动的 storm supervisor的日志, 发现没有报出什么异常 ...

  4. supervisor 安装、配置、常用命令

    前言 在 web 应用部署到线上后,需要保证应用一直处于运行状态,在遇到程序异常.报错等情况,导致 web 应用终止时,需要保证程序可以立刻重启,继续提供服务. 所以,就需要一个工具,时刻监控 web ...

  5. CentOS7 下 安装 supervisor以及使用

    CentOS7 下 安装 supervisor 以及使用 手动安装 [注] linux环境必须安装 python 1.获取supervisor包:[https://pypi.python.org/py ...

  6. supervisor安装配置与使用

    supervisor:C/S架构的进程控制系统,可使用户在类UNIX系统中监控.管理进程.常用于管理与某个用户或项目相关的进程. 组成部分supervisord:服务守护进程supervisorctl ...

  7. supervisor 安装 配置 及 使用

    supervisor是微软官方推荐的一个工具,传送门, 所以我们也使用这个工具来管理我们的asp.net core应用进程   服务器环境:ubuntu14.04 x64   安装  apt-get ...

  8. supervisor安装、使用详解

    supervisor是用python写的一个进程管理工具,用来启动,重启,关闭进程. 1 supervisor的安装 pip install supervisor 2 supervisor的配置文件( ...

  9. supervisor的安装和配置

    1. 安装 yum install supervisor 2.配置 [unix_http_server] file=/tmp/supervisor.sock ;UNIX socket 文件,super ...

随机推荐

  1. 用fritzing绘制arduino硬件连线图

    在http://fritzing.org/home/ 点击下载最新版本. 解压之后直接可以使用. 打开Fritzing.exe 在点击面包板,在搜索界面输入想要找到的原件拖拽即可放在面包板所在的图上. ...

  2. jQuery和MVVM类框架的编程区别点

    本文说的mvvm框架以react为列,其他应该也是类似的: react实际上仅仅是帮助我们再View层简化,让我们仅仅需要专注数据,只要数据改变,所有的视图就会自己跟随着改变, 本人自己做react项 ...

  3. Angular面试题三

    十六.一个 angular 应用应当如何良好地分层? 目录结构的划分 1.对于小型项目,可以按照文件类型组织,比如: css Js  {  controllers  models  services ...

  4. Java学习笔记(3)----网络套接字服务器多线程版本

    本例给出一个客户端程序和一个服务器程序.客户端向服务器发送数据.服务器接收数据,并用它来生成一个结果,然后将这个结果返回给客户端.客户端在控制台上显示结果.在本例中,客户端发送的数据是圆的半径,服务器 ...

  5. ubuntu 14.04/14.10 iptables 防火墙设置

    1. 一键批处理设置      [plain] view plaincopyprint? #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/loc ...

  6. Binary Tree Inorder/Preorder Traversal 返回中序和前序/遍历二叉树的元素集合

    给定一个二叉树,以集合方式返回其中序/先序方式遍历的所有元素. 有两种方法,一种是经典的中序/先序方式的经典递归方式,另一种可以结合栈来实现非递归 Given a binary tree, retur ...

  7. Oracle 给字符串补空格、补0

    利用lpad().RPAD()函数来实现给字符串补空格或补0的功能: 一.lpad()lpad函数将左边的字符串填充一些特定的字符其语法格式如下:lpad(string,n,[pad_string]) ...

  8. HttpStatus

    /* * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Vers ...

  9. Linux Kernel 4.11首个候选版本开放下载

    Linus Torvalds宣布了即将到来的Linux Kernel 4.11内核分支的首个候选(RC)版本,用户可下载.编译并在自己的GNU/Linux发行版本中进行测试.Linus Torvald ...

  10. C++显式隐式构造函数

    https://blog.csdn.net/starlee/article/details/1331268#comments