一、安装

1.1 yum安装

CentOS 7.9
supervisor在epel-release库中,先安装epel-release库。

yum install supervisor -y && yum install supervisor -y

安装完成后设置启动服务

systemctl enable --now supervisord
1.2 apt安装

Ubuntu 20.4

apt update
apt install supervisor

如果是全新系统,在使用apt安装软件之前需要先进行update。

二、主要目录与配置文件

CentOS系统

  • 主配置文件

    • /etc/supervisord.conf
  • 子进程配置文件

    • /etc/supervisord.d/*.ini

Ubuntu系统

  • 主配置文件

    • /etc/supervisor/supervisord.conf
  • 子进程配置文件

    • /etc//supervisor/conf.d/*.conf

子进程配置文件在默认情况下,根据不同的supervisor版本,可能是ini结尾或conf结尾。

三、配置web管理界面

3.1 编辑主配置文件
;[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))

取消配置项前的注释,并设置用户名与密码。
使用“*:9001”可通过任意IP访问。

3.2 重启服务
systemctl restart superviosrd
3.3 使用浏览器登录

![[Pasted image 20220617105138.png]]
使用浏览器登录supervisor服务器。

四、子进程配置文件

4.1 java项目配置文件例子
[program:healthy]
#command=java -jar -Djava.library.path=$LD_LIBRARY_PATH /data/release/healthy/healthy.jar
command=java -jar /data/release/healthy/healthy.jar
directory=/data/release/healthy
user=root
autorestart=true
redirect_stderr=true
stdout_logfile = /data/logs/healthy/healthy.log
loglevel=info
environment=LD_LIBRARY_PATH="/usr/local/MATLAB/MATLAB_Runtime/v93/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v93/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v93/sys/os/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v93/extern/bin/glnxa64"
4.2 redis配置文件例子
[program:redis-server]
command=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
priority=999
autostart=true
autorestart=true
startsecs=10
startretries=3
exitcodes=0,2
stopsignal=QUIT
stopwaitsecs=1
user=root
log_stdout=true
log_stderr=false
logfile=/var/log/redis-server.log
logfile_maxbytes=1MB
logfile_backups=10

使用supervisor管理redis时,redis的守护进程模式需要关闭。

五、supervisor命令

5.1 命令行管理工具

命令行管理工具superviosrctl

superviosrctl

执行命令时可以进入命令行工具模式:可使用help查看命令帮助。

supervisor>

supervisor> 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

也可以不进入命令行模式,直接在bash中执行完整命令。

supervisorctl update
5.2 更新配置文件

当supervisor子进程配置文件发生改变后,需要重新载入配置文件后才能生效。

supervisor> update
5.3 启动子进程

启动、停止或重启子进程

supervisor> start 子进程名
supervisor> restart 子进程名
supervisor> stop 子进程名
5.4 查看日志输出

可以查看子进程运行的日志输出

supervisor> start tail -f 子进程名
5.5 查看supervisor版本
supervisor> version
4.1.0

标签: Supervisord

添加新评论