Ubuntu部署轻量化工具supervisor

本文介绍了如何在Ubuntu系统中安装和配置轻量级的进程管理工具Supervisor,包括添加sudo权限、配置文件的创建、运行命令以及设置开机自启动的详细步骤。
摘要由CSDN通过智能技术生成

supervisor(ubuntu)

supervisor是一个轻量化守护进程工具

1, 安装

本次测试使用服务器是Ubuntu 86 64(Linux)

sudo给用户临时添加一个管理员权限

sudo apt-get install supervisor

2,配置

安装完成supervisor配置目录在 /etc/supervisor ,并且安装完成supervisor会自动启动。(并不是开机自启动)

cd /etc/supervisor/   #移动至supervisor配置目录

打开supervisor工具配置

vim supervisor.conf #编辑supervisor的配置文件
; supervisor config file

[unix_http_server]
#指定的sock文件给到sock 775权限
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)

[supervisord]
#如结尾log所示supervisord日志文件路径
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
#有pid的工具可以配合moil做监控
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP)

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

[include]
#指定supervisord需要执行并监控的conf配置文件路径
files = /etc/supervisor/conf.d/*.conf

移动至supervisor需要监控的conf配置文件路径conf.d下

ll可以发现此目录下没有任何conf文件(需要自己新建,但不需要赋权)

这里创建一个java.conf表示监控的是java进程的conf配置

vim java.conf
[program:java]
command=  #需要执行的java命令比如 java -jar(jar包)
numprocs=1 #优先级从1-999
user=root #让哪个用户执行command命令
startsecs=25 #如果正常运行25秒后就表示正常的运行将不会重启
directory=/etc/ #移动至某个目录
autostart=true
autorestart=true
startretries=10 #如果发生kill 或程序错误 只会重启十次
exitcodes=0
stopsignal=KILL
stopwaitsecs=10
redirect_stderr=true
stdout_logfile=/opt/apps/log/java.log #运行日志存放位置

3,运行命令

supervisorctl update #更新新的配置至supervisord(修改过conf.d中或者supervisord.conf文件需要执行)
 
supervisorctl reload #重新启动supervisord

supervisorctl status #查看supervisord运行的进程状态

supervisorctl shutdown #关闭supervisord

supervisord -c  /etc/supervisor/supervisord.conf #指定conf文件启动supervisord

supervisorctl start xxxx #单独启动某个进程

supervisorctl stop xxxx #单独停止某个进程

supervisorctl restart xxxx #单独重启某个进程

4,开机自启动

进入到system系统文件中

cd /etc/systemd/system/

创建一个supervisord.service系统文件并且编译(需要修改启动目录,其他默认即可)

[Unit] 
Description=Supervisor daemon

[Service] 
Type=forking 
ExecStart=/usr/bin/supervisord -c /etc/supervisord/supervisord.conf #启动目录
ExecStop=/usr/bin/supervisorctl shutdown 
ExecReload=/usr/bin/supervisorctl reload 
KillMode=process 
Restart=on-failure 
RestartSec=42s

[Install] 
WantedBy=multi-user.target

2.赋权

使用以下命令对service赋权并添加启动项

systemctl enable supevisord.service

最后使用命令查看启动项的状态

systemctl status supevisord.service

出现以下信息表示自启动完成

● supervisor.service - Supervisor process control system for UNIX
   Loaded: loaded (/lib/systemd/system/supervisor.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2021-10-21 14:51:39 CST; 5 days ago
     Docs: http://supervisord.org
 Main PID: 1657 (supervisord)
    Tasks: 24 (limit: 4915)
   CGroup: /system.slice/supervisor.service
           ├─ 1657 /usr/bin/python /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
           ├─13151 node ./node_modules/@vue/cli-service/bin/vue-cli-service.js serve --mode production
           ├─16606 /bin/bash /etc/vue.sh
           └─16608 node ./node_modules/@vue/cli-service/bin/vue-cli-service.js serve --mode production

第一次写文章不对的地方望包含

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值