您现在的位置是:首页 > 文章详情

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

日期:2018-12-10点击:604

目录

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

概述

    了解supervisor基本概念,请点击查看进程管理利器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

 

原文链接:https://my.oschina.net/u/2342969/blog/2986173
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章