supervisor安装配置与使用
supervisor:C/S架构的进程控制系统,可使用户在类UNIX系统中监控、管理进程。常用于管理与某个用户或项目相关的进程。
组成部分
supervisord:服务守护进程
supervisorctl:命令行客户端
Web Server:提供与supervisorctl功能相当的WEB操作界面
XML-RPC Interface:XML-RPC接口
安装
CentOS平台下可直接用过YUM源安装
yum info supervisor
sudo yum install supervisor
sudo chkconfig supervisord on
服务器启停
sudo /etc/init.d/supervisord {start|stop|status|restart|reload|force-reload|condrestart}
日志
/var/log/supervisor/supervisord.log
配置文件
sudo vim /etc/supervisord.conf
需要重点关注的是以部分
[program:x]中配置要监控的进程
配置样例
[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 ; (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")
; 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:example]
;command=/bin/echo; 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)
;startsecs=10 ; number of secs prog must stay running (def. 10)
;startretries=3 ; max # of serial start failures (default 3)
;exitcodes=0,2 ; 'expected' exit codes for process (default 0,2)
;stopsignal=QUIT ; signal used to kill process (default TERM)
;stopwaitsecs=10 ; max num secs to wait before SIGKILL (default 10)
;user=chrism ; setuid to this UNIX account to run the program
;log_stdout=true ; if true, log program stdout (default true)
;log_stderr=true ; if true, log program stderr (def false)
;logfile=/var/log/supervisor.log ; child log path, use NONE for none; default AUTO
;logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;logfile_backups=10 ; # of logfile backups (default 10)
“;”为注释。各参数的含义都很明确。可以根据官方手册结合实验来进一步深入了解。重点说几个[program:example]中的参数
;command=/bin/echo; supervisor启动时将要开启的进程。相对或绝对路径均可。若是相对路径则会从supervisord的$PATH变中查找。命令可带参数。
;priority=999 指明进程启动和关闭的顺序。低优先级表明进程启动时较先启动关闭时较后关闭。高优先级表明进程启动时启动时较后启动关闭时较先关闭。
;autostart=true 是否随supervisord启动而启动
;autorestart=true 进程意外退出后是否自动重启
;startsecs=10 进程持续运行多久才认为是启动成功
;startretries=3 重启失败的连续重试次数
;exitcodes=0,2 若autostart设置为unexpected且监控的进程并非因为supervisord停止而退出,那么如果进程的退出码不在exitcode列表中supervisord将重启进程
;stopsignal=QUIT 杀进程的信号
;stopwaitsecs=10 向进程发出stopsignal后等待OS向supervisord返回SIGCHILD 的时间。若超时则supervisord将使用SIGKILL杀进程
一个Rabbitmq项目中生产者和消费者进程使用supervisor监控的配置情况:(配置中的其他部分略)
[program:worker_for_summary]
command=/home/op1/scripts/rabbitmqclient/worker_for_summary.py
priority=1
log_stderr=true ; if true, log program stderr (def false)
[program:worker_for_detail_all]
command=/home/op1/scripts/rabbitmqclient/worker_for_detail_all.py
priority=1
log_stderr=true ; if true, log program stderr (def false)
[program:worker_for_detail_recent_list]
command=/home/op1/scripts/rabbitmqclient/worker_for_detail_recent_list.py
priority=1
log_stderr=true ; if true, log program stderr (def false)
[program:worker_for_detail_recent_sset]
command=/home/op1/scripts/rabbitmqclient/worker_for_detail_recent_sset.py
priority=1
log_stderr=true ; if true, log program stderr (def false)
[program:publisher_for_summary]
command=/home/op1/scripts/rabbitmqclient/publisher_for_summary.py
priority=999
log_stderr=true ; if true, log program stderr (def false)
[program:publisher_for_summary_nt]
command=/home/op1/scripts/rabbitmqclient/publisher_for_summary_nt.py
priority=999
log_stderr=true ; if true, log program stderr (def false)
[program:publisher_for_detail]
command=/home/op1/scripts/rabbitmqclient/publisher_for_detail.py
priority=999
log_stderr=true ; if true, log program stderr (def false)
[program:publisher_for_detail_nt]
command=/home/op1/scripts/rabbitmqclient/publisher_for_detail_nt.py
priority=999
log_stderr=true ; if true, log program stderr (def false)
配置完成后启动supervisord'
sudo /etc/init.d/supervisord start
可以看到配置的各个进程在后台运行了起来。
停掉某个进程后supervisor会马上重启该进程
停止supervisor
sudo /etc/init.d/supervisord stop
可以看到配置的各个进程都停止运行了。
可以通过supervisorctl查看管理监控的进程情况:
[op1@SVR1631HP360 ~]$ sudo supervisorctl
publisher_for_detail RUNNING pid 27557, uptime 0:00:45
publisher_for_detail_nt RUNNING pid 27567, uptime 0:00:45
publisher_for_summary RUNNING pid 27566, uptime 0:00:45
publisher_for_summary_nt RUNNING pid 27568, uptime 0:00:45
worker_for_detail_all RUNNING pid 27581, uptime 0:00:45
worker_for_detail_recent RUNNING pid 27582, uptime 0:00:45
worker_for_summary RUNNING pid 27559, uptime 0:00:45
#可通过help了解命令的更多用法
supervisor> help
Documented commands (type help <topic>):
========================================
EOF exit maintail quit restart start stop
clear help open reload shutdown status tail
supervisor> help stop
stop <processname> Stop a process.
stop <processname> <processname> Stop multiple processes
stop all Stop all processes
When all processes are stopped, they are stopped in
reverse priority order (see config file)
supervisor> help status
status Get all process status info.
status <name> Get status on a single process by name.
status <name> <name> Get status on multiple named processes.
#停止某个进程
supervisor> stop publisher_for_summary
publisher_for_summary: stopped
#查看此时此刻的状态
supervisor> status
publisher_for_detail RUNNING pid 27557, uptime 0:05:41
publisher_for_detail_nt RUNNING pid 27567, uptime 0:05:41
publisher_for_summary STOPPED Feb 27 02:48 PM
publisher_for_summary_nt RUNNING pid 27568, uptime 0:05:41
worker_for_detail_all RUNNING pid 27581, uptime 0:05:41
worker_for_detail_recent RUNNING pid 27582, uptime 0:05:41
worker_for_summary RUNNING pid 27559, uptime 0:05:41
#发现被supervisorctl停掉的进程不会被自动重启
#开启刚才停掉的进程
supervisor> start publisher_for_summary
publisher_for_summary: started
supervisor> status
publisher_for_detail RUNNING pid 27557, uptime 0:08:02
publisher_for_detail_nt RUNNING pid 27567, uptime 0:08:02
publisher_for_summary RUNNING pid 3035, uptime 0:00:04
publisher_for_summary_nt RUNNING pid 27568, uptime 0:08:02
worker_for_detail_all RUNNING pid 27581, uptime 0:08:02
worker_for_detail_recent RUNNING pid 27582, uptime 0:08:02
worker_for_summary RUNNING pid 27559, uptime 0:08:02
#停掉所有进程
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 27 02:51 PM
publisher_for_detail_nt STOPPED Feb 27 02:51 PM
publisher_for_summary STOPPED Feb 27 02:51 PM
publisher_for_summary_nt STOPPED Feb 27 02:51 PM
worker_for_detail_all STOPPED Feb 27 02:51 PM
worker_for_detail_recent STOPPED Feb 27 02:51 PM
worker_for_summary STOPPED Feb 27 02:51 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 5111, uptime 0:00:15
publisher_for_detail_nt RUNNING pid 5141, uptime 0:00:15
publisher_for_summary RUNNING pid 5135, uptime 0:00:15
publisher_for_summary_nt RUNNING pid 5147, uptime 0:00:15
worker_for_detail_all RUNNING pid 5153, uptime 0:00:15
worker_for_detail_recent RUNNING pid 5159, uptime 0:00:14
worker_for_summary RUNNING pid 5112, uptime 0:00:15
更多内容请参考官方手册
http://supervisord.org/
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-04/116701.htm
supervisor安装配置与使用的更多相关文章
- .Net Core Linux部署之进程守护 Supervisor 安装配置
1.Supervisor 安装 //安装easy_install yum install python-setuptools //安装Supervisor easy_install superviso ...
- supervisor 安装 配置 及 使用
supervisor是微软官方推荐的一个工具,传送门, 所以我们也使用这个工具来管理我们的asp.net core应用进程 服务器环境:ubuntu14.04 x64 安装 apt-get ...
- supervisor安装配置
1.安装 下载:https://codeload.github.com/Supervisor/supervisor/zip/3.1.3 2.安装 .zip cd supervisor- python ...
- supervisor 安装配置
Supervisor介绍 Supervisor 允许其用户在UNIX类操作系统上控制多个进程. 块如下: 方便 需要为每个进程实例编写rc.d脚本通常是不方便的. rc.d脚本是进程初始化/自动启动/ ...
- supervisor 安装配置详解
一.安装 源码安装 先下载最新的supervisor安装包:https://pypi.python.org/pypi/supervisor , 如: (python3命令为 pip install g ...
- CentOS7下Supervisor安装与配置
Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统 ...
- supervisor安装和配置
直接命令 easy_install supervisor 如果报错先安装 yum install python-setuptools,再上面一条命令: 安装成功后显示finished,我们再次进行py ...
- mac下supervisor安装及简单配置
supervisor是一个用 Python 写的进程管理工具,可以很方便的用来启动.重启.关闭进程(守护进程).可以用他来管理自己的“服务程序”. 安装 首先安装Python,Mac系统好像自带. 执 ...
- Supervisor安装与配置(Linux/Unix进程管理工具)
原文链接:http://blog.csdn.net/xyang81/article/details/51555473 Supervisor(http://supervisord.org/)是用Pyth ...
随机推荐
- Unity中通过类名字符串取组件类型的方法(Types.GetType用法)
正常调用Type.GetType取不到组件,因为会先创建实例在获取,而Unity组件无法通过new来创建. 第二种创建方式是通过程序集,具体如下 Assembly.GetExecutingAssemb ...
- Android--菜单详解
Android中的菜单分为三种,即选项菜单(系统菜单),上下文菜单和弹出式菜单. 选项菜单: 一个activity只有一个选项菜单,选项菜单的创建方式有低版本创建和高版本创建两种.最常用的是干版本创建 ...
- ado.net C#如何实现数据库增删改查
ado.net数据库访问技术将数据库中的数据,提取到内存中,展示给用户看还可以将内存中的数据写入数据库中去 并不是唯一的数据库访问技术,但是它是最底层的数据库访问技术也就是说是最麻烦但是是最不可缺少的 ...
- Linux下内存占用和CPU占用的计算
->使用free命令查看内存使用情况: 1.echo 3 > /proc/sys/vm/drop_caches 2.free 或者使用cat /proc/yourpid/status 来查 ...
- IE7下总提示" 缺少标识符、字符串或数字"
用Jquery easyUI ,IE7下列表显示不了,总提示缺少标识符.字符串或数字.而google,maxthon,firefox,IE10等却没有问题. 原因是Json末尾多了个逗号.IE7下js ...
- macaca运行报错之chrome-driver问题处理,关闭 Chrome 的自动更新
由于chrome浏览器自动更新,导致 macaca运行报错,重新安装和更新chrome-driver 之后,还需要把chrome浏览器降级到50版本: 但是chrome会自动更新,所以需要禁止.找到这 ...
- WCF 4.0 进阶系列 -- 随笔汇总
WCF4.0 进阶系列–前言 WCF4.0 进阶系列--第一章 WCF简介 WCF4.0进阶系列--第二章 寄宿WCF服务 WCF4.0进阶系列--第三章 构建健壮的程序和服务 WCF4.0进阶系列- ...
- 【PHP】基于ThinkPHP框架搭建OAuth2.0服务
[PHP]基于ThinkPHP框架搭建OAuth2.0服务 http://leyteris.iteye.com/blog/1483403
- redis.conf 配置详解 (转)
# Redis 配置文件 # 当配置中需要配置内存大小时,可以使用 1k, 5GB, 4M 等类似的格式,其转换方式如下(不区分大小写)## 1k => 1000 bytes# 1kb => ...
- laravel Ajax post方式的使用
以jquery ajax 的post的方式为例 验证邮箱输入格式是否正确 html <div class="fl"> <input type="emai ...