This article has participated in the good article call order activity, click to see: back end, big front end double track submission, 20,000 yuan prize pool for you to challenge!

A lifelong learner, practitioner, and sharer committed to the path of technology, an original blogger who is busy and sometimes lazy, and a teenager who is occasionally boring and sometimes humorous.

Welcome to search “Jge’s IT Journey” on wechat!

Supervisor: a process management tool in Linux

Supervisor, a process management tool for Linux

I. Introduction to the Supervisor

  • Supervisord.org/
  • Supervisor is a C/S service developed in Python. It is a process management tool in Linux.
  • You can listen to, start, stop, or restart one or more processes.
  • When the process managed by the supervisor is accidentally killed, the supervisor will automatically restart the process after hearing that the process is dead, which is very convenient to achieve the automatic recovery function of the process, and it does not need to write scripts to control.

Supervisor installation

2.1 Install using PIP
# pip install supervisor
Copy the code
2.2 Installation using yum
# yum install -y epel-release
# yum install -y supervisor
Copy the code

Use of Supervisor

3.1 Installing supervisor using PIP
# # configuration supervisor sudo mkdir/etc/supervisor # echo_supervisord_conf > / etc/supervisor/supervisord. ConfCopy the code
3.2 Using yum to install Supervisor

A supervisor.conf file and a supervisor.d file directory are generated in /etc/file

[unix_http_server] file=/tmp/supervisor.sock ; The UNIX socket file is used by the supervisorctl. chmod=0700 ; Socket file mode, default is 0700; chown=nobody:nogroup ; Socket Owner of a file. Format: UID: GID; [inet_http_server] ; The HTTP server provides a Web management interface. Port = 0.0.0.0:9001; If the IP address and port used by the Web management background are open to the public network, pay attention to security. username=user ; User name for logging in to the management background; password=123 ; Supervisord. logfile=/ TMP /supervisord.log; /supervisord. logfile=/ TMP /supervisord.log; The default value is $CWD/supervisord.log logfile_maxbytes=50MB; The logfile size is rotate. The default size is 50MB. If this parameter is set to 0, the logfile size is not limited. The default number of reserved log files is 10. If the value is set to 0, loglevel=info. Log level, default info, other: debug, WARN,trace pidfile=/ TMP /supervisord.pid; Pid file nodaemon=false; Whether to start in the foreground, default is false, that is, daemon mode minfds=1024; Minimum number of file descriptors that can be opened, default 1024 minprocs=200; Can open a minimum value of the number of processes, the default 200 [supervisorctl] serverurl = Unix: / / / TMP/supervisor. The sock; The UNIX socket is run on the supervisord, and the path is the same as the file in the unix_http_server section. Serverurl = http://127.0.0.1:9001; The supervisord is connected to the container in the HTTP format. [program:xx] command=/opt/apache-tomcat-8.0.35/bin/catalina.sh run; [program:xx] command=/opt/apache-tomcat-8.0.35/bin/catalina.sh run; Program start command autostart=true; Supervisord starts the startSecs container when it is running; it is designed to run on the container when it is running. If the process does not exit after 10 seconds, it is normal to start the process. Default: autorestart=true; Unexpected,true,false). The default value is UNEXPECTED, which indicates that the process is restarted only after it is accidentally killed. Startretries =3. The default value is 3. User =tomcat; Which user to start the process with, default root priority=999; Redirect_stderr =true; the default value is 999. Redirect stderr to stdout, default false stdOUT_LOGFILe_maxbytes =20MB; Stdout Log file size. The default value is 50MB. Stdout_logfile_backups = 20. Stdout Number of log files to back up. Default is 10. Stdout Log file. Note that if the specified directory does not exist, it cannot be started properly. /opt/apache-tomcat-8.0.35/logs/catalina.out stopasGroup =false; /opt/apache-tomcat-8.0.35/logs/catalina.out stopasGroup =false; /opt/apache-tomcat-8.0.35/logs/catalina.out stopasGroup =false; The default value is false. If a process is killed, whether to send a stop signal to the process group, including child process killasgroup=false. The default value is false and a kill signal is sent to a process group, including child processes. [include] # files = relative/directory/*.ini; You can specify one or more configuration files ending in.ini: file = relative/directory/*.conf; It can also be written as a.conf configuration fileCopy the code
The process supervises its configuration parameters. It should be written to each process and stored in the include directory in the supervisord.conf file. Used by the supervisor. D. directory to store user defined process configuration: # start_es. Conf/program: nginx command = / usr/local/nginx/sbin/nginx - g 'daemon off; ' stdout_logfile=/etc/supervisor/logs/run.log stderr_logfile=/etc/supervisor/logs/error.log autostart=true autorestart=true startsecs=60 stopasgroup=true ikillasgroup=true startretries=1 redirect_stderr=trueCopy the code

Note: Supervisor cannot monitor background processes, and command cannot run commands for the background

3.3 Starting the Supervisor service
supervisor -c /etc/supervisor.conf
Copy the code

4. Supervisor commands

Supervisorctl is the container that it is designed to run on. - supervisorctl is the container that it is designed to run on. - supervisorctl restart <name>: supervisorctl restart <name> Supervisorctl update: This command is used to load new configurations when the configuration file is modified. -supervisorctl reload: restarts all programs in the configurationCopy the code

5. Cluster management

5.1 cesii

Installation reference: github.com/Gamegos/ces…

Username = user Password = 123 host = 192.168.1.10 port = 9001; [node:<node_name2>] ### if there are multiple machines, add them in sequence; username = <username> ; password = <password> ; host = <hostname> ; port = <port> ; [environment:<environment_name>] ; members = <node_name>, <node_name2> [cesi] database = /opt/cesi/userinfo.db ### Set the db path activity_log = /data/logs/cesi/cesi.log ### Set the log path host = 0.0.0.0 At last, use http://ip:5000 to log in to view related informationCopy the code

Recommended reading

  • How to efficiently run Linux commands in the background?

  • How to quickly recall a Forgotten Linux command?

  • With this technique, you can play with your boss even when he or she is staring at you!

  • How to efficiently manage the Network using the Linux command line?

  • SAO | how to elegant under Linux terminal operation on video?


Original is not easy, if you think this article is a little useful to you, please give me a like, comment or forward for this article, because this will be my power to output more quality articles, thanks!

By the way, dig friends remember to give me a free attention yo! In case you get lost and you can’t find me next time.

See you next time!