Linux 后台进程管理器 supervisor 安装配置(使用httpd来做被监控进程)
2016-04-13 15:30
801 查看
在linux服务需要可靠的运行,并且服务exit后,需要自动重新启动起来,还可以监控进程状态,supervisor就是个不错的选项,supervisor是用python开发的一个进程管理器。下面是安装配置过程。
1.安装supervisor
easy_install supervisor SetupTool安装方法
apt-get install supervisor Debian/Ubuntu安装方法
yum install supervisor RedHat/Centos安装方法
2.生成默认配置文件
echo_supervisord_conf > /etc/supervisord.conf
3.修改/etc/supervisord.conf配置文件
如需要访问web控制界面,inet_http_server区段修改为
[inet_http_server]
port=0.0.0.0:9001
username=username ; 你的用户名
password=password ; 你的密码
4.修改启动脚本-将supervisord加入系统服务
#!/bin/sh
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36
# description: Supervisor Server
# processname: supervisord
# Source init functions
. /etc/init.d/functions
RETVAL=0
prog="supervisord"
pidfile="/tmp/supervisord.pid"
lockfile="/var/lock/subsys/supervisord"
start()
{
echo -n $"Starting $prog: "
daemon --pidfile $pidfile supervisord -c /etc/supervisord.conf
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch ${lockfile}
}
stop()
{
echo -n $"Shutting down $prog: "
killproc -p ${pidfile} /usr/bin/supervisord
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f ${lockfile} ${pidfile}
fi
}
case "$1" in
start)
start ;;
stop) stop ;;
status)
status $prog ;;
restart)
stop
start ;;
*)
echo "Usage: $0 {start|stop|restart|status}" ;;
esac
5.赋予权限加到开机启动
chmod +x /etc/init.d/supervisord
chkconfig supervisord on
service supervisord start
目前所有的supervisor基本的都完成,那么我现在用httpd来受被管理测试是否可以启动 并访问和exit后会不会自启动。
6.修改/etc/supervisord.conf在最后添加以下内容
[program:apache]
command=/usr/local/apache/bin/httpd -D FOREGROUND
autostart=true
autorestart=true
startsecs=3
user=root
7.重新加载配置文件是否80端口可以访问
service supervisord restart
日志显示正常:
CRIT Supervisor running as root (no user in config file)
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 4510
INFO spawned: 'apache' with pid 4512
INFO success: apache entered RUNNING state, process has stayed up for > than 3 seconds (startsecs)
8.测试服务
9.supervisor web测试是否显现正常
10.关闭掉httpd 看是否可以自启动起来
/usr/local/apache/bin/apachectl stop手动关闭掉httpd
看日志停止后又启动起来:
exited: apache (exit status 0; expected)
INFO spawned: 'apache' with pid 4640
INFO success: apache entered RUNNING state, process has stayed up for > than 3 seconds (startsecs)
另外一种配置文件方法(这样的方法适合多个服务好管理):
1. 修改配置文件 vim /etc/supervisord.conf
[include]
;files = relative/directory/*.ini
修改为:
[include]
;files = relative/directory/*.ini
files = /etc/supervisord.conf.d/*.conf
2. 创建被管理服务配置文件
Mkdir /etc/supervisord.conf.d/
Cd /etc/supervisord.conf.d/
Vim apache.conf
[program:apache]
command=/usr/local/apache/bin/httpd -D FOREGROUND
autostart=true
autorestart=true
startsecs=3
user=root
3. 常用命令
supervisorctl start apache
supervisorctl stop apache
supervisorctl status apache
本文出自 “风伯飞廉” 博客,请务必保留此出处http://gloryxin.blog.51cto.com/10134758/1763451
1.安装supervisor
easy_install supervisor SetupTool安装方法
apt-get install supervisor Debian/Ubuntu安装方法
yum install supervisor RedHat/Centos安装方法
2.生成默认配置文件
echo_supervisord_conf > /etc/supervisord.conf
3.修改/etc/supervisord.conf配置文件
如需要访问web控制界面,inet_http_server区段修改为
[inet_http_server]
port=0.0.0.0:9001
username=username ; 你的用户名
password=password ; 你的密码
4.修改启动脚本-将supervisord加入系统服务
#!/bin/sh
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36
# description: Supervisor Server
# processname: supervisord
# Source init functions
. /etc/init.d/functions
RETVAL=0
prog="supervisord"
pidfile="/tmp/supervisord.pid"
lockfile="/var/lock/subsys/supervisord"
start()
{
echo -n $"Starting $prog: "
daemon --pidfile $pidfile supervisord -c /etc/supervisord.conf
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch ${lockfile}
}
stop()
{
echo -n $"Shutting down $prog: "
killproc -p ${pidfile} /usr/bin/supervisord
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f ${lockfile} ${pidfile}
fi
}
case "$1" in
start)
start ;;
stop) stop ;;
status)
status $prog ;;
restart)
stop
start ;;
*)
echo "Usage: $0 {start|stop|restart|status}" ;;
esac
5.赋予权限加到开机启动
chmod +x /etc/init.d/supervisord
chkconfig supervisord on
service supervisord start
目前所有的supervisor基本的都完成,那么我现在用httpd来受被管理测试是否可以启动 并访问和exit后会不会自启动。
6.修改/etc/supervisord.conf在最后添加以下内容
[program:apache]
command=/usr/local/apache/bin/httpd -D FOREGROUND
autostart=true
autorestart=true
startsecs=3
user=root
7.重新加载配置文件是否80端口可以访问
service supervisord restart
日志显示正常:
CRIT Supervisor running as root (no user in config file)
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 4510
INFO spawned: 'apache' with pid 4512
INFO success: apache entered RUNNING state, process has stayed up for > than 3 seconds (startsecs)
8.测试服务
9.supervisor web测试是否显现正常
10.关闭掉httpd 看是否可以自启动起来
/usr/local/apache/bin/apachectl stop手动关闭掉httpd
看日志停止后又启动起来:
exited: apache (exit status 0; expected)
INFO spawned: 'apache' with pid 4640
INFO success: apache entered RUNNING state, process has stayed up for > than 3 seconds (startsecs)
另外一种配置文件方法(这样的方法适合多个服务好管理):
1. 修改配置文件 vim /etc/supervisord.conf
[include]
;files = relative/directory/*.ini
修改为:
[include]
;files = relative/directory/*.ini
files = /etc/supervisord.conf.d/*.conf
2. 创建被管理服务配置文件
Mkdir /etc/supervisord.conf.d/
Cd /etc/supervisord.conf.d/
Vim apache.conf
[program:apache]
command=/usr/local/apache/bin/httpd -D FOREGROUND
autostart=true
autorestart=true
startsecs=3
user=root
3. 常用命令
supervisorctl start apache
supervisorctl stop apache
supervisorctl status apache
本文出自 “风伯飞廉” 博客,请务必保留此出处http://gloryxin.blog.51cto.com/10134758/1763451
相关文章推荐
- 机器学习算法汇总:人工神经网络、深度学习及其它
- 使用Volley执行网络数据传输
- BPFP系列:优化电池使用时间:确定和监控网络连接状态
- 初探网络性能测试
- Ubuntu无法正常连接无线网络
- 仿iOS的网络请求的加载框
- Hyperscan 介绍与安装
- WARN (org.apache.commons.httpclient.HttpMethodBase:1511) - Cookie rejected 警告
- Linux网络编程--recv函数返回值详解
- 使用Jmeter进行http接口测试
- 使用SSH设置映射端口跳转,解决网络限制问题
- tomcat下配置https
- 通过SecureCRT设置代理,访问网络中web界面
- 从网上整理了一些关于比较时间大小和请求网络时间的代码,在这里展示一下
- tcp/ip三次握手
- 2015年ACM-ICPC亚洲区域赛合肥站网络预选赛H题——The Next (位运算)
- nagios网络流量监控(附pnp模板)
- 计算机网络学习笔记--数据链据层上的设备详解
- TCP/IP(十二)TCP的超时与重传
- Openwrt上Php+Mysql+Lighttpd的安装配置