centos6.5安装配置supervisor
1.下载并安装supervisor
https://pypi.python.org/pypi/supervisor/3.2.0 tar -zxvf supervisor-3.2..tar.gz
cd supervisor-3.2.
python setup.py install
2.测试supervisord是否安装成功
[root conf.d]# echo_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".
; - Comments must have a leading space: "a=b ;comment" not "a=b;comment". [unix_http_server]
file=/tmp/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=/tmp/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=/tmp/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)
;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:///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= ; 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)
;startsecs= ; # of secs prog must stay up to be running (def. )
;startretries= ; max # of serial start failures when starting (default )
;autorestart=unexpected ; when to restart if exited after running (def: unexpected)
;exitcodes=, ; 'expected' exit codes used with autorestart (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)
;startsecs= ; # of secs prog must stay up to be running (def. )
;startretries= ; max # of serial start failures when starting (default )
;autorestart=unexpected ; autorestart if exited after running (def: unexpected)
;exitcodes=, ; 'expected' exit codes used with autorestart (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=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= ; # 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.
3.建立文件夹,把应用的配置文件单独放置
mkdir -p /opt/app/supervisor mkdir -p /opt/app/supervisor/conf.d
4.创建默认的配置文件,并修改配置
echo_supervisord_conf >/opt/app/supervisor/supervisord.conf vi /etc/supervisord.conf [inet_http_server] ; inet (TCP) server disabled by default
port=0.0.0.0: ; (ip_address:port specifier, *:port for all iface)
username=user ; (default is no username (open server))
password= ; (default is no password (open server))
[include]
files = ./conf.d/*.conf
5.设定supervisor启动文件
vi /etc/init.d/supervisord #! /usr/bin/env bash
# chkconfig: - PATH=/sbin:/bin:/usr/sbin:/usr/bin PROGNAME=supervisord DAEMON=/usr/bin/$PROGNAME CONFIG=/opt/app/supervisor/$PROGNAME.conf PIDFILE=/tmp/$PROGNAME.pid DESC="supervisord daemon" SCRIPTNAME=/etc/init.d/$PROGNAME # Gracefully exit if the package has been removed. test -x $DAEMON || exit start() { echo -n "Starting $DESC: $PROGNAME" $DAEMON -c $CONFIG echo ".............start success" } stop() { echo "Stopping $DESC: $PROGNAME" if [ -f "$PIDFILE" ];
then
supervisor_pid=$(cat $PIDFILE)
kill - $supervisor_pid
echo "......"
echo "stop success"
else
echo "$DESC: $PROGNAME is not Runing"
echo ".........................stop sucess"
fi
} status() { statusport=`netstat -lntp|grep |awk -F ' ' '{print $4}'|awk -F ':' '{print $2}'` if [ -f "$PIDFILE" ];
then
supervisor_pid=$(cat $PIDFILE)
echo "$DESC: $PROGNAME is Runing pid=$supervisor_pid"
else
echo "$DESC: $PROGNAME is not Runing"
echo "please use command /etc/init.d/supervisord start Run the service"
fi
} case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart}" >& exit ;; esac exit
添加为自启动、启动、关闭
chkconfig supervisord on //添加自启动服务 service supervisord start //启动服务 service supervisord stop //停止服务
6.增加自定义的后台进程
vi /opt/app/supervisor/conf.d/salt-minion.conf
[program:salt-minion]
command=salt-minion
autostart=true
autorestart=true
以后可以按照每个应用分别写一个配置文件。
6.1(program)配置模板
[program:cat]
command=/bin/cat
process_name=%(program_name)s
numprocs=
directory=/tmp
umask=
priority=
autostart=true
autorestart=true
startsecs=
startretries=
exitcodes=,
stopsignal=TERM
stopwaitsecs=
user=chrism
redirect_stderr=false
stdout_logfile=/a/path
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=
stdout_capture_maxbytes=1MB
stderr_logfile=/a/path
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=
stderr_capture_maxbytes=1MB
environment=A="",B=""
serverurl=AUTO
6.2简化模板
[program:test]
command=python test.py
directory=/home/supervisor_test/
autorestart=true
stopsignal=INT
user=root
stdout_logfile=test_out.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=
stdout_capture_maxbytes=1MB
stderr_logfile=test_err.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=
stderr_capture_maxbytes=1MB
6.3(program)配置说明;*为必须填写项;*[program:应用名称][program:cat]
;*命令路径,如果使用python启动的程序应该为 python /home/test.py,
;不建议放入/home/user/, 对于非user用户一般情况下是不能访问
command=/bin/cat ;当numprocs为1时,process_name=%(program_name)s
;当numprocs>=2时,%(program_name)s_%(process_num)02d
process_name=%(program_name)s ;进程数量
numprocs= ;执行目录,若有/home/supervisor_test/test1.py
;将directory设置成/home/supervisor_test
;则command只需设置成python test1.py
;否则command必须设置成绝对执行目录
directory=/tmp ;掩码:--- -w- -w-, 转换后rwx r-x w-x
umask= ;优先级,值越高,最后启动,最先被关闭,默认值999
priority= ;如果是true,当supervisor启动时,程序将会自动启动
autostart=true ;*自动重启
autorestart=true ;启动延时执行,默认1秒
startsecs= ;启动尝试次数,默认3次
startretries= ;当退出码是0,2时,执行重启,默认值0,
exitcodes=, ;停止信号,默认TERM
;中断:INT(类似于Ctrl+C)(kill -INT pid),退出后会将写文件或日志(推荐)
;终止:TERM(kill -TERM pid) //信号量参考文章(http://c.biancheng.net/cpp/html/2784.html)
;挂起:HUP(kill -HUP pid),注意与Ctrl+Z/kill -stop pid不同
;从容停止:QUIT(kill -QUIT pid)
;KILL, USR1, USR2其他见命令(kill -l),说明1
stopsignal=TERM stopwaitsecs= ;*以root用户执行
user=root ;重定向
redirect_stderr=false stdout_logfile=/a/path
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=
stdout_capture_maxbytes=1MB
stderr_logfile=/a/path
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=
stderr_capture_maxbytes=1MB ;环境变量设置
environment=A="",B="" serverurl=AUTO
7.启动supervisor服务,并观察salt-minion服务状态
-- ::, INFO stopped: salt-minion (terminated by SIGTERM)
-- ::, CRIT Supervisor running as root (no user in config file)
-- ::, WARN Included extra file "/opt/app/supervisor/./conf.d/salt-minion.conf" during parsing
-- ::, INFO RPC interface 'supervisor' initialized
-- ::, INFO RPC interface 'supervisor' initialized
-- ::, CRIT Server 'unix_http_server' running without any HTTP authentication checking
-- ::, INFO daemonizing the supervisord process
-- ::, INFO supervisord started with pid
-- ::, INFO spawned: 'salt-minion' with pid
-- ::, INFO success: salt-minion entered RUNNING state, process has stayed up for > than seconds (startsecs)
8.命令使用
Supervisor 有两个可执行程序 — supervisord 和 supervisorctl:
supervisord 是后台管理服务器, 用来依据配置文件的策略管理后台守护进程;
supervisorctl 用于管理员向后台管理程序发送 启动/重启/停止 等指令;
它们之间的关系就相当于 Apache 的 httpd 和 apachectl.
8.1查看所有命令
[root~]# supervisorctl help default commands (type help <topic>):
=====================================
add exit open reload restart start tail
avail fg pid remove shutdown status update
clear maintail quit reread signal stop version
supervisord,初始启动Supervisord,启动、管理配置中设置的进程。
supervisorctl stop programxxx,停止某一个进程(programxxx),programxxx为[program:chatdemon]里配置的值
,这个示例就是chatdemon。
supervisorctl start programxxx,启动某个进程
supervisorctl restart programxxx,重启某个进程
supervisorctl stop groupworker: ,重启所有属于名为groupworker这个分组的进程(start,restart同理)
supervisorctl stop all,停止全部进程,注:start、restart、stop都不会载入最新的配置文件。
supervisorctl reload,载入最新的配置文件,停止原有进程并按新的配置启动、管理所有进程。
supervisorctl update,根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重
启。
注意:显示用stop停止掉的进程,用reload或者update都不会自动重启。
8.2进入命令行
[root ~]# supervisorctl
Server requires authentication
Username:user
Password: salt-minion RUNNING pid , uptime ::
supervisor> help default commands (type help <topic>):
=====================================
add exit open reload restart start tail
avail fg pid remove shutdown status update
clear maintail quit reread signal stop version
#显示某个命令的用法
supervisor> help add
add <name> [...] Activates any updates in config for process/group
supervisor> help reload
reload Restart the remote supervisord. #停止某个进程
supervisor> stop publisher_for_summary
publisher_for_summary: stopped #查看此时此刻的状态
supervisor> status
publisher_for_detail RUNNING pid , uptime ::
publisher_for_detail_nt RUNNING pid , uptime ::
publisher_for_summary STOPPED Feb : PM
publisher_for_summary_nt RUNNING pid , uptime ::
worker_for_detail_all RUNNING pid , uptime ::
worker_for_detail_recent RUNNING pid , uptime ::
worker_for_summary RUNNING pid , uptime ::
#发现被supervisorctl停掉的进程不会被自动重启 #开启刚才停掉的进程
supervisor> start publisher_for_summary
publisher_for_summary: started
supervisor> status
publisher_for_detail RUNNING pid , uptime ::
publisher_for_detail_nt RUNNING pid , uptime ::
publisher_for_summary RUNNING pid , uptime ::
publisher_for_summary_nt RUNNING pid , uptime ::
worker_for_detail_all RUNNING pid , uptime ::
worker_for_detail_recent RUNNING pid , uptime ::
worker_for_summary RUNNING pid , uptime :: #停掉所有进程
supervisor> stop all
worker_for_detail_recent: stopped
worker_for_detail_all: stopped
publisher_for_summary_nt: stopped
publisher_for_detail_nt: stopped
publisher_for_summary: stopped
worker_for_summary: stopped
publisher_for_detail: stopped
supervisor> status
publisher_for_detail STOPPED Feb : PM
publisher_for_detail_nt STOPPED Feb : PM
publisher_for_summary STOPPED Feb : PM
publisher_for_summary_nt STOPPED Feb : PM
worker_for_detail_all STOPPED Feb : PM
worker_for_detail_recent STOPPED Feb : PM
worker_for_summary STOPPED Feb : PM #开启所有进程
supervisor> start all
publisher_for_detail: started
worker_for_summary: started
publisher_for_summary: started
publisher_for_detail_nt: started
publisher_for_summary_nt: started
worker_for_detail_all: started
worker_for_detail_recent: started
supervisor> status
publisher_for_detail RUNNING pid , uptime ::
publisher_for_detail_nt RUNNING pid , uptime ::
publisher_for_summary RUNNING pid , uptime ::
publisher_for_summary_nt RUNNING pid , uptime ::
worker_for_detail_all RUNNING pid , uptime ::
worker_for_detail_recent RUNNING pid , uptime ::
worker_for_summary RUNNING pid , uptime ::
9.http://10.129.62.42:9001/ 可以查看进程状态
参考文档:
http://www.linuxidc.com/Linux/2012-11/73832.htm
http://supervisord.org/configuration.html
http://www.cnblogs.com/yjf512/archive/2012/03/05/2380496.html
http://my.oschina.net/crooner/blog/395069
http://jwch.sdut.edu.cn/book/server/supervisor.html
http://www.2cto.com/os/201503/378878.html
http://c.biancheng.net/cpp/html/2784.html
centos6.5安装配置supervisor的更多相关文章
- [转]CentOS-6.3安装配置cmake
CentOS-6.3安装配置cmake zhoulf 2013-02-03 原创 安装说明 安装环境:CentOS-6.3安装方式:源码编译安装 软件:cmake-2.8.10.2.tar.gz下 ...
- centos6.4安装配置vpn服务器步骤详解
centos6.4安装配置vpn服务器步骤详解,从安装VPN到配置VPN服务器.配置VPN服务器的路由转发功能,每一步都很详细 一.VPN服务器环境说明 操作系统:CentOS release ...
- CentOS6.5安装配置Samba
CentOS6.5安装配置Samba 本文的场景是虚拟机运行CentOS6.,本机是Win7,现欲把CentOS上的一个文件夹共享出来,Win的机器可以读写. Samba与window连接需要使用Ne ...
- [转]Centos6.5安装配置keepalived
参考博文: Centos6.5安装配置keepalived CentOS6.5 keepalived详解及实现Nginx服务的高可用性 CentOS6.5 LVS + KeepAlived搭建步骤 我 ...
- CentOS-6.9安装配置JDK-7
CentOS-6.9安装配置JDK-7 安装说明 系统环境:centos-6.9安装方式:rpm安装 软件:jdk-7u79-linux-x64.rpm下载地址:http://download.ora ...
- CentOS-6.6安装配置Tomcat-7
安装说明 安装环境:CentOS-6.3安装方式:源码安装 软件:apache-tomcat-7.0.29.tar.gz下载地址:http://tomcat.apache.org/download-7 ...
- 38. CentOS-6.3安装配置Tomcat-7
安装说明 安装环境:CentOS-6.3安装方式:源码安装 软件:apache-tomcat-7.0.29.tar.gz下载地址:http://tomcat.apache.org/download-7 ...
- 34. CentOS-6.3安装配置Apache2.2.6
安装说明 安装环境:CentOS-6.3安装方式:源码编译安装 软件:httpd-2.2.6.tar.gz | pcre-8.32.tar.gz | apr-1.4.6.tar.gz | apr-u ...
- Linux环境CentOS6.9安装配置Elasticsearch6.2.2最全详细教程
Linux环境CentOS6.9安装配置Elasticsearch6.2.2最全详细教程 前言 第一步:下载Elasticsearch6.2.2 第二步:创建应用程序目录 第四步:创建Elastics ...
随机推荐
- MongoDB基础之六 索引
一 . 索引概述和基本操作 1. 索引提高查询速度,降低写入速度,权衡常用的查询字段,不必在太多列上建索引2. 在mongodb中,索引可以按字段升序/降序来创建,便于排序3. 默认是用btree来组 ...
- 【小梅哥FPGA进阶教程】第九章 基于串口猎人软件的串口示波器
九.基于串口猎人软件的串口示波器 1.实验介绍 本实验,为芯航线开发板的综合实验,该实验利用芯航线开发板上的ADC.独立按键.UART等外设,搭建了一个具备丰富功能的数据采集卡,芯航线开发板负责进行数 ...
- UIApplication 和 Appdelegate-----iOS
正文 一 UIApplication 1.一个UIApplication代表是一个应用程序,而且是单例的.一个程序也只能有一个UIApplication对象 2.获取UIApplication对象: ...
- 毕向东udp学习笔记1
参看了毕向东老师的视频教程,准备直接用EditPlus记事本来直接敲Java代码,好好学习一下udp部分,GUI部分,线程部分,加油 项目功能: 实现udp简单的发送接收功能. 当使用EditPlus ...
- ionic-cordova 支付宝支付插件cordova-plugin-alipay-v2使用篇
支付宝WS_APP_PAY_SDK_BASE_2.0 <APP支付> 支付宝的cordova插件其实在github上已经有很多了,但是都已经是以前的版本了.在2016年11月的时候支付宝进 ...
- Java(多态练习 instanceof)
/* 题目: (多态,instanceof)有如下代码 class Animal { private String name; // 1 } class Dog extends Animal { // ...
- [HBase] - Hbase调优1
版本:HBase-0.98.6-cdh5.3.6 HBase参数调优 1. zookeeper.session.timeout: 默认90000(毫秒), 控制连接zk的timeout时间.由于hba ...
- 电脑机器刷BIOS
http://www.51nb.com/forum/viewthread.php?tid=934570&page=1#pid13765036 [原创]hp笔记本刷新bios失败后真的可以恢复吗 ...
- 2017-2-21 C#基础 if条件语句,作用域
今天学了if 条件语句和作用域.作用域可以用一句话来概括:儿子可以用爹的所有东西,爹不可以用儿子的任何东西.If条件语句我用几个练习题来解释. 1."请输入年份:" 判断是否是闰年 ...
- 使用秘钥连接ssh
ssh服务器搭建 通过秘钥登陆连接另外一台虚拟机 创建证书 ssh-keygen -t rsa 第一行密钥保存位置直接输入回车 确定默认创建位置为 /root/.ssh 公钥必须改名为 autho ...