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)
安裝
推薦環(huán)境
- CentOS 6+ 不建議在V6以下的版本上進(jìn)行安裝
- python 2.7.x Installing Python 2.7 on Centos 6
安裝步驟
!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 。supervisord 和 supervisorctl 都會使用這個文件。
!bash
echo_supervisord_conf > /etc/supervisord.conf
mkdir /etc/supervisord/
include 分段
# 支持多級文件配置
vi /etc/supervisord.conf
...
; last line
[include]
files = /etc/supervisord/*.ini
配置 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
管理 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