How to Install and configure Nagios 4.x on Centos 7.x


What Is Nagios Core:-

Nagios Core is an Open Source system and network monitoring application. It watches hosts and services that you specify, alerting you when things go bad and when they get better.

System Requirments:-


1- Linux machine (In my case I am using Centos7.X)
2- HTTPd, PHP with gd and CGI.

Nagios Installation:-

Step 1- Install and setup prerequisites 
 Install Deployment tool 
[root@localhost ~]# yum groupinstall "Development Tools"

Install PHP, HTTPD, Pearl and wget
[root@localhost ~]# yum install wget perl httpd php gcc glibc glibc-common gd gd-devel make net-snmp libpng-devel libjpeg-turbo-devel

Create nagios User and group:
[root@localhost ~]# useradd nagios && passwd nagios      ##Command to add user and set password ##
[root@localhost ~]# groupadd nagcmd
## Command to add group ##
[root@localhost ~]# usermod -a -G nagcmd nagios
## command to add nagios user in group nagcmd ##
[root@localhost ~]# usermod -a -G nagcmd apache ## Command to add apache user in group nagcmd ##

Step 2- Install and configure Nagios
Download Nagios stable release 
[root@localhost ~]# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.4.tar.gz
 Extract and Configure
[root@localhost ~]# tar zxfv nagios-4.2.4.tar.gz
Now go to extracted directory
[root@localhost ~]# cd nagios-4.2.4

Configure Nagios for installation
[root@localhost nagios-4.2.4]# ./configure -with-command-group=nagcmd

Make and install all the configuration files
[root@localhost nagios-4.2.4]# make all
[root@localhost nagios-4.2.4]# make install
[root@localhost nagios-4.2.4]# make install-init
[root@localhost nagios-4.2.4]# make install-commandmode
[root@localhost nagios-4.2.4]# make install-config
[root@localhost nagios-4.2.4]# make install-webconf

Copy eventhandlers and set permission
[root@localhost nagios-4.2.4]# cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/

[root@localhost nagios-4.2.4]# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
Copy Check Nagios configuration and add Nagios login credentials 
[root@localhost nagios-4.2.4]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios Core 4.2.4
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 12-07-2016
License: GPL

Website: https://www.nagios.org
Reading configuration data...
Read main config file okay...
Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 contact groups.
Checked 26 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors: 0


Setup Nagios login credentials
[root@localhost nagios-4.2.4]#  htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
*********
Re-type new password:
*********

Adding password for user nagiosadmin


Install Nagios Plugins and NRPE client
[root@localhost nagios-4.2.4]# yum install nagios-plugins-all nagios-plugins-nrpe

Update Firewall-cmd and allow http access
[root@localhost nagios-4.2.4]# firewall-cmd --permanent --add-service=http

[root@localhost nagios-4.2.4]# firewall-cmd --reload

Change plugins access user from this file "usr/local/nagios/etc/resource.cfg"
[root@localhost nagios-4.2.4]# vi /usr/local/nagios/etc/resource.cfg
Made changes as follow
# Sets $USER1$ to be the path to the plugins
#$USER1$=/usr/local/nagios/libexec
$USER1$=//usr/lib64/nagios/plugins

# Sets $USER2$ to be the path to event handlers
#$USER2$=/usr/local/nagios/libexec/eventhandlers
Enable Nagios and httpd service to start at boot time 
[root@localhost nagios-4.2.4]# systemctl enable httpd && systemctl enable nagios
Now reload httpd and nagios service
[root@localhost nagios-4.2.4]# systemctl restart httpd && systemctl restart nagios

Installation and configuration part completed successfully.
Let's check through URL: http://192.168.102.11/nagios/



















!!! Congrats Nagios 4.x installation and configuration part completed successfully !!!


In the next blog we will learn how to configure pnp4nagios to generate graph and view usage of resource whenever needed.