Process Monitoring Tool Supervisor starts MongoDB
1. What is a supervisor?
Superviosr is a process monitoring tool on a UNIX-like system. Supervisor is a Python-developed client/server system that can manage and monitor processes on * nix. However, like daemontools, it cannot monitor daemon processes.
Official Website: http://supervisord.org/
Second, use a supervisor.
Simple deployment: Why is it simple? Because when we usually manage linux processes, we generally need to write a script that can implement the start, stop, restart, and reload functions of the process, and then drop it under/etc/init. d. This is a lot of bad things. First, we need to write this script, which is time-consuming and labor-intensive. Second, when this process fails, linux will not automatically restart it. If we want to restart it automatically, We need to write a monitoring restart script. However, supervisor can solve these problems perfectly. Well, how can we solve this problem? In fact, the supervisor management process is to start these processes as sub-processes of the supervisor through fork/exec. In this case, we only need to write the executable file path of the process to be managed into the supervisor configuration file. This saves us the trouble of writing control scripts by ourselves when we are like a linux management process. Second, the managed process acts as the sub-process of the supervisor. When the sub-process fails, the parent process can accurately obtain the information of the sub-process, so of course, You can automatically restart the crashed sub-process. Of course, restart is still not restarted. It also depends on the setting of autostart = true in your configuration file.
Centralized management: Processes and process group information managed by the supervisor are all written in an ini file. In addition, we can manage the supervisor locally or remotely. In addition, the supervisor provides a web interface that allows us to monitor and manage processes. Of course, you need to call the xml_rpc interface of the supervisor during remote and web management.
Processes and process group information managed by the supervisor are all written in an ini file. In addition, we can manage the supervisor locally or remotely. In addition, the supervisor provides a web interface that allows us to monitor and manage processes. Of course, you need to call the xml_rpc interface of the supervisor during remote and web management.
Precision
Why is it accurate? Because the linux feedback on the Process status is sometimes inaccurate. Why is it inaccurate? I don't know the owner either. This is what the official document says. I am very grateful to you for telling me what you know. The supervisor monitors sub-processes, and the obtained sub-process status is undoubtedly accurate.
Process Group
Supervisor can manage process groups in a unified manner, that is to say, we can write processes to be managed into a group, and then we manage this group as an object, such as start and stop, restart and other operations. Linux does not have this function. If we want to stop a process, we can only stop it one by one, or write a script to stop it in batches.
Permission
As we all know, linux processes, especially those listening on port 1024, cannot be controlled in most cases. You must have the root permission. The supervisor provides a function to set a non-root user for supervisord or each sub-process, and the user can manage the corresponding process.
However, this function can be used in your own environment.
Three supervisor Structure
Supervisord: the master process, responsible for managing the process server. It creates a specified number of application sub-processes based on the configuration file, manages the entire lifecycle of sub-processes, and restarts crash processes, sends Event Notifications to process changes. Built-in web server and XML-RPC Interface for easy process management.
Supervisorctl: manages the client. You can send a message to supervisord through the command line to view the process status, load the configuration file, start and stop the process, view the process standard output and error output, and perform remote operations.
Web server: supervisr provides the web server function to control processes through web.
XML-RPC interface: XML-RPC interface that provides XML-RPC services to manage and monitor child Processes
Iv. installation and deployment
To unify python versions and various dependent libraries, we recommend that you use pyrun to deploy python instead of the system. You also need to install pip in pyrun, download the installation package to the pkg directory, and execute the following command:
/Data/pyrun/bin/pip install -- no-index-f pkg meld3 = 1.0.0
/Data/pyrun/bin/pip install -- no-index-f pkg elementtree = 1.2.6-20050316
/Data/pyrun/bin/pip install -- no-index-f pkg supervisor = 3.2.0
If the machine cannot be connected to the Internet, you can install it in the source code:
1) python-dependent version can be upgraded
2) third-party packages including meld3, setuptools, and ElementTree are required.
Setuptools (latest) from http://pypi.python.org/pypi/setuptools.
Meld3 (latest) from http://www.plope.com/software/meld3.
Elementtree (latest) from http://effbot.org/downloads#elementtree.
3) decompress the package root and install the package in batches.
5. Configuration
The configuration file of the Supervisor is named supervisord. conf, which provides configuration option settings for supervisord (the main service command of the Supervisor) and supervisorctl (the Monitoring and Management command of the Supervisor. The Supervisor does not specify the storage location of the configuration file supervisord. conf. By default, when the Supervisor service is started:
- $ CWD/supervisord. conf
- $ CWD/etc/supervisord. conf
- /Etc/supervisord. conf
Find the configuration file supervisord. conf in these directories.
The Supervisor also provides the "-c" parameter to specify the directory path of the configuration file.
Enter the "echo_supervisord_conf" command on the terminal to view the default configurations of the Supervisor.
Generate a default configuration file:
Echo_supervisord_conf>/etc/supervisord. conf
The supervisor configuration is relatively simple. The following configuration items meet basic requirements. For more configuration items, refer to official configuration instructions.
[Supervisord]
Nodeamon = false # start the process in deamon Mode
[Supervisorctl] # use the default system configuration item
[Inet_http_server] # port and user password on the web Management page
Port = 8080
Username = user
Password = pwd
[Rpcinterface: supervisor] # xml-rpc Interface Configuration
Supervisor. rpcinterface_factory = supervisor. rpcinterface: make_main_rpcinterface
[Program: mongodb]
Command =/data1/mongodb_2.4.7_build/mongod-config/data1/mongodbrs/config/mongodb. conf -- directoryperdb -- quiet -- profile 1 -- slowms 1000 -- noprealloc -- shardsvr
Directory =/data1/mongodb_2.4.7_build
Autostart = false
User = root
Note the last few lines of the default configuration file
You can add separate. ini files in the supervisord. d directory under the same directory as the supervisord. conf file.
[Include]
Files = supervisord. d/*. ini
Note: The monitored process must run in non-daemon mode. Take mongodb as an example. You need to remove the -- fork parameter in the mongodb process startup command.
6. Use
# Start a supervisor
Python/usr/bin/supervisord
# Start the monitoring process
Supervisorctl start all
# Shut down the monitoring process
Supervisorctl stop all
# Viewing Status
Supervisorctl status
# Reload the configuration file:
Supervisorctl reload
In fact, you can use supervisorctl to open the command line console of the supervisor, and enter help to view the commands used. Then, the help + command can view the specific functions of each command.
7. web Control
Configure [inet_http_server] In supervisord. conf,
[Inet_http_server]
Port = 0.0.0.0: 8080 # IP address and bound port
Username = admin # Administrator name
Password = 123456 # administrator password
In this way, enter the address and port number written in the configuration in the browser, enter the configured user name and password, and you will be able to see the webpage-based console interface. From this, you can view the> information monitored by the supervisor, and view the process logs.
Browser access: http: // 10.14.4.84: 8080/, (the IP address here is the IP address used to deploy the supervisor)
8. Monitoring and alarms
If you only need to automatically pull the crash process and manage the process through the command line, the above content is sufficient. Supervisor 3.0 introduces events. With this feature, we can monitor the process status and generate alarms in real time.
First, let's take a look at the events provided by the supervisor. The supervisor manages applications through sub-processes, and the monitoring program runs as a sub-process. The stdin, stdout, and stderr of sub-processes have been redirected. The event processing process is as follows:
- Write READY \ n to stdout as a sub-process of the listener
- When an event occurs, the supervisor selects the stdin of a sub-process in Ready status to write the event content.
- After the sub-process event is processed, write OK \ n or FAIL \ n to stdout to report the processing result.
- Repeat the preceding operations
Supervisor provides a variety of event types, including process status events, supervisor status events, scheduled events, xmlrpc call events, process log events, and so on. We focus on process status events. The supervisor defines the following States for the process, and each State switch will trigger the corresponding event.
The monitoring program can be written in any language, as long as the event message is processed correctly according to the supervisor protocol format. We recommend that you use python as the monitoring program. The supervisor provides a childutils module to simplify the process writing.
For more MongoDB tutorials, see the following:
CentOS compilation and installation of php extensions for MongoDB and mongoDB
CentOS 6 install MongoDB and server configuration using yum
Install MongoDB2.4.3 in Ubuntu 13.04
MongoDB beginners must read (both concepts and practices)
MongoDB Installation Guide for Ubunu 14.04
MongoDB authoritative Guide (The Definitive Guide) in English [PDF]
Nagios monitoring MongoDB sharded cluster service practice
Build MongoDB Service Based on CentOS 6.5 Operating System
MongoDB details: click here
MongoDB: click here
9. Extended reading
On github, two centralized process management tools based on the second development of supervisor can manage processes of multiple machines on one page.
Https://github.com/mlazarov/supervisord-monitor
Https://github.com/TAKEALOT/nodervisor
This article permanently updates the link address: