了解supervisor基本概念,请点击查看进程管理利器Supervisor--入门简介 python
Supervisor的安装能够有在线安装和离线安装两种方式。安装方式取决于服务器是否联网,联网的话可采用在线安装,不然采用离线安装。git
本文仅介绍在线安装方式github
转帖请注明原贴地址: https://my.oschina.net/u/2342969/blog/2986173web
通常centos7 自带python,经过 python -V 命令查看vim
执行命令结果如图:若是知足环境准备的python版本,则跳过此步,直接进行下一章安装centos
#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
在线安装又有两种安装方式:浏览器
以上方式均须要服务器能够联网bash
#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
#easy_install supervisor
经过安装日志能够发现安装路径为: /usr/bin/supervisor服务器
#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/supervisorapp
建立配置文件
#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