非常实用的Linux 进程监控工具---Supervisor(一)

Supervisor是一款用Python开发的进程管理工具,能监控并自动重启异常退出的子进程。支持通过fork/exec方式启动子进程,配置文件可自定义监控策略,如自动重启、日志管理和Web管理界面。

简述:

Supervisor 是用Python开发的通用进程管理程序,能将一个普通的命令行进程变为其子进程,并监控进程状态,异常退出时能自动重启。通过fork/exec的方式将这些被管理的进程当作supervisor的子进程来启动,允许其用户控制类似UNIX的操作系统上的许多进程。Supervisord将进程作为其子进程启动,并且可以配置为在崩溃时自动重新启动它们。也可以将其自动配置为自行调用启动进程。被管理进程被视为supervisor的子进程,若该子进程异常中断,则父进程可以准确的获取子进程异常中断的信息,通过在配置文件中配置 autostart=ture,来实现对异常退出的子进程进行自动重启。

一、安装

安装Supervisor 官方有两种,详细参见 Installing,我通过离线方式安装 Supevisor ,需要准备 依赖:[meld3-2.0.1.tar.gz] (meld3软件包不再是Supervisor 4.1.0以后版本的依赖项,即不需要安装)(https://files.pythonhosted.org/packages/53/af/5b8b67d04a36980de03505446d35db39c7b2a01b9bac1cb673434769ddb8/meld3-2.0.1.tar.gz)
以及Supervisor 源码包,Supervisor

1.1 安装环境要求:

  1. CentOS 7 默认安装
  2. Python 2.4+ 即可,本地 Python 2.7.5 (default, Oct 30 2018, 23:45:53)
  3. Supervisor-4.1.0.tar.gz 源码文件

1.2 Supervisor 安装:

1. 解压源码包

// 解压Supervisor 源码包
[root@localhost Supervisor]# tar -xvf supervisor-4.1.0.tar.gz
[root@localhost Supervisor]# cd supervisor-4.1.0/
[root@localhost supervisor-4.1.0]# ls
CHANGES.rst    docs          MANIFEST.in  setup.cfg  supervisor
COPYRIGHT.txt  LICENSES.txt  README.rst   setup.py   tox.ini

2. 源码安装Supervisor 应用

[root@localhost supervisor-4.1.0]# python setup.py install
......
Installed /usr/lib/python2.7/site-packages/supervisor-4.1.0-py2.7.egg
Processing dependencies for supervisor==4.1.0
Finished processing dependencies for supervisor==4.1.0 # 安装完成

3. 安装meld 依赖

Supervisor 4.1.0 以前的版本会要求该依赖,否则会安装 Error,安装方法如下:

[root@localhost supervisor-4.1.0]# cd ../meld3-2.0.1/
[root@localhost meld3-2.0.1]# python setup.py install
....
Installed /usr/lib/python2.7/site-packages/meld3-2.0.1-py2.7.egg
Processing dependencies for meld3==2.0.1
Finished processing dependencies for meld3==2.0.1

二、supervisord 配置文件

默认没有配置文件,我们可以通过 echo_supervisord_conf,生成默认的Supervisor 配置文件;

[root@localhost meld3-2.0.1]# mkdir /etc/supervisord
[root@localhost meld3-2.0.1]# echo_supervisord_conf > /etc/supervisord/supervisord.conf

默认参数解析:

[root@localhost meld3-2.0.1]# cat /etc/supervisord/supervisord.conf
; 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 ".
;
; 注意上面的提示:- 配置文件不支持Shell 的声明、环境变量,可以通过 "%(ENV_HOME)s"使用变量
;     			 - 不支持引号的值,可以通过等
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值