Install And Configure Nagios 4 On CentOS 7

Introduction

Nagios is an open source software that can be used for network and infrastructure monitoring. Nagios will monitor servers, switches, applications and services. It alerts the System Administrator when something went wrong and also alerts back when the issues has been rectified.

Features

·         Monitor your entire IT infrastructure;

·         Identify problems before they occur;

·         Know immediately when problems arise;

·         Share availability data with stakeholders.hypothetical question;

·         Detect security breaches;

·         Plan and budget for IT upgrades;

·         Reduce downtime and business losses.

Scenario

In this tutorial i am going to use two systems as mentioned below.

Nagios server:

Operating system : CentOS 7 minimal server

IP Address       : 192.168.1.150/24

Nagios client:

Operating System : CentOS 7 minimal server

IP Address       : 192.168.1.152/24

Prerequisites

Before installing Nagios, make sure that you’ve a properly installed and configured LAMP stack in your server. To install and configure LAMP server, refer the following link.

·         Install LAMP server On CentOS/RHEL/Scientific Linux 7

Also install the following prerequisites too. All commands should be run as root user.

yum install gd gd-devel gcc glibc glibc-common wget

Create Nagios User And Group

Create a new nagios user account and give it a password:

useradd -m nagios

passwd nagios

Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.

groupadd nagcmd

usermod -a -G nagcmd nagios

usermod -a -G nagcmd apache

Download Nagios And Plugins

Go to the nagios download page, and get the latest version. As of writing this, the latest version was 4.0.8.

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz

And, download nagios plugins too.

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

Install Nagios And Plugins

Install nagios:

I tested this how-to on CentOS 7 minimal server, although it should work on all RHEL 7 and its clones like Scientific Linux 7 too.

Go to the folder where you’ve downloaded nagios, and extract it using command:

tar xzf nagios-4.0.8.tar.gz

Change to the nagios directory, and run the following commands one by one from the Terminal to compile and install nagios.

cd nagios-4.0.8

./configure --with-command-group=nagcmd

make all

make install

make install-init

make install-config

make install-commandmode

Install Nagios Web interface:

Enter the following commands to compile and install nagios web interface.

make install-webconf

Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account. You’ll need it while logging in to nagios web interface..

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Restart Apache to make the new settings take effect.

systemctl restart httpd

Install Nagios plugins:

Go to the directory where you downloaded the nagios plugins, and extract it.

tar xzf nagios-plugins-2.0.3.tar.gz

Change to the nagios plugins directory:

cd nagios-plugins-2.0.3

Run the following commands one by one to compile and install it.

./configure --with-nagios-user=nagios --with-nagios-group=nagios

make

make install

We aren’t finished yet.

Configure Nagios

Nagios sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. However, you’ll need to put your actual email ID to receive alerts.

To do that, Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts.

vi /usr/local/nagios/etc/objects/contacts.cfg

Find the following line and enter the email id:

[...]

define contact{

        contact_name                    nagiosadmin             ; Short name of user

        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)

        alias                           Nagios Admin            ; Full name of user

 

        email                           sk@unixmen.com  ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

        }

[...]

Save and close the file.

Then, Edit file /etc/httpd/conf.d/nagios.conf,

vi /etc/httpd/conf.d/nagios.conf

And edit the following lines if you want to access nagios administrative console from a particular IP series. Here, I want to allow nagios administrative access from 192.168.1.0/24 series only.

[...]

## Comment the following lines ##

<p class="MsoNormal" style="margin-bottom:7.5pt;line-height:15.0pt;tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt
Was this answer helpful? 135 Users Found This Useful (139 Votes)