supervisor--go版安装

系统环境

ubuntu18.04

安装

1、下载指定golang版本的安装包

安装包下载地址:https://github.com/ochinchina/supervisord/releases/tag/v0.7.3

1.1、构建supervisor的目录结构

mkdir -p /etc/supervisord/conf.d

1.2、supervisor的目录结构

在这里插入图片描述

1.3、说明

目录中的supervisord二进制文件为上面安装包中的二进制文件

2、配置

2.1 添加启动所需配置文件

配置文件路径
/etc/supervisord/supervisord.conf
配置文件内容
[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)

[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_maxbytes=50MB        ;日志文件大小,超出会rotate,默认 50MB,如果设成0,表示不限制大小
logfile_backups=10           ;日志文件保留备份数量默认10,设为0表示不备份
loglevel=info                ;日志级别,默认info,其它: debug,warn,trace
nodaemon=false               ;是否在前台启动,默认是false,即以 daemon 的方式启动
minfds=1024                  ;可以打开的文件描述符的最小值,默认 1024
minprocs=200                 ;可以打开的进程数的最小值,默认 200

; 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

; 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.

[inet_http_server]
port=0.0.0.0:9001

[include]
files = /etc/supervisord/conf.d/*.conf

2.2 将需要后台运行的程序挂载到配置文件

(此处是配置模板,请根据自己需求自行配置)

## 将需要挂载到后台运行的配置文件放置到 /etc/supervisord/conf.d/alter.conf
# 例如:altermanager
[program:alertmanager]
# 程序所在目录
directory = /opt/project/alertmanager/
# 启动程序的命令;
command = /opt/project/alertmanager/alertmanager --config.file=/opt/project/alertmanager/alertmanager.yml --cluster.advertise-address=0.0.0.0:9093
# 在supervisord启动的时候也自动启动;
autostart = true
# 程序异常退出后自动重启;
autorestart = true
# 启动5秒后没有异常退出,就当作已经正常启动了;
startsecs = 5
# 启动失败自动重试次数,默认是3;
startretries = 3
# 启动程序的用户;
user = root
# 把stderr重定向到stdout,默认false;
redirect_stderr = true
# 标准日志输出;
stdout_logfile=/tmp/alertmanager_stdout.log
# 错误日志输出;
stderr_logfile=/tmp/alertmanager_stderr.log
# 标准日志文件大小,默认50MB;
stdout_logfile_maxbytes = 20MB
# 标准日志文件备份数;
stdout_logfile_backups = 20

2.3 将服务加入到系统服务system中

2.3.1 命令
vim  /etc/systemd/system/supervisord.service
2.3.2 内容
[Unit]
Description=supervisord service in golang
After=network.target
 
[Service]
Type=simple
User=root
StartLimitInterval=5
StartLimitBurst=10
ExecStartPre=/bin/sleep 10
ExecStart=/etc/supervisord/supervisord -c /etc/supervisord/supervisord.conf
Restart=always
RestartSec=120
 
[Install]
WantedBy=multi-user.target
2.3.3 加载新配置
systemctl daemon-reload
systemctl start  supervisord.service
systemctl status supervisord

2.4 简化命令

2.4.1 打开配置文件

root用户下的:

vim  /root/.bashrc

普通用户下的:

vim /home/xxx用户/.bashrc
2.4.2 文件中追加当前命令

在这里插入图片描述

alias supervisorctl='/etc/supervisord/supervisord ctl'
2.4.3 使配置生效

root用户下的:

source /root/.bashrc

普通用户下的:

source /home/xxx用户/.bashrc

借鉴链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值