說明:對于需要自啟動的服務用supervisor管理,可實作自啟動enable、status、start、stop等操作
# 安裝,所用系統為Ubuntu
apt-get install supervisor
vim /etc/supervisor/supervisord.conf
systemctl status supervisor.service
systemctl restart supervisor.service
# 設定開機自啟
systemctl enable supervisor.service
修改配置檔案,添加管理子產品
[email protected]:/etc/supervisor/conf.d# cat /etc/supervisor/supervisord.conf
; supervisor config file
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)
; 添加前端界面,友善檢視,預設關閉
[inet_http_server] ; web console
port=0.0.0.0:9001
username=admin
password=1234
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
logfile_backups=7
loglevel=warn
; the below 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: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
prompt=mysupervisor
history_file=~/.sc_history
; 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 = /etc/supervisor/conf.d/*.conf
[email protected]:/etc/supervisor/conf.d# pwd
/etc/supervisor/conf.d
[email protected]:/etc/supervisor/conf.d# cat alertmanager.conf
[program:alertmanager]
command=/home/ctdna/prometheus+grafana/alertmanager/alertmanager --config.file=/home/ctdna/prometheus+grafana/alertmanager/alertmanager.yml --storage.path=/home/ctdna/prometheus+grafana/alertmanager/data --web.listen-address=:7996
user=ctdna
autostart=true
startsecs=5
exitcodes=0
redirect_stderr=true
stdout_logfile=/var/log/alertmanager.log
stdout_logfile_backups=5
[email protected]:/etc/supervisor/conf.d# cat prometheus.conf
[program:prometheus]
command=/home/ctdna/prometheus+grafana/prometheus/prometheus --config.file=/home/ctdna/prometheus+grafana/prometheus/prometheus.yml --storage.tsdb.path=/home/ctdna/prometheus+grafana/prometheus/data --web.enable-lifecycle --storage.tsdb.retention.time=7d
user=ctdna
autostart=true
startsecs=5
exitcodes=0
redirect_stderr=true
stdout_logfile=/var/log/prometheus.log
stdout_logfile_backups=5
更新配置
# 加載更新配置
[email protected]:/etc/supervisor/conf.d# supervisorctl update
# 加入後檢視
[email protected]:/etc/supervisor/conf.d# supervisorctl
alertmanager FATAL Exited too quickly (process log may have details)
prometheus RUNNING pid 11752, uptime 0:01:35
mysupervisor>
# 啟動
[email protected]:/etc/supervisor/conf.d# supervisorctl start alertmanager
alertmanager: started
[email protected]:/etc/supervisor/conf.d# supervisorctl
alertmanager RUNNING pid 12110, uptime 0:00:18
prometheus RUNNING pid 11752, uptime 0:02:44
mysupervisor>