Centos7 supervisor installation and configuration

Keywords: supervisor Tomcat Unix socket

Background

#

Two, installation

1. Install Python setuptools
yum install python-setuptools

#After the installation of supervisor, three executors will be generated: Supervisor TD, supervisor CTL and echo supervisor conf. they are the supervisor's daemons service (for receiving process management commands), the client (for communicating with the daemons and sending management process instructions), and the initial configuration file program.
2. Install the supervisor
easy_install supervisor

Three, configuration

1. Using echo supervisor conf, we redirect it to a file and modify its configuration items. When running the supervisor service, you need to specify the supervisor configuration file. Here we specify / etc/supervisor
#new directory
mkdir /etc/supervisor

echo_supervisord_conf > /etc/supervisor/supervisord.conf #Configuration output to / etc/supervisor/supervisord.conf in
Initialize the configuration file as shown.

2. Configuration management process.
Process management configuration parameters are not recommended to be written in the supervisor.conf file. You can write a configuration file for each process to be included in the supervisor.conf file in the directory specified by include. A configuration file similar to nginx.
(1) Create the / etc/supervisor/config.d directory to store the configuration files for process management. (the directory can be customized here, which corresponds to the configuration file.)
(2) Modify the include parameter in / etc / Supervisor / supervisor.conf to add the / etc/supervisor/conf.d directory to include.
[include]
files = /etc/supervisor/config.d/*.ini
3. Service configuration template.
/etc/supervisor/supervisor.conf
[unix_http_server]
file=/tmp/supervisor.sock   ;UNIX socket Documents, supervisorctl Will use
;chmod=0700                 ;socket Documentation mode,The default is 0700
;chown=nobody:nogroup       ;socket Documentation owner,Format: uid:gid

[inet_http_server]         ;HTTP Server, providing web Management interface
port=127.0.0.1:9001        ;Web Manage background running IP And port. If you open it to the public network, you need to pay attention to security
;username=user              ;User name of login management background
;password=123               ;Password of login management background

[supervisord]
logfile=/tmp/supervisord.log ;Log file, default is $CWD/supervisord.log
logfile_maxbytes=50MB        ;Log file size, exceeding rotate,default 50MB,If set up0,Indicates unlimited size
logfile_backups=10           ;Log file reserve backup quantity default10,Set as0Indicates no backup
loglevel=info                ;Log level, default info,Other: debug,warn,trace
pidfile=/tmp/supervisord.pid ;pid file
nodaemon=false               ;Whether to start in the foreground, the default isfalse,That is to say daemon Start by
minfds=1024                  ;Minimum value of file descriptors that can be opened, default 1024
minprocs=200                 ;Minimum number of processes that can be opened, default 200

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock; connect supervisor through UNIX socket, and the path is the same as the file in the HTTP server part of UNIX
;serverurl=http://127.0.0.1:9001; connect to supervisor through HTTP

;Include other profiles
[include]
files = /etc/supervisor/config.d/*.ini    ;You can specify one or more to.ini Profile ended
/etc/supervisor/conf.d/tomcat.ini
;[program:tomcat]Is the managed process configuration parameter, tomcat Is the name of the process
[program:tomcat]
command=/opt/tomcat/bin/startup.sh  ; Program start command
autostart=true       ; stay supervisord It starts automatically when it starts
startsecs=10         ; start-up10Seconds later, if there is no abnormal exit, the process starts normally. The default is1second
autorestart=true     ; Automatic restart after program exit,Optional values:[unexpected,true,false],Default is unexpected,Indicates that the process is not restarted until it is accidentally killed
startretries=3       ; Number of automatic retries for startup failure, default is3
user=tomcat          ; Which user is used to start the process? The default is root
priority=999         ; Process start priority, default999,Priority start with low value
redirect_stderr=true ; hold stderr Redirection to stdout,defaultfalse
stdout_logfile_maxbytes=20MB  ; stdout Log file size, default50MB
stdout_logfile_backups = 20   ; stdout Number of log file backups, default is10
; stdout For log files, it should be noted that when the specified directory does not exist, it cannot be started normally, so you need to create the directory manually( supervisord Automatically create log file)
stdout_logfile=/opt/tomcat/logs/catalina.out
stopasgroup=false     ;Default isfalse,Whether to send to this process group when the process is killed stop Signals, including subprocesses
killasgroup=false     ;Default isfalse,Send to process group kill Signals, including subprocesses
4. Service startup and shutdown.
#Start supervisor, - c to make the configuration file read
supervisord -c /etc/supervisor/supervisord.conf

#Close supervisor
supervisorctl shutdown

#Reload the supervisor configuration file and restart the supervisor
supervisorctl reload

#Add or remove profiles 
#To update
supervisorctl update

#Manage the service of the supervisor
###Startup service
supervisorctl start all
supervisorctl start service_name
###Shut down service
supervisorctl stop all
supervisorctl stop service_name
###View state
supervisorctl status [service_name]
###Restart all services or a service
supervisorctl restart all
supervisorctl restart service_name
View the status of the tomcat process.

5.web access. Browser input http://192.168.10.135:9001 , the access address corresponds to supervisor.conf.

Note: if you can't access it normally, use cmd ping192.168.10.135 (your supervisor server ip) on the windows side to see if Ping is enabled. If you can't consider the network problems, try to clear the centos7 firewall rules or add port rules.

Posted by ict on Tue, 31 Dec 2019 04:00:30 -0800