当前位置:网站首页>supervisor 使用文档
supervisor 使用文档
2022-07-06 07:04:00 【afterlife_union】
1、supervisor 解决什么问题
我们的每台服务器都可能需要运行好几个进程,比如一个服务器往往同时存在nginx、php-fpm多个进程,对于执行定时任务的机器则往往会同时运行多个cli进程任务,如果使用命令行方式一个一个去手动启动和停止显然非常麻烦、低效,而且任务如果异常退出、每次都靠人工去重启也不现实,另外查看每个进程的状态也很不方便。Supervisord工具就是用来管理每台机器上多个进程的,与Supervisord类似的工具包括monit, daemontools和runit。
2、supervisor介绍
总结来说,Supervisor 是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,自动重启异常退出的进程,同时提供了命令行程序和web界面用于查看、管理进程。
Supervisor在大多数类Unix系统都可以正常工作,包括Linux,Mac OS X 和Solaris(10 for Intel)和FreeBSD 6.1,但是不支持 Windows平台。
网上一些资料显示Supervisor 只能在Python 2下运行,但实际上最新版本的Supervisor已经支持Python 3,要求>= Python 3.4。
官方网站
http://supervisord.org/
2、supervisor安装
mac 安装命令如下
brew install supervisor
启动supervisor
brew services restart supervisor
从启动supervisor的输出可以看到,使用的配置文件如下
/opt/homebrew/etc/supervisord.conf
该配置文件显示,会从 /opt/homebrew/etc/supervisor.d/ 中读取 .ini配置文件,管理相关的进程任务
使用-c参数可以指定主配置文件
/opt/homebrew/bin/supervisord -c /opt/homebrew/etc/supervisord.conf
关闭、重启命令
关闭supervisor
brew services stop supervisor
3、supervisor配置
配置可以分成两类 supervisord.conf 配置 和 子进程配置
3.1 supervisord.conf 配置
[unix_http_server]
file=/tmp/supervisor.sock #UNIX socket 文件,supervisorctl 会使用
chmod=0700 #socket文件的mode,默认是0700
chown=nobody:nogroup #socket文件的owner,格式:uid:gid
username=user # 认证账户
password=123 # 认证密码
[inet_http_server] #HTTP服务器,提供web管理界面,默认未开启,启用后可以通过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
minprocs=200 #可以打开的进程数的最小值,默认 200
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock #通过UNIX socket连接supervisord,路径与unix_http_server部分的file一致
serverurl=http://127.0.0.1:9001 #通过HTTP的方式连接supervisord
#包含其它配置文件
[include]
files = relative/directory/*.ini #可以指定一个或多个以.ini结束的配置文件
3.2 program配置
也就是需要监控的子进程配置,
# 子进程的名称,也即web界面中展示的进程名称
[program:blog]
#脚本目录
directory=/opt/bin
#脚本执行命令
command=/usr/bin/python /opt/bin/test.py
#supervisor启动的时候是否随着同时启动,默认True
autostart=true
#当程序exit的时候,这个program不会自动重启,默认unexpected,设置子进程挂掉后自动重启的情况,有三个选项,false,unexpected和true。如果为false的时候,无论什么情况下,都不会被重新启动,如果为unexpected,只有当进程的退出码不在下面的exitcodes里面定义的
autorestart=false
#这个选项是子进程启动多少秒之后,此时状态如果是running,则我们认为启动成功了。默认值为1
startsecs=1
#脚本运行的用户身份
user = test
#日志输出
stderr_logfile=/tmp/blog_stderr.log
stdout_logfile=/tmp/blog_stdout.log
#把stderr重定向到stdout,默认 false
redirect_stderr = true
#stdout日志文件大小,默认 50MB
stdout_logfile_maxbytes = 20MB
#stdout日志文件备份数
stdout_logfile_backups = 20
4、supervisorctl命令
命令示例如下
supervisorctl status //查看所有进程的状态
supervisorctl stop es //停止es
supervisorctl start es //启动es
supervisorctl restart //重启es
supervisorctl update //配置文件修改后使用该命令加载新的配置
supervisorctl reload //重新启动配置中的所有程序
注:把es换成all可以管理配置中的所有进程。直接输入supervisorctl进入supervisorctl的shell交互界面,此时上面的命令不带supervisorctl可直接使用。
5、数据聚合
如果有大量服务需要管理,怎么把这些机器的supervisor所管理的服务统一管理?
6、问题
6.1 supervisor couldn’t setuid to 0 Can’t drop privilege as nonroot user
主配置文件和子进程的配置文件的用户都是用的相同的root用户,通过下面的命令启动时
/opt/homebrew/bin/supervisord -c /opt/homebrew/etc/supervisord.conf
一直报下面的错误
Error: Can't drop privilege as nonroot user
For help, use /opt/homebrew/bin/supervisord -h
查找资料提示,说是以root用户启动supervisor,但是以非root用户启动
https://stackoverflow.com/questions/67344737/error-cant-drop-privilege-as-nonroot-user-container-keeps-restarting-on-googl
于是想到以root 用户执行启动命令,命令如下,最终程序可以正常运行。
sudo /opt/homebrew/bin/supervisord -c /opt/homebrew/etc/supervisord.conf
6.2 启动命令
supervisor主配置和子进程的配置文件都支持设置执行用户,但是似乎如果用户不同的话,是启动不起来的,不确定这是不是必须的要求
参考文档
https://zhuanlan.zhihu.com/p/424346764
https://www.jianshu.com/p/00fbff2c6ee1
https://blog.csdn.net/cyt0906/article/details/107344361
边栏推荐
- Day 246/300 SSH connection prompt "remote host identification has changed!"
- Practical guidance for interface automation testing (Part I): what preparations should be made for interface automation
- win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问
- [brush questions] how can we correctly meet the interview?
- AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models. common‘ from ‘/home/yolov5/models/comm
- 将ue4程序嵌入qt界面显示
- Refer to how customer push e-commerce does content operation
- leetcode704. 二分查找(查找某个元素,简单,不同写法)
- Do you really know the use of idea?
- 同事上了个厕所,我帮产品妹子轻松完成BI数据产品顺便得到奶茶奖励
猜你喜欢

Configure raspberry pie access network

开源的网易云音乐API项目都是怎么实现的?

Blue Bridge Cup zero Foundation National Championship - day 20

Thought map of data warehouse construction

顶测分享:想转行,这些问题一定要考虑清楚!

Top test sharing: if you want to change careers, you must consider these issues clearly!

Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes

WPF之MVVM

After sharing the clone remote project, NPM install reports an error - CB () never called! This is an error with npm itself.

Introduction to ros2 installation and basic knowledge
随机推荐
树莓派串口登录与SSH登录方法
Three methods of adding color to latex text
同事上了个厕所,我帮产品妹子轻松完成BI数据产品顺便得到奶茶奖励
Bio model realizes multi person chat
Fedora/rehl installation semanage
Pallet management in SAP SD delivery process
Thought map of data warehouse construction
leetcode1020. 飞地的数量(中等)
Development of entity developer database application
[daily question] 729 My schedule I
Fast target recognition based on pytorch and fast RCNN
Windows Server 2016 standard installing Oracle
C language_ Double create, pre insert, post insert, traverse, delete
[server data recovery] case of offline data recovery of two hard disks of IBM server RAID5
Wechat official account infinite callback authorization system source code, launched in the whole network
作者已死?AI正用艺术征服人类
升级版手机检测微信工具小程序源码-支持多种流量主模式
开源的网易云音乐API项目都是怎么实现的?
Interface automation test framework: pytest+allure+excel
UDP攻击是什么意思?UDP攻击防范措施