大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

unix中配置Supervisor的教程

这篇文章给大家分享的是有关unix中配置Supervisor的教程。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。

创新互联成立与2013年,是专业互联网技术服务公司,拥有项目成都网站设计、网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元寻甸做网站,已为上家服务,为寻甸各地企业和个人服务,联系电话:18980820575

/etc/supervisord.conf配置

注意
1、去掉[include]配置的注释,包括[include]本身
[include]
files = /etc/supervisor/.ini
2、[inet_http_server]中的port配置,
:port
[inet_http_server]        
port=*:9001

[root@home supervisor]# ll /etc/supervisord.conf 
-rw-r--r-- 1 root root 9178 Jan  6 14:18 /etc/supervisord.conf
[root@home supervisor]# cat /etc/supervisord.conf 
; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
;  - Shell expansion ("~" or "$HOME") is not supported.  Environment
;    variables can be expanded using this syntax: "%(ENV_HOME)s".
;  - Quotes around values are not supported, except in the case of
;    the environment= options as shown below.
;  - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
;  - Command will be truncated if it looks like a config file comment, e.g.
;    "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ".

[unix_http_server]
file=/tmp/supervisor.sock   ; the path to the socket file
;chmod=0700                 ; socket file mode (default 0700)
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

[inet_http_server]         ; inet (TCP) server disabled by default
port=*:9001       ; ip_address:port specifier, *:port for all iface
username=user              ; default is no username (open server)
password=123               ; default is no password (open server)

[supervisord]
logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB        ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10           ; # of main logfile backups; 0 means none, default 10
loglevel=info                ; log level; default info; others: debug,warn,trace
pidfile=/tmp/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
;umask=022                   ; process file creation umask; default 022
;user=chrism                 ; default is current user, required if root
;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 rpcinterface:supervisor 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:x] sections.

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

; The supervisorctl section configures how supervisorctl will connect to
; supervisord.  configure it match the settings in either the unix_http_server
; or inet_http_server section.

[supervisorctl]
serverurl=unix:///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 in [*_http_server] if set
password=123                ; should be same as in [*_http_server] if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available

; The sample program section below 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=1                    ; number of processes copies to start (def 1)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=999                  ; the relative start priority (default 999)
;autostart=true                ; start at supervisord start (default: true)
;startsecs=1                   ; # of secs prog must stay up to be running (def. 1)
;startretries=3                ; max # of serial start failures when starting (default 3)
;autorestart=unexpected        ; when to restart if exited after running (def: unexpected)
;exitcodes=0,2                 ; 'expected' exit codes used with autorestart (default 0,2)
;stopsignal=QUIT               ; signal used to kill process (default TERM)
;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
;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=10     ; # of stdout logfile backups (0 means none, default 10)
;stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
;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=10     ; # of stderr logfile backups (0 means none, default 10)
;stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;environment=A="1",B="2"       ; process environment additions (def no adds)
;serverurl=AUTO                ; override serverurl computation (childutils)

; The sample eventlistener section below shows all possible eventlistener
; subsection values.  Create one or more 'real' eventlistener: sections to be
; able to handle event notifications sent by supervisord.

;[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=1                    ; number of processes copies to start (def 1)
;events=EVENT                  ; event notif. types to subscribe to (req'd)
;buffer_size=10                ; event buffer queue size (default 10)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=-1                   ; the relative start priority (default -1)
;autostart=true                ; start at supervisord start (default: true)
;startsecs=1                   ; # of secs prog must stay up to be running (def. 1)
;startretries=3                ; max # of serial start failures when starting (default 3)
;autorestart=unexpected        ; autorestart if exited after running (def: unexpected)
;exitcodes=0,2                 ; 'expected' exit codes used with autorestart (default 0,2)
;stopsignal=QUIT               ; signal used to kill process (default TERM)
;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
;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=false         ; redirect_stderr=true is not allowed for eventlisteners
;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=10     ; # of stdout logfile backups (0 means none, default 10)
;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=10     ; # of stderr logfile backups (0 means none, default 10)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;environment=A="1",B="2"       ; process environment additions
;serverurl=AUTO                ; override serverurl computation (childutils)

; The sample group section below 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=999                  ; the relative start priority (default 999)

; 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 = relative/directory/*.ini
files = /etc/supervisor/*.ini

监控Tomcat配置(tomcat.ini)

supervisor不支持进程后台启动方式,注意command命令以/usr/local/tomcat/bin/catalina.sh run配置可以避免后台启动方式,如此配置supervisor不报错。
注意:进程日志配置stdout_logfile=/mnt/logs/tomcat-service.log,在重启过程中如有不正常情况可以从日志文件中排查解决问题。

[root@home supervisor]# cat /etc/supervisor/tomcat.ini 
[program:tomcat]
command=/usr/local/tomcat/bin/catalina.sh run          ; the program (relative uses PATH, can take args)
user=rd
priority=999                  ; the relative start priority (default 999)
autostart=true                ; start at supervisord start (default: true)
autorestart=true              ; retstart at unexpected quit (default: true)
startretries=10                ; max # of serial start failures (default 3)
stdout_logfile=/mnt/logs/tomcat-service.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)

监控Grafana配置(grafana.ini)

grafana是以service方式启动,同样有后台方式启动的问题,需要将/etc/init.d/grafana-server中    
action $"Starting $DESC: ..." su -s /bin/sh -c "nohup ${DAEMON} ${DAEMON_OPTS} >> /dev/null 3>&1 &" $GRAFANA_USER 2> /dev/null
修改为:
action $"Starting $DESC: ..." su -s /bin/sh -c "nohup ${DAEMON} ${DAEMON_OPTS} >> /dev/null 3>&1 " $GRAFANA_USER 2> /dev/null

修改grafana-server的启动脚本

[root@home init.d]# cat /etc/init.d/grafana-server 
#! /usr/bin/env bash

# chkconfig: 2345 80 05
# description: Grafana web server & backend
# processname: grafana
# config: /etc/grafana/grafana.ini
# pidfile: /var/run/grafana.pid

### BEGIN INIT INF
# Provides:          grafana
# Required-Start:    $all
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start grafana at boot time
### END INIT INFO

#  tested on
#  1. New lsb that define start-stop-daemon
#  3. Centos with initscripts package installed

PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=grafana-server
DESC="Grafana Server"

GRAFANA_USER=grafana
GRAFANA_GROUP=grafana
GRAFANA_HOME=/usr/share/grafana
CONF_DIR=/etc/grafana
WORK_DIR=$GRAFANA_HOME
DATA_DIR=/var/lib/grafana
PLUGINS_DIR=/var/lib/grafana/plugins
LOG_DIR=/var/log/grafana
CONF_FILE=$CONF_DIR/grafana.ini
PROVISIONING_CFG_DIR=$CONF_DIR/provisioning
MAX_OPEN_FILES=10000
PID_FILE=/var/run/$NAME.pid
DAEMON=/usr/sbin/$NAME

if [ ! -x $DAEMON ]; then
  echo "Program not installed or not executable"
  exit 5
fi

#
# init.d / servicectl compatibility (openSUSE)
#
if [ -f /etc/rc.status ]; then
    . /etc/rc.status
    rc_reset
fi

#
# Source function library.
#
if [ -f /etc/rc.d/init.d/functions ]; then
    . /etc/rc.d/init.d/functions
fi

# overwrite settings from default file
[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME

DAEMON_OPTS="--pidfile=${PID_FILE} --config=${CONF_FILE} --packaging=rpm cfg:default.paths.provisioning=$PROVISIONING_CFG_DIR cfg:default.paths.data=${DATA_DIR} cfg:default.paths.logs=${LOG_DIR} cfg:default.paths.plugins=${PLUGINS_DIR}"

function isRunning() {
  status -p $PID_FILE $NAME > /dev/null 2>&1
}

function checkUser() {
  if [ `id -u` -ne 0 ]; then
    echo "You need root privileges to run this script"
    exit 4
  fi
}

case "$1" in
  start)
    checkUser
    isRunning
    if [ $? -eq 0 ]; then
      echo "Already running."
      exit 0
    fi

    # Prepare environment
    mkdir -p "$LOG_DIR" "$DATA_DIR" && chown "$GRAFANA_USER":"$GRAFANA_GROUP" "$LOG_DIR" "$DATA_DIR"
    touch "$PID_FILE" && chown "$GRAFANA_USER":"$GRAFANA_GROUP" "$PID_FILE"

    if [ -n "$MAX_OPEN_FILES" ]; then
      ulimit -n $MAX_OPEN_FILES
    fi

    # Start Daemon
    cd $GRAFANA_HOME
    #action $"Starting $DESC: ..." su -s /bin/sh -c "nohup ${DAEMON} ${DAEMON_OPTS} >> /dev/null 3>&1 &" $GRAFANA_USER 2> /dev/null
    action $"Starting $DESC: ..." su -s /bin/sh -c "nohup ${DAEMON} ${DAEMON_OPTS} >> /dev/null 3>&1 " $GRAFANA_USER 2> /dev/null
    return=$?
    if [ $return -eq 0 ]
    then
      sleep 1
      # check if pid file has been written to
      if ! [[ -s $PID_FILE ]]; then
        echo "FAILED"
        exit 1
      fi
      i=0
      timeout=10
      # Wait for the process to be properly started before exiting
      until { cat "$PID_FILE" | xargs kill -0; } >/dev/null 2>&1
      do
        sleep 1
        i=$(($i + 1))
        if [ $i -gt $timeout ]; then
          echo "FAILED"
          exit 1
        fi
      done
    fi

    exit $return
    ;;
  stop)
    checkUser
    echo -n "Stopping $DESC: ..."

    if [ -f "$PID_FILE" ]; then
      killproc -p $PID_FILE -d 20 $NAME
      if [ $? -eq 1 ]; then
        echo  "$DESC is not running but pid file exists, cleaning up"
      elif [ $? -eq 3 ]; then
        PID="`cat $PID_FILE`"
        echo  "Failed to stop $DESC (pid $PID)"
        exit 1
      fi
      rm -f "$PID_FILE"
      echo  ""
      exit 0
    else
      echo  "(not running)"
    fi
    exit 0
    ;;
  status)
    status -p $PID_FILE $NAME
    exit $?
    ;;
  restart|force-reload)
    if [ -f "$PID_FILE" ]; then
      $0 stop
      sleep 1
    fi
    $0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|force-reload|status}"
    exit 3
    ;;
esac

配置grafana-server.ini

[root@home init.d]# cat /etc/supervisor/grafana.ini 
[program:grafana]
command=service grafana-server start          ; the program (relative uses PATH, can take args)
priority=999                  ; the relative start priority (default 999)
autostart=true                ; start at supervisord start (default: true)
autorestart=true              ; retstart at unexpected quit (default: true)
startretries=10                ; max # of serial start failures (default 3)
stdout_logfile=/mnt/logs/grafana-service.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)

监控Influxdb配置(influxdb.ini)

修改influxdb启动脚本,取消后台启动&符号(以下启动脚本一部分)

[rd@home ~]$ vim /etc/init.d/influxdb 
# 省略没有被修改的代码
# Launch process
echo "Starting $NAME..."
if command -v start-stop-daemon &>/dev/null; then
    start-stop-daemon \
        --chuid $USER:$GROUP \
        --start \
        --quiet \
        --pidfile $PIDFILE \
        --exec $DAEMON \
        -- \
        -pidfile $PIDFILE \
        -config $CONFIG \
        #$INFLUXD_OPTS >>$STDOUT 2>>$STDERR &  这个地方有修改
        $INFLUXD_OPTS >>$STDOUT 2>>$STDERR
else
    #local CMD="$DAEMON -pidfile $PIDFILE -config $CONFIG $INFLUXD_OPTS >>$STDOUT 2>>$STDERR &"  这个地方有修改
    local CMD="$DAEMON -pidfile $PIDFILE -config $CONFIG $INFLUXD_OPTS >>$STDOUT 2>>$STDERR "
    su -s /bin/sh -c "$CMD" $USER
fi

配置grafana.ini

[rd@home ~]$ cat /etc/supervisor/influxdb.ini 
[program:influxdb]
command=service influxdb start          ; the program (relative uses PATH, can take args)
priority=999                  ; the relative start priority (default 999)
autostart=true                ; start at supervisord start (default: true)
autorestart=true              ; retstart at unexpected quit (default: true)
startretries=10                ; max # of serial start failures (default 3)
stderr_logfile=/mnt/logs/influxdb-services.err.log
stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=10     ; # of stdout logfile backups (default 10)
stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)

stdout_logfile=/mnt/logs/influxdb-service.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=2MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)

以上就是unix中配置Supervisor的方法介绍,详细使用情况还得要大家自己使用过才能知道具体要领。如果想阅读更多相关内容的文章,欢迎关注创新互联行业资讯频道!


当前题目:unix中配置Supervisor的教程
URL地址:http://dzwzjz.com/article/jgdspc.html
在线咨询
服务热线
服务热线:028-86922220
TOP