瞭解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