进程管理利器Supervisor--centos7下安装与配置


声明:本文转载自https://my.oschina.net/u/2342969/blog/2986173,转载目的在于传递更多信息,仅供学习交流之用。如有侵权行为,请联系我,我会及时删除。

目录

  • 概述
  • 环境准备
  • 检查python环境
  • 在线安装
  • 配置Supervisor
  • 启动并验证
  • 运维命令

概述

    Supervisor的安装可以有在线安装和离线安装两种方式。安装方式取决于服务器是否联网,联网的话可采用在线安装,否则采用离线安装。

本文仅介绍在线安装方式

转帖请注明原贴地址: https://my.oschina.net/u/2342969/blog/2986173

环境准备

  1. 最小化安装centos7
  2. Supervisor3.3.4
  3. Python 2.4及以上, 注意:不能是python3

检查python环境

    一般centos7 自带python,通过 python -V 命令查看

执行命令结果如图:如果满足环境准备的python版本,则跳过此步,直接进行下一章安装

安装python2.7.5

#cd /opt/packages
#wget https://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz
#tar -zxvf Python-2.7.5.tgz
#cd Python-2.7.5
#./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
#make && sudo make altinstall

在线安装

    在线安装又有两种安装方式:

  • 使用Setuptools
  • 使用python安装

以上方式均需要服务器可以联网

使用Setuptools

    安装setuptools

#cd /opt/packages
#wget https://files.pythonhosted.org/packages/6e/9c/6a003320b00ef237f94aa74e4ad66c57a7618f6c79d67527136e2544b728/setuptools-40.4.3.zip
#unzip setuptools-40.4.3.zip
#cd setuptools-40.4.3
#python setup.py install

    安装supervisor

#easy_install supervisor

    通过安装日志可以发现安装路径为: /usr/bin/supervisor

使用python

#cd /opt/packages
#wget https://github.com/Supervisor/supervisor/archive/3.3.4.tar.gz
#tar zxvf 3.3.4
#cd supervisor-3.3.4/
#python setup.py install

    通过安装日志可以发现安装路径为: /usr/bin/supervisor

配置supervisor

    创建配置文件

#mkdir -p /etc/supervisor
#mkdir -p /etc/supervisor/conf.d
#echo_supervisord_conf > /etc/supervisor/supervisord.conf
#vim /etc/supervisor/supervisord.conf

配置内容如下:

# 启用访问web控制界面,inet_http_server区段修改为
[inet_http_server]         
port=*:9001        

# 修改log路径
[supervisord]
logfile=/var/log/supervisord.log

# 修改 unix_http_server file 路径,避免被系统删除
[unix_http_server]
file=/var/lock/supervisor.sock

# 和unix_http_server file保持一致
[supervisorctl]
serverurl=unix:///var/lock/supervisor.sock

# include区段修改为
[include]
files = /etc/supervisor/conf.d/*.conf

设置开机服务

#vim /etc/rc.d/init.d/supervisord

文件内容如下:

#!/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/init.d/functions

RETVAL=0
prog="supervisord"
pidfile="/tmp/supervisord.pid"
lockfile="/var/lock/supervisor.sock"

start()
{
        echo -n $"Starting $prog: "
        daemon --pidfile $pidfile supervisord -c /etc/supervisor/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

保存退出

增加开机服务

#chmod +x /etc/rc.d/init.d/supervisord
#chkconfig --add supervisord
#chkconfig supervisord on

启动服务并验证

#service supervisord start
#firewall-cmd --zone=public --add-port=9001/tcp --permanent
#firewall-cmd --reload

在浏览器输入 : http://ip:9001 ,查看是否可以正常访问,如果不能请再认真查看上述步骤

运维命令

# 查看程序状态
supervisorctl status

# 关闭程序
supervisorctl stop app-name

# 启动程序
supervisorctl start app-name

# 重启
supervisorctl restart app-name

# 读取有更新(增加)的配置文件,不会启动新添加的程序
supervisorctl reread

# 重启配置文件修改过的程序
supervisorctl update

 

本文发表于2018年12月10日 14:00
(c)注:本文转载自https://my.oschina.net/u/2342969/blog/2986173,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如有侵权行为,请联系我们,我们会及时删除.

阅读 1601 讨论 0 喜欢 0

抢先体验

扫码体验
趣味小程序
文字表情生成器

闪念胶囊

你要过得好哇,这样我才能恨你啊,你要是过得不好,我都不知道该恨你还是拥抱你啊。

直抵黄龙府,与诸君痛饮尔。

那时陪伴我的人啊,你们如今在何方。

不出意外的话,我们再也不会见了,祝你前程似锦。

这世界真好,吃野东西也要留出这条命来看看

快捷链接
网站地图
提交友链
Copyright © 2016 - 2021 Cion.
All Rights Reserved.
京ICP备2021004668号-1