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:
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:
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:
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:
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:
领英推荐
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:
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:
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:
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:
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.