zoukankan      html  css  js  c++  java
  • 配置supervisor管理beego应用

    一、golang、beego等环境安装与配置

    二、supervisor安装

    github项目地址:https://github.com/Supervisor/supervisor
    克隆项目:git clone https://github.com/Supervisor/supervisor.git
    进入项目:cd supervisor
    安装执行:python setup.py install

    三、supervisor配置文件

    官方文档-配置部分
    vi /etc/supervisord.conf

    [supervisord]
    http_port=/var/tmp/supervisor.sock ; (default is to run a UNIX domain socket server)
    ;http_port=127.0.0.1:9001  ; (alternately, ip_address:port specifies AF_INET)
    ;sockchmod=0700              ; AF_UNIX socketmode (AF_INET ignore, default 0700)
    ;sockchown=nobody.nogroup     ; AF_UNIX socket uid.gid owner (AF_INET ignores)
    ;umask=022                   ; (process file creation umask;default 022)
    logfile=/var/log/supervisor/supervisord.log ; (supervisor输出日志,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               ; (logging level;default info; others: debug,warn)
    pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
    nodaemon=false              ; (start in foreground if true;default false)
    minfds=1024                 ; (min. avail startup file descriptors;default 1024)
    minprocs=200                ; (min. avail process descriptors;default 200)
    
    ;nocleanup=true              ; (don't clean up tempfiles at start;default false)
    ;http_username=user          ; (default is no username (open system))
    ;http_password=123           ; (default is no password (open system))
    ;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
    ;user=chrism                 ; (default is current user, required if root)
    ;directory=/tmp              ; (default is not to cd during start)
    ;environment=KEY=value       ; (key value pairs to add to environment)
    
    [supervisorctl]
    serverurl=unix:///var/tmp/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=123                ; should be same as http_password if set
    ;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
    
    [unix_http_server]
    file=/var/tmp/supervisor.sock   ; (the path to the socket file)
    ;chmod=0777                 ; socket file mode (default 0700)
    ;chown=root:root       ; socket file uid:gid owner
    ;username=root              ; (default is no username (open server))
    ;password=root               ; (default is no password (open server))
    
    [inet_http_server]
    port = 127.0.0.1:9001
    
    [rpcinterface:supervisor]
    supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
    
    [program:hello] ;可以在这边配置要管理的程序
    directory=/home/www/php/ ;
    command=/usr/bin/php test.php ;
    process_name=%(program_name)s ;
    numprocs=1 ;
    autostart=true ;
    startsecs=1 ;
    autorestart=true ;
    startretries=3 ;
    user=root ;
    redirect_stderr=true ;
    stdout_logfile_maxbytes=20MB ;
    stdout_logfile_backups=10 ;
    
    [include] ;也可以通过include包含进来程序配置文件
    files = ./supervisor/conf.d/*.ini ;
    

    vi /etc/supervisor/conf.d/wx-prj.ini

    [program:wx-prj]
    ;directory=/home/www/go/src/wx-prj ;go项目目录
    ;command=/home/www/go/src/wx-prj/wx-prj ;go项目编译好的可执行文件
    directory=/home/www/go/bin ;
    command=/home/www/go/bin/wx-prj ;
    process_name=%(program_name)s ;
    numprocs=1 ;
    autostart=true ;
    startsecs=1 ;
    autorestart=true ;
    startretries=3 ;
    user=root ;
    redirect_stderr=true ;
    stdout_logfile=/home/www/go/wx-prj.stdout.log ;打印标准输出日志
    stdout_logfile_maxbytes=20MB ;
    stdout_logfile_backups=10 ;
    stderr_logfile=/home/www/go/wx-prj.stderr.log ;打印标准错误输出日志
    stderr_logfile_maxbytes=20MB ;
    stderr_logfile_backups=10 ;
    log_stdout=true             ; if true, log program stdout (default true)
    log_stderr=true             ; if true, log program stderr (def false)
    

    四、启动supervisor服务

    supervisord -c /etc/supervisord.conf
    
    启动服务时可以跟踪日志输出观察
    [root@10-23-67-69 go]# tail -f  /var/log/supervisor/supervisord.log
    2018-10-26 13:36:30,881 INFO Included extra file "/etc/./supervisor/conf.d/wx-prj.ini" during parsing
    2018-10-26 13:36:30,902 INFO RPC interface 'supervisor' initialized
    2018-10-26 13:36:30,902 CRIT Server 'inet_http_server' running without any HTTP authentication checking
    2018-10-26 13:36:31,203 INFO RPC interface 'supervisor' initialized
    2018-10-26 13:36:31,203 CRIT Server 'unix_http_server' running without any HTTP authentication checking
    2018-10-26 13:36:31,206 INFO daemonizing the supervisord process
    2018-10-26 13:36:31,207 INFO supervisord started with pid 17040
    2018-10-26 13:36:32,209 INFO spawned: 'hello' with pid 17041
    2018-10-26 13:36:32,213 INFO spawned: 'wx-prj' with pid 17042
    2018-10-26 13:36:32,219 INFO spawned: 'world' with pid 17043
    2018-10-26 13:36:33,279 INFO success: hello entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
    2018-10-26 13:36:33,279 INFO success: wx-prj entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
    2018-10-26 13:36:33,279 INFO success: world entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
    
    也通过命令查看程序状态
    [root@10-23-67-69 conf.d]# supervisorctl status
    hello                            RUNNING   pid 17041, uptime 0:00:19
    world                            RUNNING   pid 17043, uptime 0:00:19
    wx-prj                           RUNNING   pid 17042, uptime 0:00:19
    

    五、重载supervisor修改过的配置

    supervisorctl reload
    

    六、停止/启动/重启supervisor管理的程序

    [root@10-23-67-69 conf.d]# supervisorctl stop wx-prj
    wx-prj: stopped
    [root@10-23-67-69 conf.d]# supervisorctl start wx-prj
    wx-prj: started
    [root@10-23-67-69 conf.d]# supervisorctl restart wx-prj
    wx-prj: stopped
    wx-prj: started
    [root@10-23-67-69 conf.d]# supervisorctl stop all
    hello: stopped
    wx-prj: stopped
    world: stopped
    [root@10-23-67-69 conf.d]# supervisorctl start all
    hello: started
    wx-prj: started
    world: started
    
  • 相关阅读:
    《ASP.ENT Core 与 RESTful API 开发实战》-- (第5章)-- 读书笔记(中)
    《ASP.ENT Core 与 RESTful API 开发实战》-- (第5章)-- 读书笔记(上)
    《ASP.ENT Core 与 RESTful API 开发实战》-- (第4章)-- 读书笔记(下)
    《ASP.ENT Core 与 RESTful API 开发实战》-- (第4章)-- 读书笔记(上)
    《ASP.ENT Core 与 RESTful API 开发实战》(第3章)-- 读书笔记(下)
    《ASP.ENT Core 与 RESTful API 开发实战》(第3章)-- 读书笔记(中)
    《ASP.ENT Core 与 RESTful API 开发实战》(第3章)-- 读书笔记(上)
    《ASP.ENT Core 与 RESTful API 开发实战》-- 读书笔记(第2章)
    《ASP.ENT Core 与 RESTful API 开发实战》-- 读书笔记(第1章)
    ASP.NET Core分布式项目实战(集成ASP.NETCore Identity)--学习笔记
  • 原文地址:https://www.cnblogs.com/clivewang/p/9863687.html
Copyright © 2011-2022 走看看