Rotten mud: Learning Nagios (3): NRPE installation and configuration, nagiosnrip

Source: Internet
Author: User

Rotten mud: Learning Nagios (3): NRPE installation and configuration, nagiosnrip

This document consistsXiuyi Lin FengProviding friendship sponsorship, first launchedThe world

In the first two articles, we introduced the installation and configuration of nagios. The articles are "mud: Learning Nagios (1): Nagios installation" and "mud: Learning Nagios (2 ): nagios configuration, this article introduces the knowledge about NRPE.

The introduction of NRPE involves the following steps:

1. What is NRPE?

2. Working Process of NRPE

3. install and configure NRPE

4. monitor hosts through NRPE

5. PASS Parameters to NRPE

6. NRPE monitoring precautions

1. What is NRPE?

NRPE is short for Nagios Remote Plugin Executor. It is an extension tool of nagios and is used on the monitored host. It provides some local information about the host to the nagios monitoring server. For example, cpu load, memory usage, disk capacity, number of logged-in users, total number of processes, number of zombie processes, and swap partition usage.

Note: The NRPE monitoring method can only monitor the local information of the host, and cannot monitor the database.

NRPE can be called the nagios for linux client. Why is this client used?

There are two reasons:

1. nagios can only monitor its own server, but it cannot monitor other hosts. After all, it is impossible to obtain the information without obtaining the proper permissions of the monitored host. To solve this problem, we can monitor the local information of the remote host through NRPE.

2. in nagios monitoring plug-in, there is a plug-in named check_ssh, which can also monitor local information of remote hosts. However, compared with NRPE, check_ssh occupies a little more system resources. A small number of services may not be noticed, but if there are many monitored objects, the gap between the two is very obvious.

At the same time, it should be noted that the monitoring process of NRPE does not require the system account information on the remote host and does not need to log on to the system for moderate operations, so its security is higher than the check_ssh monitoring method.

Ii. Working Process of NRPE

In the previous chapter, we introduced what is NRPE. In this chapter, we will introduce how NRPE works.

NRPE consists of the check_nrpe plug-in and NRPE daemon.

The check_nrpe plug-in exists on the nagios monitoring server and monitored host. NRPE daemon only runs on the monitored host.

When nagios needs to monitor the services or resources of a remote host, the NRPE process is as follows:

1. The nagios monitoring server runs the local check_nrpe plug-in to tell it which services or resources to check.

2. The check_nrpe plug-in on the nagios monitoring server is connected to the NRPE daemon on the remote host.

3. The NRPE daemon on the remote host runs various local nagios plug-ins to monitor local services or resources.

4. NRPE daemon returns the check result to the check_nrpe plug-in on the nagios server, and then sends the result to the nagios status queue.

5. nagios reads the information in the queue in sequence and displays the result.

The above is the work process of the entire NRPE, the related is as follows:

3. install and configure NRPE

In chapter 2, we will introduce how NRPE works. To enable nagios to monitor remote hosts through NRPE, We need to install NRPE on both the nagios server and the monitored host, and install the nagios plug-in on the monitored host.

Note: The nagios plug-in must be installed on the monitored host. Otherwise, NRPE daemon cannot perform any monitoring. Because the data monitored by NRPE daemon is obtained through the nagios plug-in.

3.1NRPE is installed on the monitored host.

To install NRPE on the monitored host, first install the nagios plug-in on the monitored host, next we will introduce the configuration file of NRPE. Download the nagios plug-in as follows:

Wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz

3.1.1Create a NRPE user

After all the required software packages have been downloaded, we will now create the users required to run the NRPE daemon. NRPE daemon uses the nagios user by default, so we will first create this user. As follows:

Useradd-M-s/sbin/nologin nagios

Grep nagios/etc/passwd

3.1.2Install the nagios plugin

Now we start to install the nagios plug-in. The installation of the nagios plug-in is very simple. Just install the software as usual. As follows:

Tar-xf nagios-plugins-2.0.3.tar.gz

Cd nagios-plugins-2.0.3

Configure the nagios plug-in as follows:

./Configure

Compile and install the nagios plugin as follows:

Make & make install

View the directory after nagios plug-in is installed as follows:

Ll/usr/local/nagios/

View the installed plug-ins as follows:

Ll/usr/local/nagios/libexec/

It is obvious that the nagios plug-in already contains the check_nrpe plug-in.

3.1.3Install NRPE

After the nagios plug-in is installed, We will download the NRPE package as follows:

Http://exchange.nagios.org/directory/Addons/Monitoring-Agents/NRPE--2D-Nagios-Remote-Plugin-Executor/detail

S

Http://sourceforge.net/projects/nagios/files/nrpe-2.x/

Wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz

After downloading the NRPE package, we will install NRPE as follows:

Tar-xf nrpe-2.15.tar.gz

Cd nrpe-2.15

Configure NRPE as follows:

./Configure -- enable-command-args

Note: The -- enable-command-args parameter is very important. If you want to pass a parameter to NRPE, you must add this parameter when installing and configuring NRPE.

Compile NRPE as follows:

Make all

Install the NRPE plugin check_nrpe as follows:

Make install-plugin

We can see that check_nrep has been installed in the/usr/local/nagios/libexec/directory.

Run the following command to install NRPE:

Make install-daemon

Install the NRPE configuration file as follows:

Make install-daemon-config

For the detailed installation steps of NRPE, there are installation documents under the doc directory of the NRPE software package. As follows:

3.2Install NRPE on nagios Server

The installation of nrpe on the nagios server is similar to that on the monitored host, but the steps are not much.

Download the nrpe plug-in as follows:

Wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz

Decompress the NRPE package as follows:

Tar-xf nrpe-2.15.tar.gz

Cd nrpe-2.15

Configure NRPE as follows:

./Configure

Compile NRPE as follows:

Make all

Install the NRPE plugin check_nrpe as follows:

Make install-plugin

Check the check_nrpe plug-in as follows:

Ll/usr/local/nagios/libexec/| grep check_nrpe

Note: If you do not want to install the NRPE plug-in on the nagios server, you can also install the NRPE plug-in on the monitored host, copy the check_nrpe file under the/usr/local/nagios/libexec directory to the/usr/local/nagios/libexec directory of the nagios server, then, modify the user attributes to nagios users and grant them the execution permission.

You can upload your own monitoring script to the nagios plug-in directory in this way.

After NRPE is installed, let's test the check_nrpe plug-in. As follows:

/Usr/local/nagios/libexec/check_nrpe-H 192.168.1.248

We can see that the check_nrpe on the nagios server has been installed normally, and the NRPE on the monitored host 192.168.1.248 is working properly, and the NRPE version is 2.15. This is consistent with the version number obtained through the check_nrpe plug-in.

3.3 NRPEHelp commands

For how to use the NRPE command, you can view its help. As follows:

/Usr/local/nagios/bin/nrpe-h

By viewing the HELP command of NRPE, we know how to run NRPE, as follows:

Nrpe-c NRPE configuration file path running mode

Note: The NRPE command only exists on the monitored host.

NRPE parameters are described as follows:

-N indicates that data is not transmitted using SSL. Data is transmitted using SSL by default.

<Config_file> specifies the path of the NRPE configuration file, which is the nrpe. cfg file.

<Mode> specifies the running mode of NRPE. There are two running Modes for NRPE:

-I runs NRPE using the super daemon inetd or xinetd. To run NRPE in this way, install and configure xinetd, which is generally not used.

-D independent daemon runs NRPE, which is usually used.

3.4 NRPEConfiguration File

Before starting NRPE, let's take a look at the NRPE configuration file nrpe. cfg. The file is in the/usr/local/nagios/etc/directory by default. As follows:

Ll/usr/local/nagios/etc/

Edit the file as follows:

Egrep-v "^ # | ^ $"/usr/local/nagios/etc/nrpe. cfg

Pid_file =/var/run/nrpe. pid defines the PID file of NRPE.

Server_port = 5666 defines the port used by the NRPE daemon.

Nrpe_user = nagios nrpe_group = nagios

Defines the users and user groups used when the NRPE is running. The default users are nagios users and nagios users.

Allowed_hosts = 127.0.0.1

Defines the nagios server that is allowed to connect to the host. Multiple servers can be separated by commas. If a CIDR block is allowed, the format is as follows: 192.168.1.0/24.

Command [check_users] =/usr/local/nagios/libexec/check_users-w 5-c 10

Defines the extension plug-in command to be run when NRPE executes the check_users command.

Note: according to the above format, we can see that when NRPE executes the relevant commands, it needs to first execute the local nagios plug-in and then feedback the execution results to NRPE.

This is why we need to install the nagios plug-in on NRPE.

Here, NRPE provides some columns for monitoring local hosts. As follows:

Command [check_users] =/usr/local/nagios/libexec/check_users-w 5-c 10

Command [check_load] =/usr/local/nagios/libexec/check_load-w 15,10, 5-c 30,25, 20

Command [check_hda1] =/usr/local/nagios/libexec/check_disk-w 20%-c 10%-p/dev/hda1

Command [check_zombie_procs] =/usr/local/nagios/libexec/check_procs-w 5-c 10-s Z

Command [check_total_procs] =/usr/local/nagios/libexec/check_procs-w 150-c 200

The above is the default extension plug-in command of NRPE, which is very important. When the monitored host runs the NRPE daemon, it also runs the NRPE extension plug-in commands defined in the NRPE configuration file.

Through the above example, we can see that these extension commands have already specified the command name, plug-in path, and option parameters. The format is as follows:

Command [NRPE command name] = plug-in path/plug-in option 1 parameter 1 option 2 parameter 2...

Note: To specify the service that the monitored host needs to be monitored, you must configure the NRPE command and run it in the NRPE daemon. If the NRPE command is not configured, The nagios server cannot monitor it.

Of course, the above command format is also provided in the nrpe. cfg configuration file, as follows:

Command [<command_name>] = <command_line>

3.5Start and view the NRPE Port

After NRPE is installed, we switch to the monitored host to start NRPE, as shown below:

/Usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe. cfg-d

Ps aux | grep nrpe

View the NRPE port as follows:

Netstat-tunlp | grep nrpe

Through, we can see that the NRPE uses TCP port 5666.

4. monitor hosts through NRPE

After the NRPE is installed on the monitored host and nagios server, we can monitor the host through NRPE.

However, before the official start of monitoring, we still need to do some work.

Note: All of the following operations are performed on the nagios server.

4.1Define the check_nrpe command

To use NRPE to monitor the host, we need to define the check_nrpe command in the commands. cfg file. As follows:

Vi/usr/local/nagios/etc/objects/commands. cfg

Define command {

Command_name check_nrpe

Command_line $ USER1 $/check_nrpe-H $ HOSTADDRESS $-c $ ARG1 $}

Note:

Command_name check_nrpeDefines a command named check_nrpe. If you want to use it later, you can directly reference this command through use.

Command_line $ USER1 $/check_nrpe-H $ HOSTADDRESS $-c $ ARG1 $

Indicates the command to be executed.-c is followed by the command name defined in nrpe. cfg of the monitored host. $ ARG1 $ indicates the command defined in nrpe. cfg of the monitored host. For example:

4.2Custom referenced host and service

After the check_nrpe command is defined, we need to define a host and service template in the templates. cfg file for reference of hosts and services in the future.

Of course, this definition can also not be used in templates. cfg. You can define a cfg file separately, but this separate cfg file must be referenced in the nagios. cfg file for normal use.

In addition, if you do not want to customize the host, you can directly use the host defined in the templates. cfg file.

Note: The host, service, and other objects defined in nagios can be directly referenced using the use command.

Here we define a host and service, first define a host named ilannihost, as follows:

Vi/usr/local/nagios/etc/objects/templates. cfg

Define host {

Name ilannihost

Use generic-host

Check_period 24x7

Check_interval 5

Retry_interval 1

Max_check_attempts 10

Check_command check-host-alive

Notification_period workhours

Icationication_interval 120

Notification_options d, u, r

Contact_groups admins

Register 0

}

Where:

Name ilannihost indicates the name of the defined host is ilannihost.

Use generic-host refers to the host defined by generic-host. The host definition of generic-host is also defined in the templates. cfg file. As follows:

After the host definition is complete, Let's define the service. Define a service named ilanniservice, as follows:

Vi/usr/local/nagios/etc/objects/templates. cfg

Define service {

Name ilanniservice

Use generic-service

Max_check_attempts 4

Normal_check_interval 5

Retry_check_interval 1

Register 0

}

Where:

Name ilanniservice indicates the name of the defined service is ilanniservice.

Use generic-service refers to the service defined by generic-service. The servic definition of generic-service is also defined in the templates. cfg file. As follows:

4.3Configure the host to be monitored

After the preceding definitions of check_nrpe, host, and service are completed, we now start to configure the host to be monitored.

In order to be closer to the actual production environment, we did not add the hosts to be monitored one by one here, and then added them to nagios. the content referenced in the cfg file is modified by modifying nagios. the cfg file stores all the host cfg files in the same directory for reference purposes. As follows:

Mkdir/usr/local/nagios/etc/ilanni

Vi/usr/local/nagios/etc/nagios. cfg

Export _dir =/usr/local/nagios/etc/ilanni

Now we will add a host to be monitored, create a cfg file in the/usr/local/nagios/etc/ilanni directory, and fill in the relevant content. As follows:

Vi/usr/local/nagios/etc/ilanni/248.cfg

Define host {

Use ilannihost

Host_name ilanni

Alias test_NRPE

Address 192.168.1.248

Check_command check-host-alive

}

Define service {

Use ilanniservice

Host_name ilanni

Service_description nrpe_load

Check_command check_nrpe! Check_load

}

Note:

Host_name must be unique throughout nagios and cannot be the same as host_name; otherwise, nagios reports an error.

Check_command check_nrpe! Check_load

The check_nrpe command is defined in the commands. cfg file ,! The check_load pair should be the $ ARG1 $ parameter in the command.

Therefore, the configuration file runs the following command on the nagios server:/usr/local/nagios/libexec/check_nrpe-H 192.168.1.248-c check_load.

After the command is executed, the check_nrpe plug-in on the nagios server calls the NRPE daemon on the monitored host.

The NRPE daemon on the monitored host calls the local check_load command, and the check_load command calls the local nagios plug-in check_load. Therefore, the last command executed on the monitored host is: /usr/local/nagios/libexec/check_load-w 15,10, 5-c 30,25, 20. After the command is executed, the result is fed back to the nagios server.

After the host configuration file is modified, run the nagios Command to check whether the configuration file is faulty, as shown below:

/Usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios. cfg

If this method is difficult to check the configuration file, we can also execute the nagios STARTUP script. As follows:

/Etc/init. d/nagios configtest

We can see that the configuration files of nagios are correct.

4.4View monitored hosts

There is no problem with the nagios configuration file. Let's start nagios now and check the newly added host. As follows:

/Etc/init. d/nagios start

After nagios is started normally, we now log on to the web page to view the newly added host, as shown below:

Through the above two images, we can see that the newly added host ilanni has been monitored normally.

5. PASS Parameters to NRPE

Through the above experiment, we have successfully monitored the host through the NRPE command. However, there is still a deficiency, that is, it is not easy for us to modify the threshold value of the Monitored object. The current situation is that each modification threshold must be modified on the monitored host, which is inconvenient.

In fact, we can modify the thresholds of different monitoring hosts by passing parameters.

However, to meet the above requirements, we need to configure it on the monitored host and nagios server.

5.1Host Configuration monitored

First, when installing and configuring NRPE, you must add the parameter -- enable-command-args. We have already added this parameter when installing and configuring NRPE. As follows:

Note: If the -- enable-command-args parameter is not added when NRPE is installed and configured, delete the installed NRPE and reinstall it. This is very important.

2. Modify the dont_blame_nrpe = 1 parameter in the nrpe. cfg file. As follows:

After the above two changes are completed, we will now start to configure a monitoring object.

Modify the nrpe. cfg file, remove the comment before check_disk, and name it check_disk_nrpe, as shown below:

Vi/usr/local/nagios/etc/nrpe. cfg + 234

+ 234 indicates that 234th rows are displayed.

Command [check_disk_nrpe] =/usr/local/nagios/libexec/check_disk-w $ ARG1 $-c $ ARG2 $-p $ ARG3 $

Note: In the check_disk_nrpe command$ ARG1 $, $ ARG2 $, $ ARG3 $Parameters. The parameters we pass on the nagios server are one-to-one matching.

Note: After modifying the nrpe. cfg file, you must restart NREP daemon. As follows:

Pkill nrpe

/Usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe. cfg-d

Netstat-tunlp | grep nrpe

5.2 nagiosServer Configuration

After the modification is completed on the monitored host, we now switch to the nagios server for configuration.

Define a command named check_disk_ilanni in the command. cfg file, as follows:

Define command {

Command_name check_disk_ilanni

Command_line $ USER1 $/check_nrpe-H $ HOSTADDRESS $-c $ ARG1 $-a $ ARG2 $ ARG3 $ ARG4 $

}

Note:

Command_line $ USER1 $/check_nrpe-H $ HOSTADDRESS $-c $ ARG1 $-a $ ARG2 $ ARG3 $ ARG4 $

The $ ARG1 $ parameter in the Command receives the monitoring command defined in the nrpe. cfg file of the monitored host. Here we take the check_disk_nrpe command as an example.

-$ ARG2 $ corresponds to $ ARG1 $ parameter in the check_disk_nrpe command of the monitored host, and $ ARG3 $ parameter corresponds to $ ARG2 $ parameter in the check_disk_nrpe command of the monitored host, the $ ARG4 $ parameter corresponds to the $ ARG3 $ parameter in the check_disk_nrpe command of the monitored host.

In order to better illustrate the problem, I drew a picture:

After the above definition is complete, we now modify the 248. cfg file to define this service for the host 192.168.1.248. The content is as follows:

Define service {

Use local-service, srv-pnp

Host_name ilanni

Service_description DISK

Check_command check_disk_ilanni! Check_disk_nrpe! 10%! 5%! /Tmp

}

Check_command check_disk_ilanni! Check_disk_nrpe! 10%! 5%! /Tmp

Monitor the/tmp partition of the host 192.168.1.248. When the partition has 10% remaining, an alarm is triggered. When the partition has 5% remaining, an emergency alarm is triggered.

248. After the cfg file is configured, reload the nagios program as follows:

/Etc/init. d/nagios reload

Log on to nagios to check the actual monitoring status. As follows:

We can see that the parameters passed through the 248. cfg file have been successfully transferred to the monitored host 192.168.1.248, and the correct data is also obtained.

Vi. NRPE monitoring precautions

1. for monitoring through NRPE, if you want to modify the relevant thresholds of nagios monitoring, you must modify them in the extended commands in the nrpe. cfg file of the monitored host.

2. Monitoring Through NRPE. If you want to add a nagios monitoring object, you must first define it in the nrpe. cfg file of the monitored host.

3. NRPE daemon runs on the monitored host.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.