当前位置:网站首页>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
边栏推荐
- Wechat official account infinite callback authorization system source code, launched in the whole network
- 巴比特 | 元宇宙每日必读:中国互联网企业涌入元宇宙的群像:“只有各种求生欲,没有前瞻创新的雄心”...
- C language_ Double create, pre insert, post insert, traverse, delete
- SEO学习的最好方式:搜索引擎
- TS Basics
- 多线程和并发编程(二)
- 《从0到1:CTFer成长之路》书籍配套题目(周更)
- UWA Pipeline 2.2.1 版本更新说明
- Yield method of tread
- 微信公众号无限回调授权系统源码 全网首发
猜你喜欢
Hydra common commands
Top test sharing: if you want to change careers, you must consider these issues clearly!
Raspberry pie 3B update VIM
After sharing the clone remote project, NPM install reports an error - CB () never called! This is an error with npm itself.
3. Business and load balancing of high architecture
18.多级页表与快表
Leetcode59. spiral matrix II (medium)
SSM学习
Thought map of data warehouse construction
The first Baidu push plug-in of dream weaving fully automatic collection Optimization SEO collection module
随机推荐
leetcode1020. 飞地的数量(中等)
How to find a medical software testing institution? First flight software evaluation is an expert
Idea console color log
这个高颜值的开源第三方网易云音乐播放器你值得拥有
leetcode841. 钥匙和房间(中等)
OpenGL ES 学习初识(1)
A brief introduction of reverseme in misc in the world of attack and defense
supervisor 使用文档
When my colleague went to the bathroom, I helped my product sister easily complete the BI data product and got a milk tea reward
leetcode59. 螺旋矩阵 II(中等)
编译,连接 -- 笔记 -2
Win10 64 bit Mitsubishi PLC software appears oleaut32 DLL access denied
中青看点阅读新闻
1189. Maximum number of "balloons"
多线程和并发编程(二)
18. Multi level page table and fast table
Missing monitoring: ZABBIX monitors the status of Eureka instance
【Hot100】739. 每日温度
呆错图床系统源码图片CDN加速与破解防盗链功能
顶测分享:想转行,这些问题一定要考虑清楚!