在centos上安装最新版supervisord后台服务

#安装python的安装工具pip
wget http://mirrors.opencas.cn/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpm
yum -y install python-pip

#安装supervisord
pip install supervisor

#测试安装是否成功
echo_supervisord_conf

#创建配置文件
mkdir -p /etc/supervisor
mkdir -m 755 -p /etc/supervisor/
echo_supervisord_conf > /etc/supervisord.conf
sed -i "s/\;\[include\]/\[include\]/" /etc/supervisord.conf
echo "files = /etc/supervisor/*.conf" >> /etc/supervisord.conf 

########################################################

#在centos 7.x下创建服务
cat > /usr/lib/systemd/system/supervisord.service << EOF
[Unit]
Description=Supervisor daemon

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s
SysVStartPriority=99

[Install]
WantedBy=multi-user.target
EOF
systemclt enable supervisord

########################################################

#在centos 6.x下创建服务

cat > /etc/init.d/supervisord << EOF
#!/bin/sh
#
# /etc/rc.d/init.d/supervisord
#
# 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/rc.d/init.d/functions


prog="supervisord"


prefix="/usr/"
exec_prefix="${prefix}"
prog_bin="${exec_prefix}/bin/supervisord"
PIDFILE="/var/run/$prog.pid"


start()
{
        echo -n $"Starting $prog: "
        daemon $prog_bin --pidfile $PIDFILE
        [ -f $PIDFILE ] && success $"$prog startup" || failure $"$prog startup"
        echo
}


stop()
{
        echo -n $"Shutting down $prog: "
        [ -f $PIDFILE ] && killproc $prog || success $"$prog shutdown"
        echo
}


case "$1" in


  start)
    start
  ;;


  stop)
    stop
  ;;


  status)
        status $prog
  ;;


  restart)
    stop
    start
  ;;


  *)
    echo "Usage: $0 {start|stop|restart|status}"
  ;;


esac
EOF

chmod +x /etc/init.d/supervisord
chkconfig --add supervisord
chkconfig supervisord --level 2345 on

########################################################

# 创建一个监听端口为6380、非后台服务的redis配置文件
cat > /etc/redis/redis-6380.conf << EOF
daemonize no
pidfile /var/run/redis_6380.pid
port 6380
logfile /var/log/redis_6380.log
dir /var/lib/redis/6380
EOF

#创建被监控应用的配置
cat > /etc/supervisor/redis-6380.conf << EOF
[program:redis-6380]
command=/usr/local/bin/redis-server /etc/redis/6380.conf
numprocs=1                    ; 启动几个进程
autostart=true                ; 随着supervisord的启动而启动
autorestart=true              ; 自动重启。。当然要选上了
startretries=10               ; 启动失败时的最多重试次数
exitcodes=0                   ; 正常退出代码(是说退出代码是这个时就不再重启了吗?待确定)
stopsignal=KILL               ; 用来杀死进程的信号
stopwaitsecs=10               ; 发送SIGKILL前的等待时间
redirect_stderr=true          ; 重定向stderr到stdout
EOF

#重启supervisord
supervisorctl reload

# 查看redis进程号
ps aux | grep redis | grep -v grep
# 输出为:root      4290  0.3  0.3 140836  7860 ?        Sl   23:40   0:00 /usr/local/bin/redis-server *:6380

# 杀死这个redis进程
kill  `ps aux | grep redis | grep -v grep | awk '{print $2}'`

# 查看redis新的进程号
ps aux | grep redis | grep -v grep
# 输出为:root      1040  0.1  0.3 140836  7860 ?        Sl   23:48   0:00 /usr/local/bin/redis-server *:6380
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值