当前位置:网站首页>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
边栏推荐
猜你喜欢
Thought map of data warehouse construction
树莓派3B更新vim
leetcode35. 搜索插入位置(简单,找插入位置,不同写法)
leetcode841. 钥匙和房间(中等)
Path analysis model
How are the open source Netease cloud music API projects implemented?
RichView TRVStyle 模板样式的设置与使用
Leetcode59. spiral matrix II (medium)
Short video, more and more boring?
After sharing the clone remote project, NPM install reports an error - CB () never called! This is an error with npm itself.
随机推荐
(4) Web security | penetration testing | network security web site source code and related analysis
【Hot100】739. Daily temperature
UWA pipeline version 2.2.1 update instructions
The author is dead? AI is conquering mankind with art
chrome查看页面fps
Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution
[hot100] 739. Température quotidienne
树莓派3B更新vim
因高额网络费用,Arbitrum 奥德赛活动暂停,Nitro 发行迫在眉睫
将ue4程序嵌入qt界面显示
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
librosa音频处理教程
18.多级页表与快表
顶测分享:想转行,这些问题一定要考虑清楚!
UNIPRO Gantt chart "first experience": multi scene exploration behind attention to details
Cookie技术&Session技术&ServletContext对象
leetcode1020. 飞地的数量(中等)
When my colleague went to the bathroom, I helped my product sister easily complete the BI data product and got a milk tea reward
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
On the world of NDK (2)