CentOS6下supervisor进程守护安装及使用教程

  • A+

最近服务器的Sunny进程总是会挂掉,查看通过查看日志,发现是因为内存不足,被系统给Kill了,如图;因为内存本身比较小,担心还会出这种情况,打算采用supervisor进程守护解决Sunny进程被kill后,需要手动重启该进程的问题。

查看日志命令:
cat /var/log/messages

一、Supervisor的安装
Supervisor是基于python开发的,安装Supervisor前,需要先安装python,Supervisor可以通过pip或者easy_install安装。
通过easy_install安装

yum install python-setuptools
easy_install supervisor

具体可参看官方文档http://supervisord.org/installing.html

二、supervisor的使用
安装完执行以下命令:

echo_supervisord_conf > /etc/supervisord.conf

随后我们对生成的配置文件进行编辑,主要修改最后两行,我这里修改为:

[include]
files = /etc/supervisor/*.ini

根据修改的内容,我们要在/etc/supervisor目录下创建需要监控的配置文件,这里以Sunny为例,创建Sunny.ini内容如下:

[program:sunny]
//需要注意,commond这里不能使用service xxx start | stop |restart |reload 等命令
command=/sunny
autostart=true
autorestart=true
user=root
numprocs=1
stdout_logfile=/var/log/sunny.log

然后启动supervisor,启动命令有多种,可以自行尝试,我这里使用的是:

supervisord -c /etc/supervisord.conf

然后执行命令:

supervisorctl status

得到如下:

sunny RUNNING pid 26799, uptime 0:0:11

表示启动成功,我们尝试使用 kill -9 26799结束sunny进程后,在执行ps -ef |grep sunny会发现服务已经自动重启,至此supervisor进程守护配置完毕。

下载服务恢复

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

Blue Captcha Image
Refresh

*