Monitoring

How to install Nagios 4.2.0 on RHEL/CentOS and Fedora

Nagios is the most popular and famous web based Linux Monitoring tool. Nagios is fee for everybody and it allows to monitor CPU Loads, RAM consumption, Network response time, CPU usages, Number of logged in users etc. We can say Nagios keeps eyes on usage of system resources.It is very difficult to list here everything that can be monitored by Nagios. Nagios server collects all information form Local System and Nagios agents (Clients). Means We can install Nagios agent on number of Linux System, Windows hosts, BSD, or Cisco Devices to send the system resource usage to Nagios server. If there are any outage detected by Nagios server it will trigger a mail.It supports wide range of alerts system including email, chat messages, sms and phone call notifications. We can use large number of official and third party plugins to extend Nagios functionality.

Recently Nagios released its latest version Nagios 4.2.0. In this article I am going to guide how you can install Nagios 4.2.0 released from source (tarball) on RHEL/CentOS and Fedora.

Step #1: Install Nagios Dependencies

First of all you will need to install nagios required dependencies such as Apache, PHP and some libraries like gcc, glibc-common and GD libraries.

# yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp
On Fedora 22+
# dnf install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp

Step #2: Create Nagios User and Group

Now create nagios user and group and set a password using below command.

# useradd nagios
# groupadd nagcmd

Add both the nagios and apache user to nagcmd group.

# usermod -G nagcmd nagios
# usermod -G nagcmd apache

Step #3: Download Nagios Core 4.2.0 and Its Plugin

Now create a directory for Nagios installation and download tar file.

# mkdir /root/download
# cd /root/download

Nagios Core
# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.2.0.tar.gz

Nagios Core
# wget https://www.nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz

Step #4: Untar Nagios Core and its Plugins

You will need to extract downloaded tar file with tar command like below.

# tar -xvf nagios-4.2.0.tar.gz # tar -xvf nagios-plugins-2.1.2.tar.gz

Verify downloaded tar files.

# ls -l
total 13528
drwxrwxr-x. 18 root root     4096 Aug 20  2015 nagios-4.2.0
-rw-r--r--.  1 root root 11142182 Aug 20  2015 nagios-4.2.0.tar.gz
drwxr-xr-x. 15 root root     4096 Aug  1 21:58 nagios-plugins-2.1.2
-rw-r--r--.  1 root root  2695301 Aug  1 21:58 nagios-plugins-2.1.2.tar.gz

Step #5: Configure Nagios Core

Now configure Nagios core following below command.

# cd nagios-4.2.0
# ./configure --with-command-group=nagcmd

You will get some output like below.

Creating sample config files in sample-config/ ...
*** Configuration summary for nagios 4.2.0 08-01-2016 ***:
General Options:
-------------------------
Nagios executable:  nagios
Nagios user/group:  nagios,nagios
Command user/group:  nagios,nagcmd
Event Broker:  yes
Install ${prefix}:  /usr/local/nagios
Install ${includedir}:  /usr/local/nagios/include/nagios
Lock file:  ${prefix}/var/nagios.lock
Check result directory:  ${prefix}/var/spool/checkresults
Init directory:  /etc/rc.d/init.d
Apache conf.d directory:  /etc/httpd/conf.d
Mail program:  /bin/mail
Host OS:  linux-gnu
IOBroker Method:  epoll
Web Interface Options:
------------------------
HTML URL:  http://localhost/nagios/
CGI URL:  http://localhost/nagios/cgi-bin/
Traceroute (used by WAP):  /usr/bin/traceroute
Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

Now compile and install all the binaries with make and make install command.

# make all
# make install

Sample output:

*** Exfoliation theme installed ***
NOTE: Use 'make install-classicui' to revert to classic Nagios theme
make[1]: Leaving directory '/root/download/nagios-4.2.0'
make install-basic
make[1]: Entering directory '/root/download/nagios-4.2.0'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/archives
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/spool/checkresults
chmod g+s /usr/local/nagios/var/spool/checkresults
*** Main program, CGIs and HTML files installed ***
You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
make install-init
- This installs the init script in /etc/rc.d/init.d
make install-commandmode
- This installs and configures permissions on the
directory for holding the external command file
make install-config
- This installs sample config files in /usr/local/nagios/etc
make[1]: Leaving directory '/root/download/nagios-4.2.0'

Now follow the below command to install Nagios init script.

# make install-init

For command line you will need to install command mode.

# make install-commandmode

Now install nagios sample files.

# make install-config

You will get some output like below.

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg
*** Config files installed ***
Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

Step #6: Nagios Configuration Customisation

Open the contact.cfg file and set email address to receiving email alerts.

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

###############################################################################
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################
# Just one contact defined by default - the Nagios admin (that's you)
# This contact definition inherits a lot of default values from the 'generic-contact'
# template which is defined elsewhere.
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                           [email protected]     ; *** CHANGE THIS TO YOUR EMAIL ADDRESS ****
}

Step #7: Nagios Web Interface Installation and configuration

Now configure the web interface for Nagios. Follow the below command.

# make install-webconf

Create password for “nagiosadmin” it will be used when you login the nagios web interface.

# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

Restart Apache service.

# service httpd start
For Fedora
# systemctl start httpd.service

Step #8: Nagios Plugin Installation and Configuration

Now download the Nagios plugin in /root/download folder and install it.

# cd /root/download
# cd nagios-plugins-2.1.2/
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install

Step #9: Verify Nagios Configuration Files

Follow the below command to verify the nagios configuration files.

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

Nagios Core 4.2.0
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-01-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 24 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
Things look okay - No serious problems were detected during the pre-flight check

Step #10: Add Service to System Startup

You will need to add nagios service to system startup using below command.

# chkconfig --add nagios
# chkconfig --level 35 nagios on
# chkconfig --add httpd
# chkconfig --level 35 httpd on

Restart Nagios service.

# service nagios start  
For Fedora
# systemctl start nagios.service

Step #11: Access Nagios Web Interface

Nagios has been configured successfully, now open it in your browser with

http://server_ip_domain_name/nagios” and provide the username “nagiosadmin” and “password“.

Nagios-core

I hope this article will help to install and configure Nagios 4.2.0 release on CentOS/RHEL and Fedora. If you have any queries and problem please comment in comment section.

Thanks:)

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

1 Comment

  • hi

    am installing in VM not able to use yum because of internet issue,

    using cent os 7, am new to this,

    please guide how to download and install, apache,php,required libs

Leave a Comment