1. Principle of realization
A variety of servers in the network need to be managed and maintained, the administrator can not be in time for each of the status of the monitoring, it is necessary to use the function of the software to achieve. Nagios's function is to monitor the service and host, but he does not include this part of the function, all monitoring, detection functions are through a variety of plug-ins to complete. Start Nagios, it will periodically automatically invoke the plug-in to detect the server state, while Nagios will maintain a queue, all plug-ins returned to the status of information are entered the queue, Nagios each time from the beginning of the team to read information, and processing, the status results through the Web display. Nagios provides a number of plug-ins that make it easy to monitor many service states. After the installation is complete, in the Nagios home directory in the/libexec in the Nagios can use all the plug-ins, such as Check_disk is to check the disk space plug-ins, check_load check the CPU load, and so on. Each plug-in can view its usage and functionality by running./check_xxx–h. Nagios can identify 4 state return information, that is, 0 (OK) indicates that the state is normal, 1 (WARNING) indicates that a certain exception occurred, 2 (CRITICAL) indicates a very eye error, 3 (UNKNOWN) indicates that the monitored object has stopped. Nagios based on the value returned by the plug-in to determine the status of the monitoring object, and through the web display, for the administrator to find fault in time.
2. The use of Nagios NRPE plug-ins to achieve network server monitoring
Knowing how Nagios manages the server object through Plug-ins, it's time to start studying how it manages remote server objects. The Nagios system provides a plug-in NRPE. Nagios runs it periodically to obtain various state information for the remote server. The relationship between them is shown in the following illustration:
Nagios through NRPE to remote management services
1.Nagios executes the Check_nrpe plugin installed inside it and tells Check_nrpe what services to check.
2. Connect the Nrpe daemon on the remote machine via Ssl,check_nrpe
3.NRPE run a variety of local plug-ins to detect local service and status (Check_disk,.. etc
4. Finally, NRPE the results to the host-side Check_nrpe,check_nrpe and sends the results to the Nagios status queue.
5.Nagios sequentially reads the information in the queue, and then displays the results.
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/soft/tools/
The following is an example of how to monitor a remote server's CPU load and how to implement remote server management through NRPE. Assume that there is a remote server IP is the 10.20.0.110,nagios service host IP is: 10.20.10.1. They are already installed on the Nagios system, the host through the NRPE check the running server CPU load, when the load of more than 80% is issued a warning (WARNING) report, more than 95% issued an emergency (CRITICAL) report. There is a check_load-w $ARG 1$-C $ARG 2$ plug-in in the Nagios plug-in that, by viewing its help, checks the CPU load on the object host when Nagios calls it, and warns ($arg1$) when the specified value is reached WARNING An emergency report (CRITICAL) is issued $ARG 2$.
The first is the modification on the remote server:
1. Let Nagios users have the right to use the following documents:
Chown Nagios.nagios/usr/local/nagios chown–r Nagios.nagios/usr/local/nagios/libexec Then if XINETD is not installed, the XINETD is installed first.
2. Install the Nrpe plugin in accordance with the Nagios document.
3. Modify File/etc/xinetd.d/nrpe:
Only_from = 127.0.0.1 10.20.10.1 (This is the IP of the Nagios host)
Nrpe allows the above IP machines to query services via Nrpe
4. Add in/etc/service file:
Nrpe 5666/tcp #nrpe then service xinetd restart
5. Implementation: Netstat–at | grep Nrpe
If present: TCP 0 0 *:nrpe *:* LISTEN Note Nrpe Monitor has been successfully activated.
6. Implementation of/usr/local/nagios/libexec/check_nrpe–h localhost
The NRPE v 2.8.1 appears and the installation succeeds.
7. Confirm that the local firewall allows remote servers to access NRPE daemon:
Iptables-irh-firewall-1-input-p tcp-m tcp–dport 5666-j ACCEPT service iptables save 8. Open/usr/local/nagios/etc/command S.cfg, find the Check_load service, modify the following:
Define command {command_name check_server_load command_line $USER 1$/check_load-w 80%-C 95%} 9. Open/usr/local/nagios/etc /nrpe.cfg can see that some detection services have been defined by default, such as:
/usr/local/nagios/libexec/check_nrpe-h localhost-c check_users/usr/local/nagios/libexec/check_nrpe-h localhost-c Check_load/usr/local/nagios/libexec/check_nrpe-h localhost-c check_hda1 comment out other service definitions except Check_load.
Finally, the modifications on the Nagios host:
1 Install the Nrpe plugin on the Nagios host.
2 Open/usr/local/nagios/etc/command.cfg Add the following line:
Define command{command_name Check_nrpe command_line $USER 1$/check_nrpe–h 10.20.0.110-c $ARG 1$ 3 again in the configuration file defined by the object (host.cfg , modify the IP address of the host to be detected, and then add the command to be detected in the service:
Define Service {Use Linux-service service_description remote_cpu_load check_command check_nrpe!check_load} 4 in NAGIOS.CF G main configuration file, Cfg_file value is host.cfg, run
/usr/local/nagios/bin/nagios–v/usr/local/nagios/etc/nagios.cfg if it's not wrong, start Nagios:
Service Nagios Start (restart,stop) 5 Open browser: http://host Ip/nagios
You can see this information for the remote machine being monitored (Check_server_load's return result), as shown in Figure 2. The normal state is in green, and once the remote server loads more than 80%, the status information becomes Red Alert administrator.