Install and Configure Nagios on CentOS 7

Install and Configure Nagios on CentOS 7

Nagios is an open source tool that can be used for network and infrastructure monitoring. Let’s see how to Install and Configure Nagios on CentOS 7 server to monitor servers, switches, applications and services. It alerts the System Administrator when something goes wrong and also alerts back when the issues have been rectified.

All commands should be run as root user.

Install Nagios

Install Nagios Plugins

Install NRPE

Now open the xinetd startup script in an editor:

Modify the only_from line by adding the private IP address of the your Nagios server to the end (substitute in the actual IP address of your server):

Save and exit. Only the Nagios server will be allowed to communicate with NRPE.

Restart the xinetd service to start NRPE:

Now that Nagios 4 is installed, let’s configure it.

Configure Nagios

Open the main Nagios configuration file in your favorite text editor. We’ll use vi to edit the file:

Now find and uncomment this line by deleting the #:

Save and exit.

Now create the directory that will store the configuration file for each server that you will monitor:

Configure Nagios Contacts
Open the Nagios contacts configuration in your favorite text editor. We’ll use vi to edit the file:

Find the email directive, and replace its value (the highlighted part) with your own email address:

Save and exit.

Configure check_nrpe Command
Let’s add a new command to our Nagios configuration:

Add the following to the end of the file:

Save and exit.

This allows you to use the check_nrpe command in your Nagios service definitions.

Configure Apache

Optional: Restrict Access by IP Address
If you want to restrict the IP addresses that can access the Nagios web interface, you will want to edit the Apache configuration file:

Find and comment the following two lines by adding # symbols in front of them:

Then uncomment the following lines, by deleting the # symbols, and add the IP addresses or ranges (space delimited) that you want to allow to in the Allow from line:

As these lines will appear twice in the configuration file, you will need to perform these steps once more.
Save and exit.

Now start Nagios and restart Apache to put the change into effect:

Nagios is now running, so let’s try and log in.

Accessing the Nagios Web Interface

Open your favorite web browser, and enter below URL. Update the IP address or hostname accordingly and hit enter

Because we configured Apache to use htpasswd, you must enter the login credentials that we created earlier. We used “nagiosadmin” as the username:

Adjust SELinux Settings

By default, SELinux will be in enforcing mode, and it throws “Internal Server Error” messages when you attempt to access the Nagios CGIs. To rectify this error, edit file /etc/selinux/config:

And, set SELinux to permissive mode.

Reboot your server to take effects the changes.

Monitor a CentOS 7 Host with NRPE

In this section, we’ll show you how to add a new host to Nagios, so it will be monitored. Repeat this section for each CentOS or RHEL server you wish to monitor.

On a server that you want to monitor, install the EPEL repository:

Now install Nagios Plugins and NRPE:

Now, let’s update the NRPE configuration file. Open it in your favorite editor (we’re using vi):

Find the allowed_hosts directive, and add the private IP address of your Nagios server to the comma-delimited list (substitute it in place of the highlighted example):

Save and exit. This configures NRPE to accept requests from your Nagios server, via its private IP address.

Once you are done installing and configuring NRPE on the hosts that you want to monitor, you will have to add these hosts to your Nagios server configuration before it will start monitoring them.

Add Host to Nagios Configuration

On your Nagios server, create a new configuration file for each of the remote hosts that you want to monitor in /usr/local/nagios/etc/servers/. Replace the highlighted word, “yourhost”, with the name of your host:

Add in the following host definition, replacing the host_name value with your remote hostname (“web-1” in the example), the alias value with a description of the host, and the address value with the private IP address of the remote host:

With the configuration file above, Nagios will only monitor if the host is up or down. If this is sufficient for you, save and exit then restart Nagios. If you want to monitor particular services, read on.

Add any of these service blocks for services you want to monitor. Note that the value of check_command determines what will be monitored, including status threshold values. Here are some examples that you can add to your host’s configuration file:

If you’re not sure what use generic-service means, it is simply inheriting the values of a service template called “generic-service” that is defined by default.

Now save and quit. Reload your Nagios configuration to put any changes into effect:

Once you are done configuring Nagios to monitor all of your remote hosts, you should be set. Be sure to access your Nagios web interface, and check out the Services page to see all of your monitored hosts and services:

Hope this helps you.. Any comments or suggestoins would be highly appreciated. Thanks 🙂

Share this post

Leave a comment

Your email address will not be published.