一、安装

  • 源码安装

先下载最新的supervisor安装包:https://pypi.python.org/pypi/supervisor , 如:

(python3命令为 pip install git+https://github.com/Supervisor/supervisor@master)

  1.  
    cd /usr/local/src
  2.  
    wget https://pypi.python.org/packages/7b/17/88adf8cb25f80e2bc0d18e094fcd7ab300632ea00b601cbbbb84c2419eae/supervisor-3.3.2.tar.gz
  3.  
    tar -zxvf supervisor-3.3.2.tar.gz
  4.  
    cd supervisor-3.3.2
  5.  
    python setup.py install #本地python版本为python2.7
  6.  
    # python2.7 setup.py install #本地python版本为python3以上

二、配置

1.生成配置文件

  1.  
    echo_supervisord_conf > /etc/supervisord.conf
  2.  
     

2.启动

supervisord -c /etc/supervisord.conf
 

查看 supervisord 是否在运行:

ps aux | grep supervisord
 

3.配置

打开配置文件

vim /etc/supervisord.conf
 

在最下边加入

[program:sougou]   #souogu 为程序的名称
command=scrapy crawl sougou #需要执行的命令
directory=/home/mzj/桌面/sougou/sougou/wechat_name/wechat_name/spiders  #命令执行的目录
environment=ASPNETCORE__ENVIRONMENT=Production #环境变量
user=root #用户
stopsignal=INT
autostart=true #是否自启动
autorestart=true #是否自动重启
startsecs=3 #自动重启时间间隔(s)
stderr_logfile=/home/mzj/桌面/sougou/sougou/wechat_name/wechat_name/spiders/ossoffical.err.log #错误日志文件
stdout_logfile=/home/mzj/桌面/sougou/sougou/wechat_name/wechat_name/spiders/ossoffical.out.log #输出日志文件

如报错:

Unlinking stale socket /tmp/supervisor.sock

 

unlink /tmp/supervisor.sock

在配置文件底部,配置include

  1.  
    [include]
  2.  
    files=/etc/supervisor/*.conf #若你本地无/etc/supervisor目录,请自建

用supervisor管理进程,配置如下:

  1.  
    cd /etc/supervisor
  2.  
    vim ossfs.conf # 这里的文件名称自定义

加入以下内容:

  1.  
    ; 设置进程的名称,使用 supervisorctl 来管理进程时需要使用该进程名
  2.  
    [program:your_program_name]
  3.  
    command=python server.py --port=9000
  4.  
    ;numprocs=1 ; 默认为1
  5.  
    ;process_name=%(program_name)s ; 默认为 %(program_name)s,即 [program:x] 中的 x
  6.  
    directory=/home/python/tornado_server ; 执行 command 之前,先切换到工作目录
  7.  
    user=oxygen ; 使用 oxygen 用户来启动该进程
  8.  
    ; 程序崩溃时自动重启,重启次数是有限制的,默认为3次
  9.  
    autorestart=true
  10.  
    redirect_stderr=true ; 重定向输出的日志
  11.  
    stdout_logfile = /var/log/supervisord/tornado_server.log
  12.  
    loglevel=info

这里是启动要配置的参数,请根据自己的项目自定义添加

更改了supervisor配置文件,需要重启,运行以下指令:

supervisorctl reload
 

4.supervisorctl的用法

  1.  
    supervisord : 启动supervisor
  2.  
    supervisorctl reload :修改完配置文件后重新启动supervisor
  3.  
    supervisorctl status :查看supervisor监管的进程状态
  4.  
    supervisorctl start 进程名 :启动XXX进程
  5.  
    supervisorctl stop 进程名 :停止XXX进程
  6.  
    supervisorctl stop all:停止全部进程,注:start、restart、stop都不会载入最新的配置文件。
  7.  
    supervisorctl update:根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启

5.若不使用控制台来管理进程,用浏览器来管理,该如何配置?

打开配置文件

vim /etc/supervisord.conf
 

配置 inet_http_server

  1.  
    [inet_http_server]
  2.  
    port=127.0.0.1:9001 ; 服务器ip
  3.  
    username=xxx ;自定义
  4.  
    password=xxx ;自定义

三、设置开机启动

vim /etc/init.d/supervisord
 

添加以下脚本

  1.  
    #! /bin/sh
  2.  
    ### BEGIN INIT INFO
  3.  
    # Provides: supervisord
  4.  
    # Required-Start: $remote_fs
  5.  
    # Required-Stop: $remote_fs
  6.  
    # Default-Start: 2 3 4 5
  7.  
    # Default-Stop: 0 1 6
  8.  
    # Short-Description: Example initscript
  9.  
    # Description: This file should be used to construct scripts to be
  10.  
    # placed in /etc/init.d.
  11.  
    ### END INIT INFO
  12.  
     
  13.  
    # Author: Dan MacKinlay <danielm@phm.gov.au>
  14.  
    # Based on instructions by Bertrand Mathieu
  15.  
    # http://zebert.blogspot.com/2009/05/installing-django-solr-varnish-and.html
  16.  
     
  17.  
    # Do NOT "set -e"
  18.  
     
  19.  
    # PATH should only include /usr/* if it runs after the mountnfs.sh script
  20.  
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
  21.  
    DESC="Description of the service"
  22.  
    NAME=supervisord
  23.  
    DAEMON=/usr/local/bin/supervisord
  24.  
    DAEMON_ARGS=" -c /etc/supervisord.conf"
  25.  
    #PIDFILE=/var/run/$NAME.pid
  26.  
    PIDFILE=/tmp/$NAME.pid
  27.  
    SCRIPTNAME=/etc/init.d/$NAME
  28.  
     
  29.  
    # Exit if the package is not installed
  30.  
    [ -x "$DAEMON" ] || exit 0
  31.  
     
  32.  
    # Read configuration variable file if it is present
  33.  
    [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  34.  
     
  35.  
    # Load the VERBOSE setting and other rcS variables
  36.  
    . /lib/init/vars.sh
  37.  
     
  38.  
    # Define LSB log_* functions.
  39.  
    # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  40.  
    . /lib/lsb/init-functions
  41.  
     
  42.  
    #
  43.  
    # Function that starts the daemon/service
  44.  
    #
  45.  
    do_start()
  46.  
    {
  47.  
    # Return
  48.  
    # 0 if daemon has been started
  49.  
    # 1 if daemon was already running
  50.  
    # 2 if daemon could not be started
  51.  
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  52.  
    || return 1
  53.  
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  54.  
    $DAEMON_ARGS \
  55.  
    || return 2
  56.  
    # Add code here, if necessary, that waits for the process to be ready
  57.  
    # to handle requests from services started subsequently which depend
  58.  
    # on this one. As a last resort, sleep for some time.
  59.  
    }
  60.  
     
  61.  
    #
  62.  
    # Function that stops the daemon/service
  63.  
    #
  64.  
    do_stop()
  65.  
    {
  66.  
    # Return
  67.  
    # 0 if daemon has been stopped
  68.  
    # 1 if daemon was already stopped
  69.  
    # 2 if daemon could not be stopped
  70.  
    # other if a failure occurred
  71.  
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  72.  
    RETVAL="$?"
  73.  
    [ "$RETVAL" = 2 ] && return 2
  74.  
    # Wait for children to finish too if this is a daemon that forks
  75.  
    # and if the daemon is only ever run from this initscript.
  76.  
    # If the above conditions are not satisfied then add some other code
  77.  
    # that waits for the process to drop all resources that could be
  78.  
    # needed by services started subsequently. A last resort is to
  79.  
    # sleep for some time.
  80.  
    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  81.  
    [ "$?" = 2 ] && return 2
  82.  
    # Many daemons don't delete their pidfiles when they exit.
  83.  
    rm -f $PIDFILE
  84.  
    return "$RETVAL"
  85.  
    }
  86.  
     
  87.  
    #
  88.  
    # Function that sends a SIGHUP to the daemon/service
  89.  
    #
  90.  
    do_reload() {
  91.  
    #
  92.  
    # If the daemon can reload its configuration without
  93.  
    # restarting (for example, when it is sent a SIGHUP),
  94.  
    # then implement that here.
  95.  
    #
  96.  
    start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  97.  
    return 0
  98.  
    }
  99.  
     
  100.  
    case "$1" in
  101.  
    start)
  102.  
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  103.  
    do_start
  104.  
    case "$?" in
  105.  
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  106.  
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  107.  
    esac
  108.  
    ;;
  109.  
    stop)
  110.  
    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  111.  
    do_stop
  112.  
    case "$?" in
  113.  
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  114.  
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  115.  
    esac
  116.  
    ;;
  117.  
    #reload|force-reload)
  118.  
    #
  119.  
    # If do_reload() is not implemented then leave this commented out
  120.  
    # and leave 'force-reload' as an alias for 'restart'.
  121.  
    #
  122.  
    #log_daemon_msg "Reloading $DESC" "$NAME"
  123.  
    #do_reload
  124.  
    #log_end_msg $?
  125.  
    #;;
  126.  
    restart|force-reload)
  127.  
    #
  128.  
    # If the "reload" option is implemented then remove the
  129.  
    # 'force-reload' alias
  130.  
    #
  131.  
    log_daemon_msg "Restarting $DESC" "$NAME"
  132.  
    do_stop
  133.  
    case "$?" in
  134.  
    0|1)
  135.  
    do_start
  136.  
    case "$?" in
  137.  
    0) log_end_msg 0 ;;
  138.  
    1) log_end_msg 1 ;; # Old process is still running
  139.  
    *) log_end_msg 1 ;; # Failed to start
  140.  
    esac
  141.  
    ;;
  142.  
    *)
  143.  
    # Failed to stop
  144.  
    log_end_msg 1
  145.  
    ;;
  146.  
    esac
  147.  
    ;;
  148.  
    *)
  149.  
    #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  150.  
    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  151.  
    exit 3
  152.  
    ;;
  153.  
    esac
  154.  
     
  155.  
    :
  1.  
    # 设置该脚本为可以执行
  2.  
    sudo chmod +x /etc/init.d/supervisord
  3.  
    # 设置为开机自动运行
  4.  
    sudo update-rc.d supervisord defaults
  5.  
    # 试一下,是否工作正常
  6.  
    service supervisord stop
  7.  
    service supervisord start

若报错:insserv: warning: script 'service' missing LSB tags and overrides,请执行:

sudo apt-get remove insserv
 

---------------------

本文来自 唐僧不爱八戒 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/python36/article/details/80571888?utm_source=copy

supervisor 安装配置详解的更多相关文章

  1. Eclipse IDE for C/C++ Developers安装配置详解

    Eclipse IDE for C/C++ Developers安装配置详解(转) 转自:http://hi.baidu.com/ltb6w/item/986532efd712460f570f1ddc ...

  2. Cloudera CDH 、Impala本地通过Parcel安装配置详解及什么是Parcel

    本文引用自:Cloudera CDH .Impala本地通过Parcel安装配置详解及什么是Parcelhttp://www.aboutyun.com/forum.php?mod=viewthread ...

  3. lvs keepalived 安装配置详解【转】

    lvs keepalived 安装配置详解 张映 发表于 2012-06-20 分类目录: 服务器相关 前段时间看了一篇文章,lvs做负载均衡根F5差不多,说实话不怎么相信,因为F5没玩过,也无法比较 ...

  4. ubuntu14.04 server ftp 服务安装配置详解

    ubuntu14.04 server ftp 服务安装配置详解 cheungmine 2016-01-27 http://wiki.ubuntu.com.cn/Vsftpd 0 安装好vsftpd服务 ...

  5. JDK10安装配置详解

    JDK10安装配置详解 1. 下载jdk10 1.1 官网下载jdk7的软件包:        地址:http://www.oracle.com/technetwork/java/javase/dow ...

  6. (转)python中调用R语言通过rpy2 进行交互安装配置详解

    python中调用R语言通过rpy2 进行交互安装配置详解(R_USER.R_HOME配置) 2018年11月08日 10:00:11 luqin_ 阅读数:753   python中调用R语言通过r ...

  7. (转)使用LVS实现负载均衡原理及安装配置详解

    使用LVS实现负载均衡原理及安装配置详解 原文:https://www.cnblogs.com/liwei0526vip/p/6370103.html

  8. redis cluster 集群 安装 配置 详解

    redis cluster 集群 安装 配置 详解 张映 发表于 2015-05-01 分类目录: nosql 标签:cluster, redis, 安装, 配置, 集群 Redis 集群是一个提供在 ...

  9. 使用LVS实现负载均衡原理及安装配置详解

    负载均衡集群是 load balance 集群的简写,翻译成中文就是负载均衡集群.常用的负载均衡开源软件有nginx.lvs.haproxy,商业的硬件负载均衡设备F5.Netscale.这里主要是学 ...

随机推荐

  1. 常用 UML 类图

    一. 类 类图分三层: 第一层是类的名称,如果是抽象类,则用斜体显示. 第二层是类的特性,通常就是字段和属性. 第三层是类的操作,通常是方法或行为.注意 '+' 表示 public,'-' 表示 pr ...

  2. python argparse:命令行参数解析详解

    简介 本文介绍的是argparse模块的基本使用方法,尤其详细介绍add_argument内建方法各个参数的使用及其效果. 本文翻译自argparse的官方说明,并加上一些笔者的理解 import a ...

  3. egg 框架自动创建数据库表结构

    // {app_root}/app.js module.exports = app => { app.beforeStart(async () => { // 从配置中心获取 MySQL ...

  4. Java匹马行天下之一顿操作猛如虎,框架作用知多少?

    流行框架: 框架就是开发人员定义好的一套模板,程序员只需要往模板中添加响应的代码即可,填完代码,项目就完成了.所以框架存在的意义以及我们学习框架的目的就是想办法能够让程序员快速的完成整个项目的开发.理 ...

  5. FPGA时序约束理解记录

    最近整理了一下时序约束的内容,顺便发出来分享记录一下. 任何硬件想要工作正常,均需满足建立和保持时间,至于这个概念不再陈述. 下面将重点介绍两个概念:建立余量和保持余量.FPGA内部进行时序分析无非就 ...

  6. [考试反思]1001csp-s模拟测试(b):逃离

    如你所见,b组题,除了NC乱入直奔T2抢了我一个首杀以外A层学过FFT的人都没有参加. 竞争压力很小,题又简单,所以就造就了6个AK. 然而并不计入总分,我仍然稳在第二机房. T1lyl16分钟切掉我 ...

  7. 「刷题」Triple

    正解是普通型母函数+FFT. 才学了多项式,做了一道比较好的题了. 首先有三个斧子被偷了. 我们考虑构造一种普通型母函数. 就是说一种多项式吧,我的理解. 系数是方案,下标,也就是所谓的元指数代表的是 ...

  8. centos7 yum 安装 mysql5.7

    1.查看系统中是否已安装 MySQL 服务,以下提供两种方式: rpm -qa | grep mysqlyum list installed | grep mysql 2.如果已安装则删除 MySQL ...

  9. Intellij IDEA配置JDK、Maven和Tomcat

    一.配置JDK 1.File-->Project Structure 2.选择SDKs 3.点击+号添加自己本地jdk的安装目录,保存即可 二.配置Maven 1.File -> Othe ...

  10. 一文教您如何通过 Java 压缩文件,打包一个 tar.gz Filebeat 采集器包

    欢迎关注笔者的公众号: 小哈学Java, 专注于推送 Java 领域优质干货文章!! 个人网站: https://www.exception.site/essay/create-tar-gz-by-j ...