In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Supervisor is a tool developed by Python to monitor the running status of processes on class UNIX. When deploying Python Web, such an architecture is often used, namely Nginx + Gunicorn + Supervisor + Django/Flask/Tornado/Webpy/Pyramid. The role of Supervisor here is to monitor the Gunicorn, restart it after the Gunicorn is down, and enhance the stability of the system. By extension, Supervisor can be used to monitor Tomcat,MySQL,Redis and so on. Its installation and use are described below.
1. Installation
Supervisor can only run in UNIX-like systems, such as Linux,Mac OS and Solaris, and does not support any version of Windows systems. At the same time, Supervisor requires Python support for Python 2.4 or later.
Two installation methods are described below.
1.1 pip mode
When the system has installed pip and can connect to the public network, the installation is very simple. Like yum install and apt-get, pip install automatically installs dependent files:
[root@localhost ~] # pip install supervisor1.2 manual installation
Manual installation can be divided into situations where you can connect to the external network and cannot connect to the external network, both of which require the support of setuptools, otherwise in the
Python setup.py install
The following error will be reported:
Traceback (most recent call last): File "setup.py", line 32, in from setuptools import setup, find_packagesImportError: No module named setuptools
You can refer to here for the installation of pip and setuptools.
1.2.1 you can connect to the external network
When you can connect to the public network, python setup.py install automatically installs dependent files:
[root@localhost ~] # cd / usr/local/src [root@localhost src] # wget https://pypi.python.org/packages/source/s/supervisor/supervisor-3.1.3.tar.gz[root@localhost src] # tar zxf supervisor-3.1.3.tar.gz [root@localhost src] # cd supervisor-3.1.3 [root@localhost supervisor-3.1.3] # python setup.py install1.2.1 cannot connect to the public network
If you cannot connect to the public network, you need to manually install the files that Supervisor depends on, as listed below:
Meld3
Elementtree
Among them, meld3 must be installed, but elementtree bloggers have not installed it and can still succeed. Readers can try it after installing meld3. If Supervisor can be installed successfully, they can no longer install elementtree.
For how to install dependent files, please refer to Section 1.2.1, which will not be repeated here.
After the installation is successful, there are four more command files, supervisord,supervisorctl,pidproxy,echo_supervisord_conf, which are located in the python installation directory (related to pip configuration), such as / usr/local/python2.7.10/bin/supervisord
two。 Use
Supervisor's configuration file is in the style of a Windows ini file, commenting on the content starting with;. Use the echo_supervisord_conf command generated after installing Supervisor to generate a profile template:
[root@localhost ~] # / usr/local/python2.7.10/bin/echo_supervisord_conf > > / etc/supervisord.conf
To get started quickly, only a few modifications are made to the generated profile template. A detailed description of the configuration file can be found here.
2.1 launch Supervisor as root user
If we start Supervisor as root user, we need to specify user=root under [supervisord]:
[supervisord]... user=root...
Start Supervisor:
[root@localhost] # supervisord-c / etc/supervisord.conf
The point to be made here is that when running Supervisor, if you do not use the-c option to specify the configuration file to use, Supervisor automatically looks for the configuration file in the following location:
$CWD/supervisord.conf$CWD/etc/supervisord.conf/etc/supervisord.conf
If no configuration files are found in these locations, the following error message is reported:
Error: No config file found at default paths (/ usr/etc/supervisord.conf, / usr/supervisord.conf, supervisord.conf, etc/supervisord.conf, / etc/supervisord.conf); use the-c option to specify a config file at a different path2.2 monitoring process
Modify the configuration file and add the configuration in [program:custom_name]. Here we take monitoring redis as an example:
[program:redis_monitor] command=/usr/local/redis/bin/redis-server / etc/redis.conf; specify the command to monitor, important directory=/root; specify the directory in which the command runs autorestart=true; specify the circumstances under which to automatically restart user=root; specify which user to run the command command; other configurations can use default values
To restart Supervisor, it is recommended to start it in the following way, put it in the background, and put the running log of supervisord into nohup.out:
[root@localhost] # nohup supervisord-n-c / etc/supervisord.conf & 2.3supervisorctl
Supervisorctl is a command line console of Supervisor, which can be used to restart and shut down supervisord conveniently, and also to start and shut down individual [program:custom_name] process monitoring. It is very convenient to operate when there are many monitored processes, and can selectively start and shut down monitored processes. Here is a brief introduction to its usage.
Supervisorctl is configured in the configuration file supervisord.conf
[unix_http_server]; use unix socket to connect to supervisord server; enable file=/tmp/supervisor.sock by default; specify the location of the socket file; chmod=0700; specify the permissions of the socket file, default is 0700; socket file owner and group; username=user; specify the user name to be used when connecting to the supervisorctl, which is not required by default; password=123 Specify the password you need to use when connecting to supervisorctl, which is not required by default; [inet_http_server]; use HTPP to connect to supervisord server, which is turned off by default; port=127.0.0.1:9001; specify the ip address and port number that can be used to connect to supervisord server. *: port opens connection permissions for any ip; username=user Specify the user name you need to use when connecting to supervisorctl, which is not required by default; password=123; specify the password you need to use when connecting to supervisorctl, and do not need the password [supervisorctl] serverurl=unix:///tmp/supervisor.sock by default; connect to supervisord server;serverurl= http://127.0.0.1:9001 using unix socket; connect to supervisord server;username=chris using HTTP; specify the user name to use when connecting to server Password=123; specify the password to use when connecting to server; prompt=mysupervisor; command line prompt, default is supervisor >; history_file=~/.sc_history; Open command line history, you can use the ↑↓ key to find history commands
Supervisorctl cannot be used to open supervisord remotely. Use the following command to connect the opened Supervisord, where-s specifies the form of the connection server (unix socket/HTTP),-u specifies the user name, and-p specifies the password:
[root@localhost] # supervisorctl-s unix:///tmp/supervisor.sock-u user-p 123
If you have configured these parameters in [supervisorctl] in the configuration file, you can directly execute the configuration file to connect.
[root@localhost] # supervisorctl-c / etc/supervisord.confredis.monitor RUNNING pid 54662, uptime 0:49:38
After a successful connection, you can view the available commands and the role of each command through the help command:
Supervisor > helpdefault commands (type help): = = add clear fg open quit remove restart start stop update avail exit maintail pid reload reread shutdown status tail versionsupervisor > help reloadreload Restart the remote supervisord.
I will not elaborate on the role of each command here. Another point is that when you open [inet_http_server], you can view the running status of supervisord from the browser, and readers can try it for themselves.
Supervisor not only monitors progress, but also has other functions. Here we only introduce this common feature, and interested readers can refer to its official documentation.
End.
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.