Nagios 4.1.1: Nagios Core 4.1.1 Installation on Centos 6.7


Nagios Core 4.1.1

This is a guide on installing the latest Nagios Core (4.1.1) on Centos 6.7. Nagios is an open source computer system monitoring, network monitoring and infrastructure monitoring software application. Nagios offers monitoring and alerting services for servers, switches, applications, and services. It alerts the users when things go wrong and alerts them a second time when the problem has been resolved. Nagios Core is the monitoring and alerting engine that serves as the primary application around which hundreds of Nagios projects are built. It serves as the basic event scheduler, event processor, and alert manager for elements that are monitored. It features several APIs that are used to extend its capabilities to perform additional tasks, is implemented as a daemon written in C for performance reasons, and is designed to run native on Linux/*nix systems.

Step 1: Install Required Dependencies

We need to install Apache, PHP and some libraries like gcc, glibc, glibc-common and GD libraries and its development libraries before installing Nagios 4.0.1 with source. And to do so we can use the yum default package installer.


# yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp perl-rrd xinetd openssl-devel package perl-GD* ntp perl-rrd*

Step 2: Create Nagios User and Group so that application will configure the server perfectly.

Create a new "nagios" user and "nagcmd" group account and set a password.


# useradd nagios
# groupadd nagcmd



Next, add both the nagios user and the apache user to the nagcmd group.

Step 3:  Add both the nagios user and the apache user to the nagcmd group.

# usermod -G nagcmd nagios
# usermod -G nagcmd www-data (for some if www-data is not theere use apache)

Step 4: Download Nagios Core 4.0.1 and Nagios Plugin 1.5

Create a directory for your
Nagios installation and all its future downloads.


# mkdir /root/nagios
# cd /root/nagios




Nowdownload latest Nagios Core 4.1.1 and the Nagios plugins 2.1.1 packages from the below Links


Nagios 4.1.1 Core Software Download and Installation:

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

Nagios Plugins: 

# wget https://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz

Step 5: Installting Nagios Core

We need to extract downloaded package with tar command as follows.

# tar –xvf nagios-4.1.1.tar.gz

When you extract these tar files with tar command, two new folders will appear in that directory.

Step 6: Configure & Install Nagios Core Server Components 

Now, first we will configure Nagios Core and to do so we need to go to Nagios directory and run configure file and if everything goes fine, it will show the output in the end as sample output. Please see below.



# cd 
nagios-4.1.1

#./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios --with-command-group=nagcmd



Output:

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/init.d
Apache conf.d directory:  /etc/httpd/conf.d
Mail program:  /usr/bin/mail
Host OS:  nagios.test.com

Web Interface Options:
------------------------
HTML URL:  http://localhost/nagios/
CGI URL:  http://localhost/nagios/cgi-bin/
Traceroute (used by WAP):  /usr/sbin/traceroute


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs
*** Main program, CGIs and HTML files installed ***




Now, after configuring we need to Compile and install all the binaries with make command and make install command will install all the needed libraries in your machine and we can proceed further.


# make all

# make install 



Output:

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 install-init
To make nagios work from the command line we need to install command-mode.
# make install-commandmode
Next, install sample nagios files, please run following command.
# make install-config


Output:
/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 8: Install and Configure Web Interface for Nagios

We are done with all configurations in the backend, now we will configure Web Interface For Nagios
with following command. The below command will Configure Web interface for Nagios and a web admin user will be created “nagiosadmin”.

# make install-webconf

In this step, we will be creating a password for “nagiosadmin”. After executing this command, please
provide a password twice and keep it remember because this password will be used when you login in 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



Step 9: Restart Apache to make the new settings take effect.

# service httpd start

Step 10: Configure and Install Nagios Plugin 

We have downloaded nagios plugins in /root/nagios, Go there and configure and install it as directed
below.

# cd /root/nagios
# cd tar –xvf nagios-plugins-2.1.1.tar.gz
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl --enable-perl-modules --enable-libtap
# make
# make install


Step 11: Verify Nagios Configuration Files 

Now we are all done with Nagios configuration and its time to verify it and to do so please insert
following command. If everything goes smoothly it will show up similar to below output.


/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Output:
Nagios Core 4.1.1
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-19-2015
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 7 services.
        Checked 1 hosts.
        Checked 1 host groups.
        Checked 0 service groups.
        Checked 1 contacts.
        Checked 1 contact groups.
        Checked 7 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 1 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 12: Restart the Nagios services.

# service nagios restart

To make Nagios work across reboots, we need to add nagios and httpd with chkconfig command.

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



Step 13: Login to the Nagios Web Interface http://yourhostip/nagios

Your nagios is ready to work, please open it in your browser with “http://Your-server-IP-address/nagios” or “http://FQDN/nagios” and Provide the username “nagiosadmin” and password.


Download and Install NRPE

NRPE allows you to remotely execute Nagios plugins on other Linux/Unix machines. This allows you to monitor remote machine metrics (disk usage, CPU load, etc.). NRPE can also communicate with some of the Windows agent addons, so you can execute scripts and check metrics on remote Windows machines as well.

Step 14: First we needed to create the right folders:

# mkdir -p /usr/local/src/nrpe
# cd /usr/local/src/nrpe

Download the files and extract:

# wget http://kent.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
# tar -xf nrpe-2.15.tar.gz
# cd nrpe-2.15

Because of an issue with the openssl library folder we need to use another path than /usr/lib:

#./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu

Now make and make install:
# make all

Next, install the NRPE plugin daemon, and sample daemon config file. 
# make install-plugin
# make install-daemon
# make install-daemon-config

Install the NRPE daemon under xinetd 
as a service.
# make install-xinetd


Next, open /etc/services file add the following entry for the NRPE daemon at the bottom of the file.
# vi /etc/services

nrpe            5666/tcp                 NRPE

Restart the xinetd service.

# service xinetd restart

Step 15: Verify NRPE Daemon Locally

Run the following command to verify the NRPE daemon working correctly under xinetd.

# netstat -at | grep nrpe

tcp        0      0 *:nrpe                      *:*                         LISTEN


Step 16: Verify the NRPE daemon is functioning properly.

# /usr/local/nagios/libexec/check_nrpe -H localhost

Output: ( Which shows the NRPE version)


NRPE v2.15

Now we needed to create two configuration files so that we can monitor Linux or Unix machines

Step 17: To add the host:

# cd /usr/local/nagios/etc
# vi /usr/local/nagios/etc/hosts.cfg

define host{
                   name                            linux-box               ; Name of this template
                   use                             generic-host            ; Inherit default values
                   check_period                    24x7        
                   check_interval                  5       
                   retry_interval                  1       
                   max_check_attempts              10      
                   heck_command                   check-host-alive
                   notification_period             24x7    
                   notification_interval           30      
                   notification_options            d,r     
                   contact_groups                  admins  
                   register                        0                       
}


define host{
   use                            linux-box               ; Inherit default values from a template
   host_name                Testbox          ; The name we're giving to this server
   alias                          CentOS 6.7              ; A longer name for the server
   address                     192.168.1.84            ; IP address of Remote Linux host
}



Step 18 To add the services:

# vi /usr/local/nagios/etc/services.cfg


define service{
        use                   generic-service
        host_name               Testbox
        service_description     CPU Load
        check_command           check_nrpe!check_load    
 }

define service{
        use                     generic-service
        host_name               Testbox
        service_description     Total Processes
        check_command           check_nrpe!check_total_procs
        }

define service{
        use                     generic-service
        host_name               Testbox
        service_description     Current Users
        check_command           check_nrpe!check_users
 }

define service{
        use                             generic-service         
        host_name                       Testbox
        service_description          Root Partition
 check_command   check_nrpe!check_disk
 }

define service{
        use                      generic-service         
        host_name                       Testbox
        service_description          Home Partition
 check_command   check_nrpe!check_disk_home
 }
define service{
        use                             generic-service         
        host_name                       Testbox
        service_description          Ping Status
 check_command   check_ping!10.0,80%!50.0,90%
        }

We needed to added this configuration files in nagios.cfg 

                             
# vi 
/usr/local/nagios/nagios.cfg

cfg_file=/usr/local/nagios/etc/hosts.cfg
cfg_file=/usr/local/nagios/etc/services.cfg





Now NRPE commands should definition needs to be created in commands.cfg file.

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

define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }


Finally, verify Nagios Configuration files for any errors.


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

# service nagios restart



Now your Nagios server is ready to monitor Linux machines 

Adding MRTG to Nagios Core 4.1.1
Adding Nagios Graph to Nagios core 4.1.1
Fixing the nagios could not find the file nagios.cmd

Keywords: Nagios Core 4.1.1, Nagios Server, Nagios Monitoring Server, Minitor Basic services on Liunx, Linux Monitoring Server 

Comments

  1. article about how to add network switch would be appreciated.

    ReplyDelete

Post a Comment

Popular posts from this blog

Observium: Configuring Microsoft Windows 2008 Server SNMP Agent

AWS: Upgrade PV Drivers on Windows Instances

How to configure Incremental backups for MSSQL Database