Supervisor 管理后台守护进程

安装

pip install supervisor

启动

  1. supervisord
  2. supervisord -c /etc/supervisord.conf
    supervisord 的配置文件默认位于 /etc/supervisord.conf;后面为注释

关闭服务

  1. supervisorctl stop all 先关闭supervisor启动脚本,之后再关闭supervisord服务
  2. kill pid

配置

supervisord 配置 program 项的路径下:/etc/supervisor/conf.d/,然后 program 的配置文件命名规则推荐:app_name.conf

常用命令

  • 查看正在守候的进程【常用】
    supervisorctl status

  • 重新加载配置
    supervisorctl reread

  • 更新新的配置到supervisord【常用】
    supervisorctl update

  • 重新启动配置中的所有程序
    supervisorctl reload

  • 启动某个进程
    supervisorctl start program_name

  • 停止某一进程
    pervisorctl stop program_name

  • 重启某一进程
    supervisorctl restart program_name

踩过的坑

  1. 执行supervisorctl status报错【error: <class 'socket.error'>, [Errno 101] Network is unreachable: file: /usr/local/python/lib/python2.7/socket.py line: 575】
    问题原因:找不到supervisord.conf文件
    解决方法:
    1)进入到supervisord目录再执行命令;
    2)supervisorctl status -c /etc/supervisord.conf

supervisor monitor工具

  1. 安装
    git clone https://github.com/mlazarov/supervisord-monitor.git

  2. 进入到application中,将默认的配置文件重命名
    cd /root/supervisord-monitor/application/config
    cp supervisor.php.example supervisor.php

  3. 打开该配置文件,所有需要连接的服务器都是在这个文件中进行设置的
    vim supervisor.php
    按照如下格式,输入需要连接的服务器的ip地址和用户名密码即可

$config['supervisor_servers'] = array(
        '127.0.0.1' => array(
                'url' => 'http://127.0.0.1/RPC2',
                'port' => '9001',
                'username' => 'user',
                'password' => '123'
        ),
);
  1. 给网站加密码
    通过htpasswd对该网页进行加密处理,需要登录才能进入网页
    1)安装httpd-tools:yum -y install httpd-tools
    2)然后在指定位置创建密码文件
    htpasswd -c /etc/nginx/htpasswd admin
    新增用户/修改密码:htpasswd /etc/nginx/htpasswd admin
    删除用户:htpasswd -D /etc/nginx/htpasswd admin
    3)在nginx配置中进行配置
    vim /etc/nginx/nginx.conf
        location / {
                        auth_basic "nginx basic http test for localhost";
                        auth_basic_user_file htpasswd;
                        autoindex on;
                try_files $uri $uri/ /index.php;
        }

4)重启nginx

原文地址:https://www.cnblogs.com/yoyoyang/p/11814072.html