当前位置:网站首页>Supervisor usage document
Supervisor usage document
2022-07-06 07:10:00 【afterlife_ union】
1、supervisor What problem to solve
Each of our servers may need to run several processes , For example, a server often exists at the same time nginx、php-fpm Multiple processes , Machines that perform scheduled tasks often run multiple at the same time cli Process task , If you use the command line mode to start and stop manually one by one, it is obviously very troublesome 、 Inefficient , And if the task exits abnormally 、 It is unrealistic to restart manually every time , In addition, it is inconvenient to check the status of each process .Supervisord Tools are used to manage multiple processes on each machine , And Supervisord Similar tools include monit, daemontools and runit.
2、supervisor Introduce
In conclusion ,Supervisor Yes, it is Python A common set of process managers developed , Can turn a normal command line process into a background daemon, And monitor the process status , Automatically restart the process that exited abnormally , Command line program and web The interface is used to view 、 Management process .
Supervisor In most classes Unix The system can work normally , Include Linux,Mac OS X and Solaris(10 for Intel) and FreeBSD 6.1, But not supported Windows platform .
Some information on the Internet shows Supervisor Only in Python 2 Run under , But in fact, the latest version Supervisor Has supported Python 3, requirement >= Python 3.4.
Official website
http://supervisord.org/
2、supervisor install
mac The installation command is as follows
brew install supervisor
start-up supervisor
brew services restart supervisor
Starting from supervisor The output of can be seen , The configuration file used is as follows
/opt/homebrew/etc/supervisord.conf
The profile shows , From /opt/homebrew/etc/supervisor.d/ Read from .ini The configuration file , Manage related process tasks
Use -c Parameters can specify the main configuration file
/opt/homebrew/bin/supervisord -c /opt/homebrew/etc/supervisord.conf
close 、 Restart command
close supervisor
brew services stop supervisor
3、supervisor To configure
Configurations can be divided into two categories supervisord.conf To configure and Subprocess configuration
3.1 supervisord.conf To configure
[unix_http_server]
file=/tmp/supervisor.sock #UNIX socket file ,supervisorctl Will use
chmod=0700 #socket Of documents mode, The default is 0700
chown=nobody:nogroup #socket Of documents owner, Format :uid:gid
username=user # Certified accounts
password=123 # The authentication code
[inet_http_server] #HTTP The server , Provide web Management interface , Default not on , After enabling, you can use web Interface view 、 Manage subprocesses
port=127.0.0.1:9001 #Web Manage the backstage IP And port , If open to the public network , Need to pay attention to safety
username=user # Login the user name in the administrative background
password=123 # Login management background password
[supervisord]
logfile=/tmp/supervisord.log # Log files , The default is $CWD/supervisord.log
logfile_maxbytes=50MB # Log file size , Beyond the will rotate, Default 50MB, If set to 0, It means unlimited size
logfile_backups=10 # Log files retain the number of backups by default 10, Set to 0 Indicates no backup
loglevel=info # The level of logging , Default info, Other : debug,warn,trace
pidfile=/tmp/supervisord.pid #pid file
nodaemon=false # Whether to start in the foreground , The default is false, That is to daemon Way to start
minfds=1024 # The minimum value of a file descriptor that can be opened , Default 1024
minprocs=200 # The minimum number of processes that can be opened , Default 200
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock # adopt UNIX socket Connect supervisord, Path and unix_http_server Part of the file Agreement
serverurl=http://127.0.0.1:9001 # adopt HTTP Mode of connection supervisord
# Include other configuration files
[include]
files = relative/directory/*.ini # You can specify one or more to .ini End of profile
3.2 program To configure
That is, the sub process configuration that needs to be monitored ,
# The name of the child process , That is to say web The process name displayed in the interface
[program:blog]
# The scripts directory
directory=/opt/bin
# Script execution command
command=/usr/bin/python /opt/bin/test.py
#supervisor Whether to start at the same time when starting , Default True
autostart=true
# When the program exit When , This program No automatic restart , Default unexpected, Set the automatic restart of the child process after hanging up , There are three options ,false,unexpected and true. If false When , In any case , Will not be restarted , If unexpected, Only if the exit code of the process is not below exitcodes Internally defined
autorestart=false
# This option is the number of seconds after the child process starts , At this point, if the state is running, Then we think the launch was successful . The default value is 1
startsecs=1
# The user who the script runs as
user = test
# Log output
stderr_logfile=/tmp/blog_stderr.log
stdout_logfile=/tmp/blog_stdout.log
# hold stderr Redirect to stdout, Default false
redirect_stderr = true
#stdout Log file size , Default 50MB
stdout_logfile_maxbytes = 20MB
#stdout Number of log file backups
stdout_logfile_backups = 20
4、supervisorctl command
An example command is as follows
supervisorctl status // View the status of all processes
supervisorctl stop es // stop it es
supervisorctl start es // start-up es
supervisorctl restart // restart es
supervisorctl update // After modifying the configuration file, use this command to load the new configuration
supervisorctl reload // Restart all programs in the configuration
notes : hold es Switch to all You can manage all processes in the configuration . Direct input supervisorctl Get into supervisorctl Of shell Interactive interface , At this point, the above command does not carry supervisorctl Can be used directly .
5、 Data aggregation
If there are a lot of services to manage , How to put these machines supervisor The managed services are managed uniformly ?
6、 problem
6.1 supervisor couldn’t setuid to 0 Can’t drop privilege as nonroot user
The users of the main configuration file and the configuration file of the child process are the same root user , When starting with the following command
/opt/homebrew/bin/supervisord -c /opt/homebrew/etc/supervisord.conf
Keep reporting the following error
Error: Can't drop privilege as nonroot user
For help, use /opt/homebrew/bin/supervisord -h
Find information tips , Say so root User start supervisor, But not root User start
https://stackoverflow.com/questions/67344737/error-cant-drop-privilege-as-nonroot-user-container-keeps-restarting-on-googl
So I thought of root The user executes the startup command , The order is as follows , Finally, the program can run normally .
sudo /opt/homebrew/bin/supervisord -c /opt/homebrew/etc/supervisord.conf
6.2 Start command
supervisor The configuration files of both the main configuration and the sub process support setting the execution user , But it seems that if the users are different , It can't start up , Not sure if this is a necessary requirement
Reference documents
https://zhuanlan.zhihu.com/p/424346764
https://www.jianshu.com/p/00fbff2c6ee1
https://blog.csdn.net/cyt0906/article/details/107344361
边栏推荐
- Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution
- Interface automation test framework: pytest+allure+excel
- Top test sharing: if you want to change careers, you must consider these issues clearly!
- After sharing the clone remote project, NPM install reports an error - CB () never called! This is an error with npm itself.
- 18.多级页表与快表
- Path analysis model
- Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
- 首发织梦百度推送插件全自动收录优化seo收录模块
- 【JDBC】快速入门教程
- ROS学习_基础
猜你喜欢
L'auteur est mort? Ai utilise l'art pour conquérir l'humanité
18.多级页表与快表
idea控制台彩色日志
Kubernetes cluster builds ZABBIX monitoring platform
微信脑力比拼答题小程序_支持流量主带最新题库文件
巴比特 | 元宇宙每日必读:中国互联网企业涌入元宇宙的群像:“只有各种求生欲,没有前瞻创新的雄心”...
The author is dead? AI is conquering mankind with art
Cif10 actual combat (resnet18)
“无聊猿” BAYC 的内忧与外患
At the age of 26, I changed my career from finance to software testing. After four years of precipitation, I have been a 25K Test Development Engineer
随机推荐
A brief introduction of reverseme in misc in the world of attack and defense
Leetcode 78: subset
[some special grammars about C]
Idea console color log
Kubernetes cluster builds ZABBIX monitoring platform
librosa音频处理教程
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Lesson 12 study notes 2022.02.11
leetcode841. Keys and rooms (medium)
Entity Developer数据库应用程序的开发
Practical guidance for interface automation testing (Part I): what preparations should be made for interface automation
树莓派3B更新vim
作者已死?AI正用艺术征服人类
从autojs到冰狐智能辅助的心里历程
Proteus -- Serial Communication parity flag mode
SEO学习的最好方式:搜索引擎
leetcode704. Binary search (find an element, simple, different writing)
【服务器数据恢复】IBM服务器raid5两块硬盘离线数据恢复案例
GET 和 POST 请求类型的区别
The best way to learn SEO: search engine