In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the introduction of the basic usage of Supervisor under the Linux system". In the daily operation, I believe that many people have doubts about the introduction of the basic usage of Supervisor under the Linux system. The editor consulted all kinds of materials and sorted out the simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "introduction to the basic usage of Supervisor under the Linux system"! Next, please follow the editor to study!
Supervisor is a Cramp S system that allows users to control some processes on UNIX-like systems. It has the following characteristics:
1 simple
Supervisor is easily configured through the INI configuration file, and it provides many configuration options for each process, allowing you to easily restart the process or automatically rotate the log.
2 Unification
Supervisor provides a unified way to start, stop, and monitor your processes, which can be controlled individually or in groups. You can configure Supervisor on the local or remote command line or on the web interface.
3 effective
Supervisor starts its child process through fork/exec, which is not a daemon. When a process terminates, the operating system immediately sends a signal to Supervisor, rather than relying on PID files like other solutions.
4 Extensible
Supervisor contains a simple event notification protocol, so any program can monitor it and provide a XML-RPC control interface.
5 compatible
Except for the windows platform, all other platforms can run.
Components of the Supervisor system:
Supervisord:
The service starts the supervisord service, which is responsible for calling its own startup subroutine, responding to commands from the client, restarting the crash or exiting process, recording the output of the process, and collecting event information. The configuration file for the service is at / etc/supervisor/supervisord.conf
Supervisorctl:
The client's command line tool provides a shell-like interface through which you can connect to different supervisord processes to manage their respective subroutines. The client command communicates with the service through UNIX socket or TCP, and the server can require the client to provide authentication before it can operate ([supervisorctl]).
Web Server:
A small web interface is integrated into supervisorctl, which can be accessed after restarting supervisord ([inet_http_server]).
XML-RPC Interface:
Just as HTTP provides WEB UI, it also provides a XML-RPC interface to control supervisor and the programs it runs.
Installation:
Supervisor is written by python, obviously with easy_install, pip can be installed, I am lazy, directly apt-get, in ubuntu14.04 after the installation of the version is 3.0b2.
Start of the Supervisor service
In fact, it is very easy to start Supervisor. Just take a look at supervisord-h. The simplest-c root configuration file can be used:
The code is as follows:
Supervisord-- run a set of applications as daemons.
Usage: / usr/bin/supervisord [options]
Options:
-c/--configuration FILENAME-- configuration file
-n/--nodaemon-- run in the foreground (same as' nodaemon true' in config file)
-h/--help-- print this usage message and exit
-v/--version-- print supervisord version number and exit
-u/--user USER-run supervisord as this user (or numeric uid)
-m/--umask UMASK-- use this umask for daemon subprocess (default is 022)
-d/--directory DIRECTORY-- directory to chdir to when daemonized
-l/--logfile FILENAME-- use FILENAME as logfile path
-y/--logfile_maxbytes BYTES-- use BYTES to limit the max size of logfile
-z/--logfile_backups NUM-- number of backups to keep when max bytes reached
-e/--loglevel LEVEL-use LEVEL as loglevel (debug,info,warn,error,critical)
-j/--pidfile FILENAME-- write a pidfile for the daemon process to FILENAME
-i/--identifier STR-- identifier used for this instance of supervisord
-q/--childlogdir DIRECTORY-- the log directory for child process logs
-k/--nocleanup-prevent the process from performing cleanup (removal of
Old automatic child log files) at startup.
-a/--minfds NUM-- the minimum number of file descriptors for start success
-t/--strip_ansi-- strip ansi escape codes from process output
-minprocs NUM-the minimum number of processes available for start success
-profile_options OPTIONS-run supervisord under profiler and output
Results based on OPTIONS, which is a comma-sep'd
List of 'cumulative',' calls', and/or 'callers'
E.g. 'cumulative,callers')
However, since I am lazy to install with apt-get, the installation package must be in line with the Debian style, directly service supervisor start can be started, wait a minute, we have not configured the configuration file of supervisor, boot does not have any effect. We will explain the configuration of the configuration file later.
The use of supervisorctl client
There are two modes of supervisorctl, one is interactive mode, the other is command line mode. Enter supervisorctl on the command line and enter directly to enter interactive mode.
The code is as follows:
Supervisorctl-- control applications run by supervisord from the cmd line.
Usage: / usr/bin/supervisorctl [options] [action [arguments]]
Options:
-c/--configuration-- configuration file path (default / etc/supervisor.conf)
-h/--help-- print usage message and exit
-i/--interactive-- start an interactive shell after executing commands
-s/--serverurl URL-- URL on which supervisord server is listening
(default "http://localhost:9001").
-u/--username-- username to use for authentication with server
-p/--password-- password to use for authentication with server
-r/--history-file-keep a readline history (if readline is available)
The code is as follows:
Action [arguments]-- see below
Actions are commands like "tail" or "stop". If-i is specified or no action is
Specified on the command line, a "shell" interpreting actions typed
Interactively is started. Use the action "help" to find out about available
Actions.
Boot self-start of Supervisor
If you install pip or easy_install, boot service self-startup is really a hassle, but officials have given some examples of rc.d scripts, on github, but since I am installed by apt-get, obviously this boot self-boot does not have to worry about, it can be done with debian update-rc.d.
Process Security of Supervisor
Since Supervisor is used to ensure the normal operation of other processes, but what if the Supervisor process fails, we can use daemontools to ensure the normal operation of Supervisor, which is similar to monitoring.
The configuration file of supervisord is mainly composed of several configuration segments, and the configuration items are presented in KBG V format. Let's see how each configuration end needs to be configured:
[unix_http_server]
The parameter item in the configuration block represents a HTTP server listening on the socket, and if the [unix_http_server] block is not in the configuration file, the socket-based HTTP server will not be started.
File: the file path of a unix domain socket, on which HTTP/XML-RPC listens
Chmod: modify the mode of unix domain socket at startup
Chown: modify the owner of the socket file
The user name of username:HTTP server when authenticating
Password: authentication password
Eg:
The code is as follows:
[unix_http_server]
File = / tmp/supervisor.sock
Chmod = 0777
Chown= nobody:nogroup
Username = user
Password = 123
[inet_http_server]
The parameter item in the configuration block represents a HTTP server listening on the TCP, and if the [inet_http_server] block is not in the configuration file, the TCP-based HTTP server will not be started.
The address and port (ip:port) of port:TCP listening, which will be monitored by HTTP/XML-RPC
The user name of username:HTTP server when authenticating
Password: authentication password
Eg:
The code is as follows:
[inet_http_server]
Port = 127.0.0.1purl 9001
Username = user
Password = 123
[supervisord]
The parameter entry for this configuration block is the global configuration item for the supervisord process.
Logfile:log file path
Logfile_maxbytes:log files reach the number of automatic rotation, units are KB, MB, GB. If set to 0, there is no limit to log file size.
Logfile_backups: number of round robin log backups. Default is 10. If set to 0, no backups are made.
Loglevel:error 、 warn 、 info 、 debug 、 trace 、 blather 、 critical
Pidfile:pid file path
Umask: Umask value. Default is 022.
Nodaemon: if set to true, supervisord starts in the foreground, not as a daemon
The minimum number of file descriptors available to minfds:supervisord before starting successfully. Default is 1024.
The minimum number of process descriptors available to minprocs:supervisord before starting successfully. Default is 200.
Nocleanup: prevents supervisord from clearing existing child process log files at startup
Childlogdir: the log directory of the automatically started child process
Users who are running user:supervisord
Directory:supervisord changes to this directory when the daemon is running
Strip_ansi: eliminates escape sequences from child process log files
Environment: a list list of KBE pairs
Eg:
The code is as follows:
[supervisord]
Logfile = / tmp/supervisord.log
Logfile_maxbytes = 50MB
Logfile_backups=10
Loglevel = info
Pidfile = / tmp/supervisord.pid
Nodaemon = false
Minfds = 1024
Minprocs = 200
Umask = 0.22
User = chrism
Identifier = supervisor
Directory = / tmp
Nocleanup = true
Childlogdir = / tmp
Strip_ansi = false
Environment = KEY1= "value1", KEY2= "value2"
[supervisorctl]
The configuration block parameter is about supervisorctl
Serverurl: this url is used to access the supervisord service (http://localhost:9001), or a sockets file (unix:///absolute/path/to/file.sock))
Authenticated users of username:supervisorctl connected to supervisord
Password: authentication password
Prompt: default is supervisor
History_file:history file path
Eg:
The code is as follows:
[supervisorctl]
Serverurl = unix:///tmp/supervisor.sock
Username = chris
Password = 123
Prompt = mysupervisor
[program:x]
The configuration block contains one or more program segments, program to indicate which programs the supervisord controls. The header of the configuration block has a fixed format, a keyword program, followed by a colon, followed by the program name. For example: [program:foo], foo is the program name, when using supervisorctl to operate the program, it is marked with foo.
Command: the command used to start the program, either an absolute path or a relative path
Process_name: a python string expression that represents the name of the one started by the supervisor process. The default value is% (program_name) s.
Numprocs:Supervisor starts multiple instances of this program. If numprocs > 1, the expression of process_name must contain% (process_num) s. The default is 1.
Numprocs_start: an int offset value that is used to calculate the numprocs value when the instance is started
Priority: weight, which can control the order in which the program starts and closes. The lower the weight, the earlier it starts, the later it closes. The default value is 999
Autostart: if set to true, the process will restart automatically when supervisord starts.
Autorestart: values can be false, true, unexpected. False: the process does not restart automatically, unexpected: when the exit code of the program is not defined in exitcodes, the process will restart, true: the process will restart unconditionally when exiting.
Startsecs: how long does the program wait before it is considered to have started successfully?
The number of times startretries:supervisord tries to start a program. The default is 3
Exitcodes: an expected exit return code. The default is 0Jing 2.
Stopsignal: when a stop request is received, a signal is sent to the program. The default is TERM signal, which can also be HUP, INT, QUIT, KILL, USR1, or USR2.
Stopwaitsecs: the time to wait when the operating system sends a SIGCHILD signal to supervisord
Stopasgroup: if set to true, supervisor will send a stop signal to the entire process group
Killasgroup: if set to true, when a SIGKILL signal is sent to the program, it will be sent to the entire process group, and its child processes will also be affected.
User: if supervisord runs as root, this will be used to set up the user startup subroutine
Redirect_stderr: if set to true, the process outputs the standard error to the standard output file descriptor behind the supervisord.
Stdout_logfile: writes the standard output of the process to a file. If stdout_logfile is not set or set to AUTO, supervisor will automatically select a file location.
Stdout_logfile_maxbytes: the standard output log file is rotated automatically after the number of standard output log files, in KB, MB, GB units. If set to 0, there is no limit to log file size.
Stdout_logfile_backups: the number of standard output log round-robin backups. Default is 10. If set to 0, no backups are made.
Stdout_capture_maxbytes: the maximum bytes value written to the FIFO queue when the process is in stderr capture mode mode, in KB, MB, GB units
Stdout_events_enabled: if set to true, the PROCESS_LOG_STDERR event will be triggered when the process is writing its stderr to the file descriptor
Stderr_logfile: outputs the error log of the process to a file, unless the redirect_stderr parameter is set to true
Stderr_logfile_maxbytes: automatically rotate the error log file after reaching the number of units: KB, MB, GB. If set to 0, there is no limit to log file size.
Stderr_logfile_backups: the number of error log rotation backups. Default is 10. If set to 0, no backup is made.
Stderr_capture_maxbytes: the maximum bytes value written to the FIFO queue when the process is in stderr capture mode mode, in KB, MB, GB units
Stderr_events_enabled: if set to true, the PROCESS_LOG_STDERR event will be triggered when the process is writing its stderr to the file descriptor
Environment: a list list of KBE pairs
Directory:supervisord changes to this directory when generating child processes
Umask: sets the umask of the process
Serverurl: whether to allow child processes to communicate with internal HTTP services. If set to AUTO,supervisor, a url will be constructed automatically.
Eg:
The code is as follows:
[program:cat]
Command=/bin/cat
Process_name=% (program_name) s
Numprocs=1
Directory=/tmp
Umask=022
Priority=999
Autostart=true
Autorestart=true
Startsecs=10
Startretries=3
Exitcodes=0,2
Stopsignal=TERM
Stopwaitsecs=10
User=chrism
Redirect_stderr=false
Stdout_logfile=/a/path
Stdout_logfile_maxbytes=1MB
Stdout_logfile_backups=10
Stdout_capture_maxbytes=1MB
Stderr_logfile=/a/path
Stderr_logfile_maxbytes=1MB
Stderr_logfile_backups=10
Stderr_capture_maxbytes=1MB
Environment=A= "1", B = "2"
Serverurl=AUTO
At this point, the study of "introduction to the basic usage of Supervisor under the Linux system" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.