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 ...
随机推荐
- windows 下 多版本nodejs切换 nvmw
以下教程不适用于nodejs v0.6.5及以下版本 nvmw 下载到本地 Git clone https://github.com/hakobera/nvmw.git 2.设置环境PATH 添加如上 ...
- Java虚拟机中Java内存区域
Java虚拟机所管理的内存将会包括以下几个运行时数据区域. 程序计数器 可以看作是当前线程所执行的字节码的行号指示器. 每一个线程都需要有一个独立的程序计数器. 如果线程正在执行的是一个Java方 ...
- [Linux] PHP程序员玩转Linux系列-搭建代码开发环境
1.PHP程序员玩转Linux系列-怎么安装使用CentOS 2.PHP程序员玩转Linux系列-lnmp环境的搭建 有些同学可能觉得我写的都是啥yum安装的,随便配置一下而已,没啥技术含量,我的目的 ...
- 一张图看懂 JS 的事件机制
一.为什么 JavaScript 单线程 假定JavaScript同时有两个线程,一个线程在某个DOM节点上添加内容,另一个线程删除了这个节点,这时浏览器应该以哪个线程为准? 为了避免复杂性, JS ...
- 前端项目经验总结之js防缓存(避免缓存的影响)
一.问题描述:打包后的h5项目中有个server.js文件夹,这个文件夹有些时候用户更新了h5,但是加载的还是旧的server.js,所以怀疑是缓存的问题,为了避免缓存的影响所以要给server.js ...
- mac环境下mentohust锐捷登录配置
今天测试react native嵌入原生项目,账号流量恰好用完,想换同学账号却不会更改配置,以至于被网络弄得头疼了一中午.于是,好好研究了一下这个mentohust 一.需要下载的文件 我已经全部整理 ...
- jwplayer 限制拖动事件 快进 快退
开源精神不是ctrl +c + ctrl+v 谢谢 最近项目需要视频播放不能拖动,我已经实现即不能向前拖动,也不能向后拖动, 方法:打开用记事本 或者notepad 工具打开 jwpla ...
- 简单说说NoHTTP
学习NoHttp的原因是由于公司之前做的产品使用的网络请求框架一直都是Volley(为什么使用Volley就不用多说了,最起码是谷歌开发团队自己搞的,总感觉权威一些),可是自从android6.0推出 ...
- Material Design学习-----TextInputLayout
TextInputLayout是为EditText提供了一种新的实现和交互方式.在传统的EditText中存在一个hint属性,是说在editext中没有内容时,默认的提示信息.当想edittext中 ...
- Gradle之恋-任务2
由于任务作为Gradle的核心功能模块,多花点精力是值得的,本文继上一篇主要涉及到:任务的执行顺序.为任务添加组和描述.跳过任务.扩展任务属性.定义默认任务. 任务顺序 如果构建(build)不能在清 ...