怎么会有如此详细的supervisor4源码安装及配置文档?!

源码安装所需软件包

root@supervisor:~# mkdir /opt/supervisor
root@supervisor:~# cd /opt/supervisor/

安装meld

root@supervisor:/opt/supervisor# wget https://files.pythonhosted.org/packages/64/34/7a43890031d05b2d3ed269ea6fa256016a8675f2420255caf22bf33bff98/meld-1.0.2.tar.gz
root@supervisor:/opt/supervisor# tar zxf meld-1.0.2.tar.gz
root@supervisor:/opt/supervisor# cd meld-1.0.2/
root@supervisor:/opt/supervisor/meld-1.0.2# python3 setup.py install
root@supervisor:/opt/supervisor/meld-1.0.2# cd ..

注意:

【可能报错】:ImportError: No module named setuptools
【解决办法】:没有setuptools的模块,说明python缺少这个模块,那我们只要安装这个模块即可解决此问题

[root@supervisor supervisor]# wget https://files.pythonhosted.org/packages/4b/d9/d0cf66484b7e28a9c42db7e3929caed46f8b80478cd8c9bd38b7be059150/setuptools-69.0.2.tar.gz
root@supervisor:/opt/supervisor# tar zxf setuptools-69.0.2.tar.gz 
root@supervisor:/opt/supervisor# cd setuptools-69.0.2
root@supervisor:/opt/supervisor/setuptools-69.0.2# python3 setup.py build
root@supervisor:/opt/supervisor/setuptools-69.0.2# python3 setup.py install
root@supervisor:/opt/supervisor/setuptools-69.0.2# cd ..

安装supervisor

[root@localhost supervisor]# wget https://files.pythonhosted.org/packages/ce/37/517989b05849dd6eaa76c148f24517544704895830a50289cbbf53c7efb9/supervisor-4.2.5.tar.gz
root@supervisor:/opt/supervisor# tar zxf supervisor-4.2.5.tar.gz 
root@supervisor:/opt/supervisor# cd supervisor-4.2.5
root@supervisor:/opt/supervisor/supervisor-4.2.5# python3 setup.py install

验证安装是否成功

root@supervisor:/opt/supervisor/supervisor-4.2.5# cd
root@supervisor:~# supervisorctl --help
supervisorctl -- control applications run by supervisord from the cmd line.

Usage: /usr/local/bin/supervisorctl [options] [action [arguments]]

Options:
-c/--configuration FILENAME -- configuration file path (searches if not given)
-h/--help -- print usage message and exit
-i/--interactive -- start an interactive shell after executing commands
-s/--serverurl URL -- URL on which supervisord server is listening
     (default "http://localhost:9001").
-u/--username USERNAME -- username to use for authentication with server
-p/--password PASSWORD -- password to use for authentication with server
-r/--history-file -- keep a readline history (if readline is available)

action [arguments] -- see below

Actions are commands like "tail" or "stop".  If -i is specified or no action is
specified on the command line, a "shell" interpreting actions typed
interactively is started.  Use the action "help" to find out about available
actions.

配置supervisor

配置文件说明

[unix_http_server]
file=/tmp/supervisor.sock   ;UNIX socket 文件,supervisorctl 会使用
;chmod=0700                 ;socket文件的mode,默认是0700
;chown=nobody:nogroup       ;socket文件的owner,格式:uid:gid
 
;[inet_http_server]         ;HTTP服务器,提供web管理界面
;port=127.0.0.1:9001        ;Web管理后台运行的IP和端口,如果开放到公网,需要注意安全性
;username=user              ;登录管理后台的用户名
;password=123               ;登录管理后台的密码
 
[supervisord]
logfile=/tmp/supervisord.log ;日志文件,默认是 $CWD/supervisord.log
logfile_maxbytes=50MB        ;日志文件大小,超出会rotate,默认 50MB,如果设成0,表示不限制大小
logfile_backups=10           ;日志文件保留备份数量默认10,设为0表示不备份
loglevel=info                ;日志级别,默认info,其它: debug,warn,trace
pidfile=/tmp/supervisord.pid ;pid 文件
nodaemon=false               ;是否在前台启动,默认是false,即以 daemon 的方式启动
minfds=1024                  ;可以打开的文件描述符的最小值,默认 1024。注意托管ES进程,这里要进行调整至65535
minprocs=200                 ;可以打开的进程数的最小值,默认 200。注意托管ES进程,这里要进行调整至4096
 
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ;通过UNIX socket连接supervisord,路径与unix_http_server部分的file一致
;serverurl=http://127.0.0.1:9001 ; 通过HTTP的方式连接supervisord
 
; [program:xx]是被管理的进程配置参数,xx是进程的名称
[program:xx]
command=/opt/apache-tomcat-8.0.35/bin/catalina.sh run  ; 程序启动命令
autostart=true       ; 在supervisord启动的时候也自动启动
startsecs=10         ; 启动10秒后没有异常退出,就表示进程正常启动了,默认为1秒
autorestart=true     ; 程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启
startretries=3       ; 启动失败自动重试次数,默认是3
user=tomcat          ; 用哪个用户启动进程,默认是root
priority=999         ; 进程启动优先级,默认999,值小的优先启动
redirect_stderr=true ; 把stderr重定向到stdout,默认false
stdout_logfile_maxbytes=20MB  ; stdout 日志文件大小,默认50MB
stdout_logfile_backups = 20   ; stdout 日志文件备份数,默认是10
; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件)
stdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.out
stopasgroup=false     ;默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
killasgroup=false     ;默认为false,向进程组发送kill信号,包括子进程
 
;包含其它配置文件
[include]
files = supervisord/*.ini    ;默认放在安装目录的supervisord.d目录下,可以指定一个或多个以.ini结束的配置文件。

子进程配置文件

需要给托管的子进程配置相应的配置文件,每个进程的配置文件都可以单独分拆也可以把相关的脚本放一起。目录及文件后缀可以在
supervisor.conf配置文件中进行自定义。见supervisor.conf的
[include]
files = supervisord.d/*.ini  #目录路径及文件后缀名都可以自定义。

#项目名
[program:crontab-ui]
environment=HOST="0.0.0.0",PORT="9002"
#脚本执行命令
command=/usr/local/bin/crontab-ui
#脚本运行的用户身份 
user=root
#supervisor启动的时候是否随着同时启动,默认True
autostart=true
##当程序exit的时候,这个program不会自动重启,默认unexpected,设置子进程挂掉后自动重启的情况,有三个选项,false,unexpected和true。如果为false的时候,无论什么情况下,都不会被重新启动,如果为unexpected,只有当进程的退出码不在下面的exitcodes里面定义的
autorestart=false
#把stderr重定向到stdout,默认 false
redirect_stderr = true
#stdout日志文件大小,默认 50MB
stdout_logfile_maxbytes = 10M
#stdout日志文件备份数
stdout_logfile_backups = 10
#日志输出 
stderr_logfile=/home/wwwlogs/crontab-ui.err.log
stdout_logfile=/home/wwwlogs/crontab-ui.out.log

创建配置

root@supervisor:~# mkdir -p /etc/supervisord/
root@supervisor:~# echo_supervisord_conf > /etc/supervisord.conf

修改配置

root@supervisor:~# vim /etc/supervisord.conf
#最后两行
[include]
files = /etc/supervisord/*.ini		#配置表示包括/etc/supervisord/的所有ini文件

创建配置(以filebeat为例)

[program:filebeat] 
; 定义一个新的程序组,命名为 filebeat。Supervisor 将用这个名字来管理该程序。
directory=/home/filebeat/ 
; 指定 Supervisor 在运行命令之前切换到的目录。在这里,它将切换到 /home/filebeat/ 目录。
command=/home/filebeat/filebeat -c /home/filebeat/filebeat.yml 
; 要运行的命令。这里是执行 filebeat,并使用配置文件 /home/filebeat/filebeat.yml。
user=root 
; 指定以哪个用户身份运行该程序。在这里,它将以 root 用户身份运行。
autostart=true 
; 如果设置为 true,Supervisor 将在启动时自动启动此程序。
autorestart=true 
; 如果设置为 true,在程序退出时,Supervisor 将自动重启该程序。这对于程序异常退出时特别有用。
stderr_logfile=/home/wwwlogs/filebeat.err.log 
; 指定标准错误输出(stderr)日志文件的位置。这里指定日志文件为 /home/wwwlogs/filebeat.err.log。
stdout_logfile=/home/wwwlogs/filebeat.out.log 
; 指定标准输出(stdout)日志文件的位置。这里指定日志文件为 /home/wwwlogs/filebeat.out.log。

启动suprvisor

命令启动

root@supervisor:~# supervisord -c /etc/supervisord.conf
root@supervisor:~# ps -ef | grep supervisor
root       93182       1  0 15:12 ?        00:00:00 /usr/bin/python3 /usr/local/bin/supervisord -c /etc/supervisord.conf
root       93184   93071  0 15:12 pts/0    00:00:00 grep supervisor

将supervisor加入到开启启动服务中

root@supervisor:~# vim /usr/lib/systemd/system/supervisord.service
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=supervisord -c /etc/supervisord.conf
ExecStop=supervisorctl shutdown
ExecReload=supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
root@supervisor:~# systemctl enable supervisord
Created symlink /etc/systemd/system/multi-user.target.wants/supervisord.service → /lib/systemd/system/supervisord.service.
root@supervisor:~# systemctl is-enabled supervisord
enabled
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

勾魂皮卡丘

咋滴,打算白嫖啊?

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值