進程管理利器Supervisor--centos7下安裝與配置

目錄

  • 概述
  • 環境準備
  • 檢查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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章