Configuring NRPE and Monitoring Remote Servers with Nagios – Setting Up a Master and Remote Server with Nagios on CentOS 7 Using Vagrant – Part 2

Configuring NRPE and Monitoring Remote Servers with Nagios – Setting Up a Master and Remote Server with Nagios on CentOS 7 Using Vagrant – Part 2

After successfully setting up the Nagios master server, the next step is to configure Nagios Remote Plugin Executor (NRPE) on your Nagios server and set up monitoring for your remote server.

Accessing the Nagios Web Interface

Before proceeding, ensure you can access the Nagios web interface. Open your browser and navigate to:

https://192.100.10.10/nagios/        

Login using the credentials:

  • Username: nagiosadmin
  • Password: The password you set during the htpasswd configuration.

This interface will allow you to monitor and manage your servers and services.


Installing NRPE and Plugins on the Master Server

NRPE is necessary for executing plugins on remote hosts. To set up NRPE on your Nagios master server, follow these steps:

Step 1: Install EPEL Repository

First, install the Extra Packages for Enterprise Linux (EPEL) repository, which provides additional packages for CentOS.

sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm        

Explanation:

  • rpm -Uvh: Installs or upgrades a package and displays a progress bar with the -Uvh option.

Step 2: Install NRPE and Nagios Plugins

Install NRPE and the necessary Nagios plugins:

sudo yum --enablerepo=epel -y install nrpe nagios-plugins nagios-plugins-all
sudo yum install -y nagios-plugins-nrpe
sudo yum --enablerepo=epel -y list nagios-plugins*        

Explanation:

  • --enablerepo=epel: Enables the EPEL repository.
  • nagios-plugins-all: Installs all available plugins, ensuring you have the tools needed to monitor a wide range of services.
  • yum list: Lists all installed and available Nagios plugins.

Example: To confirm installation, you can list the Nagios plugins by running yum list installed | grep nagios.

Step 3: Create a Symlink for check_nrpe

Create a symbolic link for the check_nrpe plugin to ensure it’s accessible:

sudo ln -s /usr/lib64/nagios/plugins/check_nrpe /usr/local/nagios/libexec/check_nrpe        

Explanation:

  • ln -s: Creates a symbolic link, which is a pointer to another file. This allows Nagios to find the check_nrpe plugin easily.


Configuring NRPE Commands in Nagios

Next, we’ll configure Nagios to use NRPE for checking services on remote hosts.

Step 4: Define the check_nrpe Command

Edit the Nagios command configuration file to define the check_nrpe command:

sudo vim /usr/local/nagios/etc/objects/commands.cfg        

Add the following configuration:

define command {
   command_name check_nrpe
   command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}        

Explanation:

  • command_name check_nrpe: Names the command check_nrpe.
  • command_line: Specifies the command line that Nagios will execute, replacing $HOSTADDRESS$ and $ARG1$ with the actual host address and command arguments during execution.

Step 5: Configure Nagios to Monitor Remote Servers

Create a directory to store configuration files for remote servers:

sudo mkdir /usr/local/nagios/etc/servers        

Then, edit the Nagios configuration file to include this directory:

sudo vim /usr/local/nagios/etc/nagios.cfg        

Add the following line:

cfg_dir=/usr/local/nagios/etc/servers        

Explanation:

  • cfg_dir: Instructs Nagios to look in this directory for additional configuration files, making it easier to manage multiple server configurations.

Example: Each remote server you want to monitor will have its configuration file in the servers directory.

Step 6: Define the Remote Server Configuration

Create a configuration file for the remote server:

sudo vim /usr/local/nagios/etc/servers/remote.cfg        

Add the following content to define the remote server and the services you want to monitor:

define host {
      use                   linux-server
      host_name             remote
      alias                 my remote server
      hostgroups            linux-servers  
      address               192.100.10.20
      max_check_attempts    5
      check_period          24x7
      notification_interval 30
      notification_period   24x7
}

define service {
      use                   generic-service
      host_name             remote
      service_description   SSH
      check_command         check_ssh
      notifications_enabled 0
}

define service {
      use                   generic-service
      host_name             remote
      service_description   CPU Load
      check_command         check_nrpe!check_load   
}        

Explanation:

  • define host: Defines a remote server with its IP address and monitoring details.
  • define service: Specifies the services (e.g., SSH, CPU Load) to be monitored on the remote server.

Example: The check_command field uses the check_nrpe command to monitor the remote server’s CPU load, and the check_ssh command to verify SSH availability.

Step 7: Verify and Restart Nagios

After setting up the configuration, verify it with the following command:

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

If everything checks out, restart Nagios to apply the new configuration:

sudo systemctl restart nagios        

Explanation:

  • nagios -v: Verifies the configuration file for syntax errors.
  • systemctl restart: Restarts the Nagios service, reloading the new configuration.

Example: You can monitor the status of Nagios with sudo systemctl status nagios.


Testing NRPE

To ensure that NRPE is working correctly, execute the following command from the Nagios server:

check_nrpe -H 192.100.10.20        

Explanation:

  • This command tests the connection to the remote server (IP: 192.100.10.20) using NRPE.

Example: If successful, the command will return information from the remote server. If there is an issue, it will return an error message, which will guide troubleshooting.

With NRPE configured, your Nagios setup is now capable of monitoring remote servers in your network. You can expand this setup by adding more servers and services to be monitored, ensuring comprehensive oversight of your IT infrastructure.


要查看或添加评论,请登录

Ali Imran的更多文章

社区洞察

其他会员也浏览了