一、簡介
Supervisor是一個進程管理工具,當進程中斷的時候Supervisor能自動重新啟動它。可以運行在各種類unix的機器上,supervisor就是用Python開發的一套通用的進程管理程序,能將一個普通的命令行進程變為后台daemon,並監控進程狀態,異常退出時能自動重啟。
1.1 supervisord
運行 Supervisor 時會啟動一個進程 supervisord,它負責啟動所管理的進程,並將所管理的進程作為自己的子進程來啟動,而且可以在所管理的進程出現崩潰時自動重啟。
supervisor是所有進程的父進程,管理着啟動的子進展,supervisor以子進程的PID來管理子進程,當子進程異常退出時supervisor可以收到相應的信號量。
1.2 supervisorctl
是命令行管理工具,可以用來執行 stop、start、restart 等命令,來對這些子進程進行管理。
supervisorctl是supervisor的命令行客戶端(command-line client),提供類似shell的命令 交互功能。supervisorctl通過使用UNIX域套接字或Internet(TCP)套接字與supervisord服務端進行通信
1.3 平台要求
- 各種類unix的機器上可以正常運行,比如Linux(Ubuntu 9.10),Mac OS X(10.4 / 10.5 / 10.6)和Solaris(10 for Intel)和FreeBSD 6.1
- 在任何版本的Windows下,Supervisor 都不會運行。
- Supervisor 可以使用
Python 2.4
或更高版本,但不能
在任何版本的Python 3
下使用
二、安裝
2.1 yum or apt
$ yum install -y supervisor
$ apt-get install supervisor
2.2 pip (推薦)
一般 linux 服務器 會自帶 2.4版本以上的python,可以直接調用 pip,所以比較推薦這種安裝方式
$ pip install supervisor
2.3 下載包安裝
wget https://pypi.python.org/packages/source/s/supervisor/supervisor-3.1.3.tar.gz
tar zxvf supervisor-3.1.3.tar.gz
cd supervisor-3.1.3
python setup.py install
安裝完成后,查看是否安裝成功
echo_supervisord_conf
三、配置
3.1 主配置文件
- 如果使用
yum
或者apt
安裝,會生成生成 supervisor的主配置文件,路徑在/etc/supervisor/supervisord.conf
或者/etc/supervisord.conf
。同時還會生成配置目錄/etc/supervisord.d
。 - 如果使用其他安裝方式,需要手動添加。
$ mkdir /etc/supervisor
$ echo_supervisord_conf > /etc/supervisor/supervisord.conf
3.2 子進程配置文件
supervisor的配置文件默認是不全的,子進程的配置文件需要另外指定(改主配置的話所有管理的子進程會一起改掉)
$ mkdir /etc/supervisor/supervisord.d/
在`/etc/supervisor/supervisord.d`的目錄下創建`conf`和`log`兩個目錄,`conf`用於存放管理進程的配置,`log`用於存放管理進程的日志。
$ cd /etc/supervisor/supervisord.d
$ mkdir conf log
3.3 修改主配置文件
$ vim /etc/supervisor/supervisord.conf
我們先修改supervisord.conf
最后的[include]
部分配置:
特別注意:原來[include] 和 files 前都有冒號,要去掉
[include]
files = /etc/supervisor/supervisord.d/conf/*.conf # 就是之前創建的子進程的配置目錄
也可以修改supervisor應用日志的目錄,默認日志路徑為/var/log/supervisor/supervisord.log
。(一般不改,直接改子進程配置項)
vi /etc/supervisord.conf
...
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
...
四、啟動 supervisor
4.1 使用 pip 或者安裝包安裝
$ supervisord
supervisor 默認在以下路徑查找配置文件:
/usr/etc/supervisord.conf
,/usr/supervisord.conf
,supervisord.conf
,etc/supervisord.conf
,/etc/supervisord.conf
,/etc/supervisor/supervisord.conf
如需指定主配置文件,則需要使用-c
參數:
$ supervisord -c /etc/supervisor/supervisord.conf
啟動時候碰到 Unlinking stale socket /tmp/supervisor.sock
,解決辦法如下:
sudo unlink /tmp/supervisor.sock
查看安裝的版本:
$ supervisord -v
3.3.4
然后查看supervisor的狀態:
$ supervisorctl status
>>>
這時候不報錯就行,因為還沒有守護進程
注:
supervisord
是主進程,supervisorctl
是給守護進程發送命令的客戶端工具。
4.2 使用 yum 或者 apt 安裝
$ /etc/init.d/supervisor start
五、簡單示例
先創建一個腳本 `/tmp/echo_time.sh`
#/bin/bash
while true; do
echo `date +%Y-%m-%d,%H:%m:%s`
sleep 2
done
在/etc/supervisor/supervisord.d/conf
新增子進程配置文件 echo_time.conf
:
[program:echo_time]
command=sh /tmp/echo_time.sh
priority=999 ; the relative start priority (default 999)
autostart=true ; start at supervisord start (default: true)
autorestart=true ; retstart at unexpected quit (default: true)
startsecs=10 ; number of secs prog must stay running (def. 10)
startretries=3 ; max # of serial start failures (default 3)
exitcodes=0,2 ; 'expected' exit codes for process (default 0,2)
stopsignal=QUIT ; signal used to kill process (default TERM)
stopwaitsecs=10 ; max num secs to wait before SIGKILL (default 10)
user=root ; setuid to this UNIX account to run the program
log_stdout=true
log_stderr=true ; if true, log program stderr (def false)
logfile=/tmp/echo_time.log
logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
logfile_backups=10 ; # of logfile backups (default 10)
stdout_logfile_maxbytes=20MB ; stdout 日志文件大小,默認 50MB
stdout_logfile_backups=20 ; stdout 日志文件備份數
stdout_logfile=/etc/supervisor/supervisord.d/log/echo_time.stdout.log
解釋
[group:tornadoes]
programs=tornado-16018,tornado-16019
[program:tornado-16018]
directory=/home/XXX/PycharmProjects/NLPXXX_build/main ; 程序的啟動目錄
command=python runServer.py --port=16018 ; 啟動命令,可以看出與手動在命令行啟動的命令是一樣的
autostart = true ; 在 supervisord 啟動的時候也自動啟動
startsecs = 30 ; 啟動 10 秒后沒有異常退出,就當作已經正常啟動了
autorestart = true ; 程序異常退出后自動重啟
startretries = 3 ; 啟動失敗自動重試次數,默認是 3
user = XXX ; 用哪個用戶啟動
redirect_stderr=true ; 把 stderr 重定向到 stdout,默認 false
stdout_logfile_maxbytes=50MB ; stdout 日志文件大小,默認 50MB
stdout_logfile_backups=10 ; stdout 日志文件備份數
; stdout 日志文件,需要注意當指定目錄不存在時無法正常啟動,所以需要手動創建目錄(supervisord 會自動創建日志文件)
stdout_logfile=/home/XXX/PycharmProjects/log/tornado_16018.log
[program:tornado-16019]
directory=/home/XXX/PycharmProjects/NLPXXX/main ; 程序的啟動目錄
command=python runServer.py --port=16018 ; 啟動命令,可以看出與手動在命令行啟動的命令是一樣的
autostart = true ; 在 supervisord 啟動的時候也自動啟動
startsecs = 30 ; 啟動 10 秒后沒有異常退出,就當作已經正常啟動了
autorestart = true ; 程序異常退出后自動重啟
startretries = 3 ; 啟動失敗自動重試次數,默認是 3
user = XXX ; 用哪個用戶啟動
redirect_stderr=true ; 把 stderr 重定向到 stdout,默認 false
stdout_logfile_maxbytes=50MB ; stdout 日志文件大小,默認 50MB
stdout_logfile_backups=10 ; stdout 日志文件備份數
; stdout 日志文件,需要注意當指定目錄不存在時無法正常啟動,所以需要手動創建目錄(supervisord 會自動創建日志文件)
stdout_logfile=/home/damao/PycharmProjects/log/tornado_16019.log
然后啟動程序:
$ supervisorctl reread
$ supervisorctl update
這兩個命令分別代表重新讀取配置、更新子進程組。
執行 supervisorctl reread
后輸出
$ echo_time: available
執行 supervisorctl update
后輸出:
$ echo_time: added process group
這樣剛才添加的echo_time
腳本就常駐運行起來了。通過日志查看運行情況:
$ tail -100f /etc/supervisor/supervisord.d/log/echo_time.stdout.log
>>>
2021-03-09,20:03:1615291846
2021-03-09,20:03:1615291848
2021-03-09,20:03:1615291850
2021-03-09,20:03:1615291852
2021-03-09,20:03:1615291854
2021-03-09,20:03:1615291856
2021-03-09,20:03:1615291858
2021-03-09,20:03:1615291860
2021-03-09,20:03:1615291862
2021-03-09,20:03:1615291864
2021-03-09,20:03:1615291866
...
也可以使用supervisorctl status
查看子進程運行情況:
$ supervisorctl status
>>>
echo_time RUNNING pid 28206, uptime 0:00:11
六、配置文件
6.1 主配置
主配置文件名: `supervisord.conf`。可以通過運行 `echo_supervisord_conf` 獲得配置。根據`章節3.2`,已經創建在 `/etc/supervisor/supervisord.conf`,這個配置文件一般情況下不需要更改,除了最后的`[include]`部分,其余保持默認即可。
; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
; - Shell expansion ("~" or "$HOME") is not supported. Environment
; variables can be expanded using this syntax: "%(ENV_HOME)s".
; - Quotes around values are not supported, except in the case of
; the environment= options as shown below.
; - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
; - Command will be truncated if it looks like a config file comment, e.g.
; "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ".
;
; Warning:
; Paths throughout this example file use /tmp because it is available on most
; systems. You will likely need to change these to locations more appropriate
; for your system. Some systems periodically delete older files in /tmp.
; Notably, if the socket file defined in the [unix_http_server] section below
; is deleted, supervisorctl will be unable to connect to supervisord.
[unix_http_server]
file=/tmp/supervisor.sock ; the path to the socket file
;chmod=0700 ; socket file mode (default 0700)
;chown=nobody:nogroup ; socket file uid:gid owner
;username=user ; default is no username (open server)
;password=123 ; default is no password (open server)
; Security Warning:
; The inet HTTP server is not enabled by default. The inet HTTP server is
; enabled by uncommenting the [inet_http_server] section below. The inet
; HTTP server is intended for use within a trusted environment only. It
; should only be bound to localhost or only accessible from within an
; isolated, trusted network. The inet HTTP server does not support any
; form of encryption. The inet HTTP server does not use authentication
; by default (see the username= and password= options to add authentication).
; Never expose the inet HTTP server to the public internet.
;[inet_http_server] ; inet (TCP) server disabled by default
;port=127.0.0.1:9001 ; ip_address:port specifier, *:port for all iface
;username=user ; default is no username (open server)
;password=123 ; default is no password (open server)
[supervisord]
logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10 ; # of main logfile backups; 0 means none, default 10
loglevel=info ; log level; default info; others: debug,warn,trace
pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon=false ; start in foreground if true; default false
silent=false ; no logs to stdout if true; default false
minfds=1024 ; min. avail startup file descriptors; default 1024
minprocs=200 ; min. avail process descriptors;default 200
;umask=022 ; process file creation umask; default 022
;user=supervisord ; setuid to this UNIX account at startup; recommended if root
;identifier=supervisor ; supervisord identifier, default is 'supervisor'
;directory=/tmp ; default is not to cd during start
;nocleanup=true ; don't clean up tempfiles at start; default false
;childlogdir=/tmp ; 'AUTO' child log dir, default $TEMP
;environment=KEY="value" ; key value pairs to add to environment
;strip_ansi=false ; strip ansi escape codes in logs; def. false
; The rpcinterface:supervisor section must remain in the config file for
; RPC (supervisorctl/web interface) to work. Additional interfaces may be
; added by defining them in separate [rpcinterface:x] sections.
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
; The supervisorctl section configures how supervisorctl will connect to
; supervisord. configure it match the settings in either the unix_http_server
; or inet_http_server section.
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris ; should be same as in [*_http_server] if set
;password=123 ; should be same as in [*_http_server] if set
;prompt=mysupervisor ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history ; use readline history if available
; The sample program section below shows all possible program subsection values.
; Create one or more 'real' program: sections to be able to control them under
; supervisor.
;[program:theprogramname]
;command=/bin/cat ; 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=/tmp ; directory to cwd to before exec (def no cwd)
;umask=022 ; umask for process (default None)
;priority=999 ; the relative start priority (default 999)
;autostart=true ; start at supervisord start (default: true)
;startsecs=1 ; # of secs prog must stay up to be running (def. 1)
;startretries=3 ; max # of serial start failures when starting (default 3)
;autorestart=unexpected ; when to restart if exited after running (def: unexpected)
;exitcodes=0 ; 'expected' exit codes used with autorestart (default 0)
;stopsignal=QUIT ; signal used to kill process (default TERM)
;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
;stopasgroup=false ; send stop signal to the UNIX process group (default false)
;killasgroup=false ; SIGKILL the UNIX process group (def false)
;user=chrism ; setuid to this UNIX account to run the program
;redirect_stderr=true ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10)
;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
;stdout_events_enabled=false ; emit events on stdout writes (default false)
;stdout_syslog=false ; send stdout to syslog with process name (default false)
;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10)
;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
;stderr_events_enabled=false ; emit events on stderr writes (default false)
;stderr_syslog=false ; send stderr to syslog with process name (default false)
;environment=A="1",B="2" ; process environment additions (def no adds)
;serverurl=AUTO ; override serverurl computation (childutils)
; The sample eventlistener section below shows all possible eventlistener
; subsection values. Create one or more 'real' eventlistener: sections to be
; able to handle event notifications sent by supervisord.
;[eventlistener:theeventlistenername]
;command=/bin/eventlistener ; 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)
;events=EVENT ; event notif. types to subscribe to (req'd)
;buffer_size=10 ; event buffer queue size (default 10)
;directory=/tmp ; directory to cwd to before exec (def no cwd)
;umask=022 ; umask for process (default None)
;priority=-1 ; the relative start priority (default -1)
;autostart=true ; start at supervisord start (default: true)
;startsecs=1 ; # of secs prog must stay up to be running (def. 1)
;startretries=3 ; max # of serial start failures when starting (default 3)
;autorestart=unexpected ; autorestart if exited after running (def: unexpected)
;exitcodes=0 ; 'expected' exit codes used with autorestart (default 0)
;stopsignal=QUIT ; signal used to kill process (default TERM)
;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
;stopasgroup=false ; send stop signal to the UNIX process group (default false)
;killasgroup=false ; SIGKILL the UNIX process group (def false)
;user=chrism ; setuid to this UNIX account to run the program
;redirect_stderr=false ; redirect_stderr=true is not allowed for eventlisteners
;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10)
;stdout_events_enabled=false ; emit events on stdout writes (default false)
;stdout_syslog=false ; send stdout to syslog with process name (default false)
;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10)
;stderr_events_enabled=false ; emit events on stderr writes (default false)
;stderr_syslog=false ; send stderr to syslog with process name (default false)
;environment=A="1",B="2" ; process environment additions
;serverurl=AUTO ; override serverurl computation (childutils)
; The sample group section below shows all possible group values. Create one
; or more 'real' group: sections to create "heterogeneous" process groups.
;[group:thegroupname]
;programs=progname1,progname2 ; each refers to 'x' in [program:x] definitions
;priority=999 ; the relative start priority (default 999)
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
;[include]
;files = relative/directory/*.ini
6.2 子進程配置文件
根據`章節3.2`設置,一般放在:`/etc/supervisor/supervisord.d/conf`目錄 。一個腳本對應一個配置文件。
配置說明:
;*為必須填寫項
;*[program:應用名稱]
[program:cat]
;*命令路徑,如果使用python啟動的程序應該為 python /home/test.py,
;不建議放入/home/user/, 對於非user用戶一般情況下是不能訪問
command=/bin/cat
;當numprocs為1時,process_name=%(program_name)s;
當numprocs>=2時,%(program_name)s_%(process_num)02d
process_name=%(program_name)s
;進程數量
numprocs=1
;執行目錄,若有/home/supervisor_test/test1.py
;將directory設置成/home/supervisor_test
;則command只需設置成python test1.py
;否則command必須設置成絕對執行目錄
directory=/tmp
;掩碼:--- -w- -w-, 轉換后rwx r-x w-x
umask=022
;優先級,值越高,最后啟動,最先被關閉,默認值999
priority=999
;如果是true,當supervisor啟動時,程序將會自動啟動
autostart=true
;*自動重啟
autorestart=true
;啟動延時執行,默認1秒
startsecs=10
;啟動嘗試次數,默認3次
startretries=3
;當退出碼是0,2時,執行重啟,默認值0,2
exitcodes=0,2
;停止信號,默認TERM
;中斷:INT(類似於Ctrl+C)(kill -INT pid),退出后會將寫文件或日志(推薦)
;終止:TERM(kill -TERM pid)
;掛起:HUP(kill -HUP pid),注意與Ctrl+Z/kill -stop pid不同
;從容停止:QUIT(kill -QUIT pid)
;KILL, USR1, USR2其他見命令(kill -l),說明1
stopsignal=TERM
stopwaitsecs=10
;*以root用戶執行
user=root
;重定向
redirect_stderr=false
stdout_logfile=/a/path
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/a/path
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
;環境變量設置
environment=A="1",B="2"
serverurl=AUTO
簡化模板
[program:echo_time]
command=sh /tmp/echo_time.sh
autostart=true
autorestart=true
startsecs=10
startretries=3
exitcodes=0,2
stopsignal=QUIT
stopwaitsecs=10
user=root
log_stdout=true
log_stderr=true
logfile=/tmp/echo_time.log
logfile_maxbytes=1MB
logfile_backups=10
stdout_logfile_maxbytes=20MB
stdout_logfile_backups=20
stdout_logfile=/tmp/echo_time.stdout.log
如果上面的模板里增加下面兩句:
process_name=%(process_num)02d
numprocs=3
執行supervisorctl update
后會啟動三個進程:
$ supervisorctl status
echo_time:00 RUNNING pid 26762, uptime 2:06:12
echo_time:01 RUNNING pid 26866, uptime 2:06:02
echo_time:02 RUNNING pid 27975, uptime 2:05:52
這對於需要多進程消費的場景非常有用。
七、命令行程序
7.1 supervisord
supervisord
是主進程,通過supervisord -h
可以查看幫助說明。示例:
-c/--configuration FILENAME ;指定配置文件
-n/--nodaemon ;運行在前台(調試用)
-v/--version ;打印版本信息
-u/--user USER ;以指定用戶(或用戶ID)運行
-m/--umask UMASK ;指定子進程的umask,默認是022
-l/--logfile FILENAME ;指定日志文件
-e/--loglevel LEVEL ;指定日志級別
7.2 supervisorctl
supervisorctl 是客戶端程序,用於向supervisord發起命令。
通過supervisorctl -h
可以查看幫助說明。我們主要關心的是其action
命令:
$ supervisorctl help
default commands (type help <topic>):
=====================================
add exit open reload restart start tail
avail fg pid remove shutdown status update
clear maintail quit reread signal stop version
這些命令對於控制子進程非常重要。示例:
注意:示例中的<name> 為[program:name]的 name
reread ;重新加載配置文件
update ;將配置文件里新增的子進程加入進程組,如果設置了autostart=true則會啟動新新增的子進程
status ;查看所有進程狀態
status <name> ;查看指定進程狀態
start all; 啟動所有子進程
start <name>; 啟動指定子進程
restart all; 重啟所有子進程
restart <name>; 重啟指定子進程
stop all; 停止所有子進程
stop <name>; 停止指定子進程
reload ;重啟supervisord
add <name>; 添加子進程到進程組
reomve <name>; 從進程組移除子進程,需要先stop。注意:移除后,需要使用reread和update才能重新運行該進程
supervisord 有進程組process group
的概念:只有子進程在進程組,才能被運行。
supervisorctl
也支持交互式命令行:
$ supervisorctl
echo_time RUNNING pid 27188, uptime 0:05:09
supervisor> version
3.3.4
supervisor>
八、web界面操作
需要開啟supervisord.conf
注釋掉的這4行:
[inet_http_server] ; inet (TCP) server disabled by default
port=127.0.0.1:9001 ; ip_address:port specifier, *:port for all iface
username=user ; default is no username (open server)
password=123 ; default is no password (open server)
端口默認是監聽127.0.0.1:9001
,這里方便測試(使所有機器都能訪問),修改為:
port=*:9001
注意:
Supervisor只能管理非daemon的進程,也就是說Supervisor不能管理守護進程。否則提示Exited too quickly (process log may have details)異常。例子中的Tomcat默認是以守護進程啟動的,所以我們改成了catalina.sh run,以前台進程的方式運行。
下面是配置Tomcat進程的一個例子:
[program:tomcat]
command=/opt/apache-tomcat-8.0.35/bin/catalina.sh run
stdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.out
autostart=true
autorestart=true
startsecs=5
priority=1
stopasgroup=true
killasgroup=true
九、cesi集群監控
supervisor不支持跨機器的進程監控,一個supervisord只能監控本機上的程序,大大限制了supervisor的使用。
不過由於supervisor本身支持xml-rpc,因此也有一些基於supervisor二次開發的多機器進程管理工具。比如:
- Django-Dashvisor Web-based dashboard written in Python. Requires Django 1.3 or 1.4.
- Nodervisor Web-based dashboard written in Node.js.
- Supervisord-Monitor Web-based dashboard written in PHP.
- SupervisorUI Another Web-based dashboard written in PHP.
- cesi cesi is a web interface provides manage supervizors from same interface.
安裝 CeSi
有三個依賴:Python3
,Flask
,sqlite3
從 Python 2.5
開始 sqlite3
已經在標准庫內置了,所以也不需要安裝 sqlite3
模塊了; 另外很多 Linux 發行版已經自帶 sqlite3
,所以無需另外安裝;
只需要安裝 flask web
框架即可;
具體的安裝直接看github README.md 即可
$ export CESI_SETUP_PATH=~/cesi
$ mkdir ${CESI_SETUP_PATH}
$ cd ${CESI_SETUP_PATH}
$ # Download the project to ~/cesi directory
$ wget https://github.com/gamegos/cesi/releases/download/v2.7.1/cesi-extended.tar.gz -O cesi.tar.gz
$ tar -xvf cesi.tar.gz
$ # Create virtual environment and install requirement packages
$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ pip3 install -r requirements.txt
$ # Run with command line
(venv) $ python3 ${CESI_SETUP_PATH}/cesi/run.py --config-file ${CESI_SETUP_PATH}/defaults/cesi.conf.toml
但是這里有個坑,官網建議的python版本為 python3.4,我用的是3.6版本,而在 requirements.txt 里面,已經把版本寫死了:
flask==1.1.2
flask-sqlalchemy==2.4.3
psycopg2-binary==2.8.5
pymysql==0.9.3
tomlkit==0.5.11
在首次登錄的時候,發現一直提示密碼錯誤,在翻看了github 的 issues 后返現不止一個人碰到這個問題,解決方法為升級flask-sqlalchemy版本:
pip3 uninstall flask-sqlalchemy
pip3 install flask-sqlalchemy
配置文件地址${CESI_SETUP_PATH}/defaults/cesi.conf.toml
:
# This is the main CeSI toml configuration file. It contains CeSI web application and
# supervisord information to connect
# This is the CeSI's own configuration.
[cesi]
# Database Uri
database = "sqlite:///users.db" # Relative path
# Etc
#database = "sqlite:////opt/cesi/< version >/users.db" # Absolute path
#database = "postgres://<user>:<password>@localhost:5432/<database_name>"
#database = "mysql+pymysql://<user>:<password>@localhost:3306/<database_name>"
activity_log = "activity.log" # File path for CeSI logs
admin_username = "admin" # Username of admin user
admin_password = "admin" # Password of admin user
# This is the definition section for new supervisord node.
# [[nodes]]
# name = "api" # (String) Unique name for supervisord node.
# environment = "" # (String) The environment name provides logical grouping of supervisord nodes. It can be used as filtering option in the UI.
# username = "" # (String) Username of the XML-RPC interface of supervisord Set nothing if no username is configured
# password = "" # (String) Password of the XML-RPC interface of supervisord. Set nothing if no username is configured
# host = "127.0.0.1" # (String) Host of the XML-RPC interface of supervisord
# port = "9001" # (String) Port of the XML-RPC interface of supervisord
# Default supervisord nodes
[[nodes]]
name = "products-server"
environment = ""
username = "tester"
password = "t@987654321"
host = "192.168.8.129"
port = "9001"
# [[nodes]]
# name = "analysis-server"
# environment = ""
# username = "user123"
# password = "pass123"
# host = "analysis.example.com"
# port = "9001"
# [[nodes]]
# name = "monitoring-server"
# environment = ""
# username = ""
# password = ""
# host = "monitoring.example.com"
# port = "9001"
參考: