In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Supervisor (http://supervisord.org/) is a client/server service developed with Python. It is a process management tool under Linux/Unix system and does not support Windows system. It can easily monitor, start, stop, and restart one or more processes. With Supervisor management process, when a process is accidentally killed, supervisort monitoring process after the death, will automatically pull it up, it is very convenient to achieve the automatic recovery of the process function, no longer need to write their own shell script to control.
Because Supervisor is developed by Python, check to see if the Python2.4 version is installed on the system before installation. The following describes the installation and configuration steps of Supervisor in the CentOS7,Python2.7 version environment:
1. Install Python package management tools (easy_install)
Easy_install is a command in the setuptools package. Using easy_install is actually calling setuptools to install the module, so you can install setuptools.
Wget-- no-check-certificate https://bootstrap.pypa.io/ez_setup.py-O-| sudo python
2. Install supervisor
Easy_install supervisor
After the installation of supervisor, three executive programs are generated: supervisortd, supervisorctl and echo_supervisord_conf, which are the daemon service of supervisor (used to receive process management commands), the client (used to communicate with the daemon and send instructions to manage the process), and the initial configuration file program.
3. Configuration
When running the supervisord service, you need to specify the supervisor configuration file. If the specified file is not displayed, it will be found in the following directory by default:
$CWD/supervisord.conf$CWD/etc/supervisord.conf/etc/supervisord.conf/etc/supervisor/supervisord.conf (since Supervisor 3.3.0).. / etc/supervisord.conf (Relative to the executable).. / supervisord.conf (Relative to the executable)
CWD represents the directory where the supervisord program is running.
You can generate an initialization configuration file for supervisor by running the echo_supervisord_conf program, as follows:
Mkdir / etc/supervisorecho_supervisord_conf > / etc/supervisor/supervisord.conf
4. Description of configuration file parameters
There are many configuration parameters for supervisor. The following describes the configuration of commonly used parameters, detailed configuration and instructions. Please refer to the official documentation.
Note: the configuration at the beginning of the semicolon (;) indicates comments
[unix_http_server] file=/tmp/supervisor.sock; UNIX socket file, which can be used by supervisorctl; chmod=0700; mode of socket file, default is 0700position ownership nobodygroup; owner of socket file, format: uid:gid; [inet_http_server]; HTTP server, which provides web management interface; port=127.0.0.1:9001 Web manages the IP and port running at the backend. If it is open to the public network, you need to pay attention to security; username=user; user name of login management backend; password=123; password of login management backend [supervisord] logfile=/tmp/supervisord.log; log file. Default is $CWD/supervisord.loglogfile_maxbytes=50MB. Log file size: rotate. Default is 50MB. If set to 0, there is no limit on the size of logfile _ backups=10. The number of reserved backups of log files defaults to 10, and 0 means no backup of loglevel=info. Log level, default info, other: debug,warn,tracepidfile=/tmp/supervisord.pid; pid file nodaemon=false Whether to start in the foreground, the default is false, that is, start minfds=1024 by daemon; the minimum value of file descriptors that can be opened, default 1024minprocs=200; the minimum value of the number of processes that can be opened, default 200 [supervisorctl] serverurl=unix:///tmp/supervisor.sock; connect supervisord through UNIX socket, the path is the same as the file of the unix_http_server part; serverurl= http://127.0.0.1:9001 Connecting supervisord; [program:xx] through HTTP is the configuration parameter of the managed process. Xx is the name of the process [program:xx] command=/opt/apache-tomcat-8.0.35/bin/catalina.sh run; the program startup command autostart=true; it also starts startsecs=10 automatically when supervisord starts. If there is no abnormal exit after starting 10 seconds, it means that the process has started normally. The default is 1 second autorestart=true. Restart automatically after the program exits. Available values: [unexpected,true,false], default is unexpected, which means startretries=3 is restarted after the process is killed unexpectedly; number of automatic retries after startup failure, default is 3user=tomcat; which user is used to start the process, default is rootpriority=999; process startup priority, default is 999, redirect_stderr=true with low value is preferred; redirect stderr to stdout, default is falsestdout_logfile_maxbytes=20MB Stdout log file size, default 50MBstdout_logfile_backups = 20; number of stdout log file backups, default is 10; stdout log file, which cannot be started normally when the specified directory does not exist, so you need to create a directory manually (supervisord will automatically create log files) stdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.outstopasgroup=false Default is false. When a process is killed, whether to send stop signal to this process group, including child process killasgroup=false; default is false, and send kill signal to process group, including child process; include other configuration files [include] files = relative/directory/*.ini; you can specify one or more configuration files that end with .ini.
Include example:
[include] files = / opt/absolute/filename.ini / opt/absolute/*.ini foo.conf config??.ini
5. Configuration management process
Process management configuration parameters are not recommended to be written in the supervisord.conf file. Each process should write a configuration file and include it in the supervisord.conf file in the directory specified by include.
1 > create the / etc/supervisor/config.d directory to store the configuration files for process management
2 > modify the include parameter in / etc/supervisor/supervisord.conf to add the / etc/supervisor/conf.d directory to include
[include] files = / etc/supervisor/config.d/*.ini
Supervisor profile directory structure
Here is an example of configuring a Tomcat process:
[program:tomcat] command=/opt/apache-tomcat-8.0.35/bin/catalina.sh runstdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.outautostart=trueautorestart=truestartsecs=5priority=1stopasgroup=truekillasgroup=true
5. Start the Supervisor service
Supervisord-c / etc/supervisor/supervisord.conf
6. Control the process
6.1 Interactive terminal
After supervisord starts successfully, you can control the process through the supervisorctl client to start, stop, and restart. Running the supervisorctl command with no parameters will enter the interactive terminal of the supervisor client and list all processes currently managed.
Supervisorctl
The tomcat in the figure above is the name we specified in the configuration file [program:tomcat].
Type help to see a list of commands that can be executed. If you want to see what a command does, run the name of the help command, such as help stop
Stop tomcat / / means to stop tomcat processes stop all / / means to stop all processes / /.
6.2 bash Terminal
Supervisorctl statussupervisorctl stop tomcatsupervisorctl start tomcatsupervisorctl restart tomcatsupervisorctl rereadsupervisorctl update
6.3 Web management interface
Supervisor Web management interface
For security reasons, the default configuration is that the web management interface is not enabled. You need to modify the supervisord.conf configuration file to open http access, and configure the following:
; [inet_http_server]; inet (TCP) server disabled by default;port=127.0.0.1:9001; (ip_address:port specifier, *: port for all iface); username=user; (default is no username (open server)); password=123; (default is no password (open server))
Modified to:
[inet_http_server]; inet (TCP) server disabled by defaultport=0.0.0.0:9001; (ip_address:port specifier, *: port for all iface) username=user; (default is no username (open server)) password=123; (default is no password (open server))
Port: bind access IP and port. Here, bind local IP and port 9001.
Username: the user name of logging in to the administrative backend
Password: the password for logging in to the administrative backend
7. Boot and start the Supervisor service
7.1Configuring systemctl Services
1 > go to the / lib/systemd/system directory and create the supervisor.service file
[Unit] Description=supervisorAfter= network.target [service] Type=forkingExecStart=/usr/bin/supervisord-c / etc/supervisor/supervisord.confExecStop=/usr/bin/supervisorctl $OPTIONS shutdownExecReload=/usr/bin/supervisorctl $OPTIONS reloadKillMode=processRestart=on-failureRestartSec=42s [Install] WantedBy=multi-user.target
2 > set Boot Startup
Systemctl enable supervisor.servicesystemctl daemon-reload
3. Modify the file permission to 766
Chmod 766 supervisor.service
7.2Configuring service type services
#! / bin/bash#supervisord This scripts turns supervisord on#Author: Mike McGrath (based off yumupdatesd) # chkconfig:-95 04 description: supervisor is a process control utility. It has a web based#xmlrpc interface as well as a few other nifty features. Processname: supervisord#config: / etc/supervisor/supervisord.conf#pidfile: / var/run/supervisord.pid#source function library. / etc/rc.d/init.d/functionsRETVAL=0start () {echo-n $"Starting supervisord:" daemon "supervisord-c / etc/supervisor/supervisord.conf" RETVAL=$? Echo [$RETVAL-eq 0] & & touch / var/lock/subsys/supervisord} stop () {echo-n $"Stopping supervisord:" killproc supervisord echo [$RETVAL-eq 0] & & rm-f / var/lock/subsys/supervisord} restart () {stop start} case "$1" in start) start;; stop) stop Restart | force-reload | reload) restart;; condrestart) [- f / var/lock/subsys/supervisord] & & restart;; status) status supervisord RETVAL=$?;; *) echo $"Usage: $0 {start | stop | status | restart | reload | condrestart}" exit 1esacexit $RETVAL
Save the above script contents to the / etc/rc.d/init.d/supervisor file, modify the file permissions to 755, and set boot
Chmod 755 / etc/rc.d/init.d/supervisorchkconfig supervisor on
Note: modify the supervisor configuration file path in the script to your supervisor configuration file path
Boot script for other Linux distributions: https://github.com/Supervisor/initscripts
Note:
Supervisor can only manage processes that are not daemon, which means that Supervisor cannot manage daemons. Otherwise, it prompts the Exited too quickly (process log may have details) exception. The Tomcat in the example is started by default as a daemon, so we changed it to catalina.sh run to run as a foreground process.
Yum installation
Yum install epel-releaseyum install-y supervisor
Supervisor is not released in the standard CentOS source, so you need to install the epel source. The installation in this way may not be the latest version, but it is more convenient. After the installation is complete, the configuration file will be automatically generated for you.
Default profile: / etc/supervisord.conf
Just put the process management configuration file in the / etc/supervisord.d/ directory.
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.