Supervisor 安裝

Supervisor


Supervisor

一個運行在類Unix系統(tǒng)下的進(jìn)程管理系統(tǒng)工具

  • 由Python進(jìn)行編寫

  • 采用C/S結(jié)構(gòu):

    • supervisord是服務(wù)進(jìn)程
    • supervisorctl是客戶端管理工具
  • 使用ini格式的配置文件


Supervisor 發(fā)布?xì)v史

  • 3.3.1 (2016-08-02) 最新版
  • 3.0 (2013-07-30)
  • 2.0 (2006-08-30)
  • 1.0.5 (2004-07-29)

Release History


安裝

推薦環(huán)境

安裝步驟

!bash
# 確認(rèn)環(huán)境
[root@localhost ~]# cat /etc/redhat-release 
CentOS release 6.8 (Final)
[root@localhost ~]# python -V
Python 2.7.8
# 使用pip進(jìn)行安裝
[root@localhost ~]# pip install supervisor
Collecting supervisor
  Downloading supervisor-3.3.1.tar.gz (415kB)
    100% |████████████████████████████████| 419kB 659kB/s 
Collecting meld3>=0.6.5 (from supervisor)
  Downloading meld3-1.0.2-py2.py3-none-any.whl
...
Successfully installed meld3-1.0.2 supervisor-3.3.1

配置服務(wù)

supervisor 配置文件: supervisord.conf 。supervisordsupervisorctl 都會使用這個文件。

!bash
echo_supervisord_conf > /etc/supervisord.conf
mkdir /etc/supervisord/

include 分段

# 支持多級文件配置
vi /etc/supervisord.conf
...
; last line
[include]
files = /etc/supervisord/*.ini

參考 include Section Settings


配置 supervisord 服務(wù)自動運行腳本

!bash
[root@localhost ~]# wget https://raw.githubusercontent.com/Supervisor/initscripts/master/redhat-init-mingalevme -O /etc/init.d/supervisord
[root@localhost ~]# chmod +x /etc/init.d/supervisord
[root@localhost ~]# chkconfig --add supervisord
[root@localhost ~]# chkconfig --level 2345 supervisord on


#supervisord腳本配置
#PREFIX=/usr
PREFIX=/opt/rh/python27/root/usr

運行服務(wù)

啟動

[root@localhost ~]# service supervisord start

service 報錯

  # service supervisord status
/opt/rh/python27/root/usr/bin/python2: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

解決方法:
在/etc/ld.so.conf.d/目錄下新建一個conf配置文件,起名為python2.7.conf
將python2.7的庫目錄放入到python2.7.conf中
/opt/python2.7/lib
保存后,運行l(wèi)dconfig,就可以了

管理

!bash
[root@localhost ~]# supervisorctl status
confluence                       RUNNING   pid 3690, uptime 6 days, 17:40:51
crowd                            RUNNING   pid 3686, uptime 6 days, 17:40:51
gerrit-crowd                     RUNNING   pid 3683, uptime 6 days, 17:40:52
gerrit2                          RUNNING   pid 3729, uptime 6 days, 17:40:51
jira                             RUNNING   pid 3682, uptime 6 days, 17:40:52
nginx                            RUNNING   pid 3705, uptime 6 days, 17:40:51

參考 Running Supervisor


管理 Nginx 服務(wù)

要點:

1. command 關(guān)閉daemon模式
2. user 一定要用 root , 因為在配置中寫了運行用戶了

配置:

[root@localhost /]# vi /etc/supervisord/nginx.ini

[program:nginx]
command=/usr/local/nginx/sbin/nginx -g "daemon off;"
process_name=%(program_name)s
directory=/usr/local/nginx
stopsignal=QUIT
user=root
stderr_logfile=/usr/local/nginx/logs/%(program_name)s.err
stdout_logfile=/usr/local/nginx/logs/%(program_name)s.log

管理 Java 進(jìn)程

直接在shell中run java會出現(xiàn)stop失敗的情況,在啟動前添加 exec即可。

[Gerrit]crowd-ldap-server

vi [root@localhost /]# vi /etc/supervisord/gerrit-crowd.ini

[program:gerrit-crowd]
command=sh /home/gerrit2/crowd-ldap-server/run.sh   ; the program (relative uses PATH, can take args)
process_name=%(program_name)s ; process_name expr (default %(program_name)s)
numprocs=1                    ; number of processes copies to start (def 1)
directory=/home/gerrit2/crowd-ldap-server   ; directory to cwd to before exec (def no cwd)
autostart=true                ; start at supervisord start (default: true)
autorestart=true              ; retstart at unexpected quit (default: true)
startsecs=3                 ;wait for 3 seconds
stopsignal=QUIT               ; signal used to kill process (default TERM)
stopwaitsecs=5               ; max num secs to wait b4 SIGKILL (default 10)
user=gerrit2
stdout_logfile  = /home/gerrit2/crowd-ldap-server/log/%(program_name)s.log
redirect_stderr = true

管理 Java 進(jìn)程(2)

[Gerrit]GerritCodeReview

[root@localhost /]# vi /etc/supervisord/gerrit2.ini

[program:gerrit2]
command=/var/lib/gerrit2/bin/gerrit.sh run
process_name=%(program_name)s
directory=/var/lib/gerrit2
startsecs=5
stopsignal=INT
user=gerrit2
redirect_stderr=true
stdout_logfile=/var/lib/gerrit2/logs/%(program_name)s.log
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容