http://zhangweide.cn/archive/2013/supervisor-note.html

Supervisord

supervisord的出现,结束了我这苦恼的问题,它可以帮你守护任何进程,当然如果它的进程也挂了就全都over了。实际情况是上线三个多月运行非常好,没有发现进程掉过。

CentOS下安装Supervisord

# yum install python-setuptools
# easy_install supervisor

创建配置文件

# echo_supervisord_conf > /etc/supervisord.conf

修改配置文件

# vi /etc/supervisord.conf

在末尾添加

1
2
3
4
5
6
[program:chat]
command=python /data0/htdocs/chat/main.py
priority=1
numprocs=1
autostart=true
autorestart=true

配置说明:

command  要执行的命令
priority  优先级
numprocs 启动几个进程
autostart  supervisor启动的时候是否随着同时启动
autorestart 当程序over的时候,这个program会自动重启,一定要选上

启动Supervisord

# supervisord

查看帮助

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[root@localhost core]# supervisord --help
supervisord -- run a set of applications as daemons.
 
Usage: /usr/bin/supervisord [options]
 
Options:
-c/--configuration FILENAME -- configuration file
-n/--nodaemon -- run in the foreground (same as 'nodaemon true' in config file)
-h/--help -- print this usage message and exit
-v/--version -- print supervisord version number and exit
-u/--user USER -- run supervisord as this user (or numeric uid)
-m/--umask UMASK -- use this umask for daemon subprocess (default is 022)
-d/--directory DIRECTORY -- directory to chdir to when daemonized
-l/--logfile FILENAME -- use FILENAME as logfile path
-y/--logfile_maxbytes BYTES -- use BYTES to limit the max size of logfile
-z/--logfile_backups NUM -- number of backups to keep when max bytes reached
-e/--loglevel LEVEL -- use LEVEL as log level (debug,info,warn,error,critical)
-j/--pidfile FILENAME -- write a pid file for the daemon process to FILENAME
-i/--identifier STR -- identifier used for this instance of supervisord
-q/--childlogdir DIRECTORY -- the log directory for child process logs
-k/--nocleanup --  prevent the process from performing cleanup (removal of
                   old automatic child log files) at startup.
-a/--minfds NUM -- the minimum number of file descriptors for start success
-t/--strip_ansi -- strip ansi escape codes from process output
--minprocs NUM  -- the minimum number of processes available for start success
--profile_options OPTIONS -- run supervisord under profiler and output
                             results based on OPTIONS, which  is a comma-sep'd
                             list of 'cumulative', 'calls', and/or 'callers',
                             e.g. 'cumulative,callers')

启动时指定配置文件

# supervisord -c /etc/supervisord.conf

进入ctl模式

# supervisorctl

ctl中的简单命令

help 查看命令帮助
status  查看状态
stop  XXX  停止某一个进程
start  XXX  启动某个进程
restart  XXX  重启某个进程
reload  载入最新的配置文件,停止原有进程并按新的配置启动、管理所有进程
update 根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启。

测试

这里以守护nginx进程来演示,首先在/etc/supervisord.conf加入

1
2
3
4
5
6
[program:nginx]
command=/usr/local/nginx/sbin/nginx
priority=1
numprocs=1
autostart=true
autorestart=true

然后启动supervisord

1
2
3
[root@localhost core]# supervisord -c /etc/supervisord.conf
[root@localhost core]# ps -le | grep supervisord           
1 S     0 14035     1  0  80   0 - 48722 poll_s ?        00:00:00 supervisord

查看nginx的进程

1
2
3
4
5
[root@localhost core]# ps -le | grep nginx
1 S     0 14037     1  0  80   0 - 56260 rt_sig ?        00:00:00 nginx
5 S    99 14038 14037  0  80   0 - 56363 ep_pol ?        00:00:00 nginx
5 S    99 14039 14037  0  80   0 - 56300 ep_pol ?        00:00:00 nginx
5 S    99 14040 14037  0  80   0 - 56300 ep_pol ?        00:00:00 nginx

杀掉nginx进程

1
[root@localhost core]# kill -9 14037

然后接着重新查看nginx进程

1
2
3
4
[root@localhost core]# ps -le | grep nginx
5 S    99 14038     1  0  80   0 - 56363 ep_pol ?        00:00:00 nginx
5 S    99 14039     1  0  80   0 - 56300 ep_pol ?        00:00:00 nginx
4 S     0 14456 14035  0  80   0 - 56259 hrtime ?        00:00:00 nginx

起死回生了,并且pid已经由14037变成14038。搞定!

通过web管理

supervisord可以通过web管理进程以及查看进程状态,需要在配置文件里开启

找到[inet_http_server]这一段,修改成

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

其中port这个字段要各位注意,如果*:9001表示允许所有ip访问,如果指定单个IP可以 xx.xx.xx.xx:9001 这样既可。如果你开启了iptabls记得要在规则里允许port指定的端口号。

然后保存配置,重启supervisord

https://github.com/mlazarov/supervisord-monitor

Supervisord安装和配置的更多相关文章

  1. Linux 进程管理工具 supervisord 安装及使用

    Supervisor是用Python实现的一款非常实用的进程管理工具 1.安装过程非常简单 安装python 安装meld3-0.6.8.tar.gz 安装supervisor-3.0a12.tar. ...

  2. elasticsearch5之Elastalert 安装使用 配置邮件报警和微信报警

    简介 Elastalert是用python2写的一个报警框架(目前支持python2.6和2.7,不支持3.x),github地址为 https://github.com/Yelp/elastaler ...

  3. Supervisor安装与配置(Linux/Unix进程管理工具)

    原文链接:http://blog.csdn.net/xyang81/article/details/51555473 Supervisor(http://supervisord.org/)是用Pyth ...

  4. Supervisor(Linux/Unix进程管理工具)安装与配置

    参考链接:https://blog.csdn.net/xyang81/article/details/51555473 Supervisor(http://supervisord.org/)是用Pyt ...

  5. Supervisor安装与配置

    Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统 ...

  6. CentOS7下Supervisor安装与配置

    Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统 ...

  7. Supervisor 的安装与配置教程

    简介 Supervisor是一个进程控制系统. 它是一个C/S系统(注意: 其提供WEB接口给用户查询和控制), 它允许用户去监控和控制在类UNIX系统的进程. 它的目标与launchd, daemo ...

  8. JDK安装与配置

    JDK安装与配置 一.下载 JDK是ORACLE提供免费下载使用的,官网地址:https://www.oracle.com/index.html 一般选择Java SE版本即可,企业版的选择Java ...

  9. Node.js 教程 01 - 简介、安装及配置

    系列目录: Node.js 教程 01 - 简介.安装及配置 Node.js 教程 02 - 经典的Hello World Node.js 教程 03 - 创建HTTP服务器 Node.js 教程 0 ...

随机推荐

  1. “全栈2019”Java多线程第十八章:同步代码块双重判断详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...

  2. Storm-kafka源码分析之Config相关类

    要创建一个KafkaSpout对象,必须要传入一个SpoutConfig对象,KafkaSpout的构造函数定义如下: public KafkaSpout(SpoutConfig spoutConf) ...

  3. String 在内存中如何存储的

    基本数据类型由于长度固定,且需要空间比较少,所以直接存储在栈中:而对象比较大,所以栈中只存储一个4btye的引用地址(逻辑地址). java中对String对象特殊对待,所以在heap区域分成了两块: ...

  4. 直接访问实例变量 VS 通过点语法访问实例变量

    直接访问实例变量,不会经过 OC 的方法派发机制,速度比较块.会直接访问对象的实例变量对应的内存. 直接访问实例变量,不会调用"设置方法".绕过了相关属性对应的"内存管理 ...

  5. python学习笔记02-编码

    ASCII码  255个  每一个占1个字节 8位 解决中文的问题:出现一张扩展表  支持中文的第一张表  gb2312  后来发展为GBK1.0 Gb18030 万国码:unicode 世界统一 存 ...

  6. 【GDOI2015】 水题 tarjan缩点

    这一题,我当年只会$60$分做法..... 我们考虑对原图跑一波边双,然后缩成一个森林. 对于森林中的每一棵树,我们钦定一个根. 令$siz[x]$表示以$x$为根的子树中,在原图中点的个数. 令当前 ...

  7. EJB3 jpa 数据库表的映射关系

    1)多对一映射关系(单向) 使用外键关联,在外键的选取上以多的一方为主,即外键要在多的一方体现出来 @Entity public class Company implements Serializab ...

  8. Java之IO(六)FileInputStream和FileOutputStream

    转载请注明源出处:http://www.cnblogs.com/lighten/p/7001458.html 1.前言 前五章按照JDK的类顺序介绍了几种流,第五章讲了Java的文件系统.本章介绍Ja ...

  9. https数字证书交换过程介绍

    文章转自:https://www.2cto.com/kf/201804/739010.html,感谢原作者的辛苦整理,讲解的很清楚,谢谢. [https数字证书交换过程介绍] 注意:该问的背景用到了非 ...

  10. oracle_jdbc_Query

    本例子程序是根据马士兵老师所讲+自己的注释.写的比较全面,特别是最后释放资源的代码. package com.ayang.jdbc; import java.sql.*; public class T ...