Watch all our Tutorials and Training Videos for Free on our Youtube Channel, Get Online Web Tools for Free on swebtools.com

Search Suggest

Nagios Installation on Linux - Nagios Tutorial for Beginners

install nagios on linux, nagios installation on linux, linux install nagios, nagios install commands, nagios tutorial, nagios client install on linux


Nagios Installation on Linux step by step procedure 


This post will show you with Nagios Installation on Linux with Step by Step Procedure.

If you are interested in learning, Request you to go through the below recommended tutorial.

As far as Infrastructure management is concerned, Nagios is one of the most powerful and 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.

With Nagios you can:

– 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.

Lets see how to install nagios on Linux Server.

Nagios Installation on Linux


Nagios server:
Operating system : Red Hat 6.5 (RHEL6.5) minimal installation
IP Address       : 192.168.2.1

1. Install Required Dependencies Packages

Please install all below required dependencies for Nagios through yum server, because installing these packages individually  is more complicated. So we recommended to go with Yum server.
# yum install gd gd-devel gcc glibc glibc-common httpd php make net-snmp

2. Download Nagios (Nagios Core) Software and Nagios Plugins

If you wish to download the latest version, please visit https://www.nagios.org/download/core

I have downloaded from the below direct link and kept in my linux server already in the folder /home/learnitguide.

Nagios Core Link : http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.1.0rc1.tar.gz
Nagios Plugin Link : http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
[learnitguide@nagiosserver ~]# cd /home/learnitguide/

Extract Nagios Core and its Plugins:
[learnitguide@nagiosserver ~]# tar -xvf nagios-4.1.0rc1.tar.gz
[learnitguide@nagiosserver ~]# tar -xvf nagios-plugins-2.0.3.tar.gz

Before going for installation, please create a dedicated user and group for nagios.
[learnitguide@nagiosserver ~]# useradd nagios

[learnitguide@nagiosserver ~]# passwd nagios
Changing password for user nagios.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

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.


[learnitguide@nagiosserver ~]# groupadd nagcmd

[learnitguide@nagiosserver ~]# /usr/sbin/usermod -a -G nagcmd nagios
[learnitguide@nagiosserver ~]# /usr/sbin/usermod -a -G nagcmd apache

3. Install Nagios on Linux and do Basic Configuration

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 type 'make all' to compile the main program and CGIs.

[learnitguide@nagiosserver ~]# cd nagios-4.1.0rc1

[learnitguide@nagiosserver nagios-4.1.0rc1]# ./configure --with-command-group=nagcmd

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.


[learnitguide@nagiosserver nagios-4.1.0rc1]# make all

[learnitguide@nagiosserver nagios-4.1.0rc1]# make install

Sample Output:

*** 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

Execute all commands as show in the above output one by one as follows,

Following command will install the init scripts for Nagios.


[learnitguide@nagiosserver nagios-4.1.0rc1]# make install-init

/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios

*** Init script installed ***

To make nagios work from command line we need to install command-mode.

[learnitguide@nagiosserver nagios-4.1.0rc1]# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw

*** External command directory configured ***

Next, install sample nagios files, please run following command.


[learnitguide@nagiosserver nagios-4.1.0rc1]# make install-config

4. Customizing Nagios Configuration


Open the “contacts.cfg” file with your choice of editor and set the email address associated with the nagiosadmin contact definition to receiving email alerts.


[learnitguide@nagiosserver nagios-4.1.0rc1]# 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   admin@learntiguide.net    ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }

5. Install and configure Web Interface for Nagios


We are done with all configuration 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”.


[learnitguide@nagiosserver ~]# make install-webconf

/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf

*** Nagios/Apache conf file installed ***

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.


[learnitguide@nagiosserver ~]# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Restart Apache to make the new settings take effect.


[learnitguide@nagiosserver ~]# service httpd restart

Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

6. Compile and Install Nagios Plugin


We have downloaded nagios plugins in /home/learnitguide/nagios-plugins-2.0.3, Go there and configure and install it as directed below.


[learnitguide@nagiosserver nagios-plugins-2.0.3]# cd /home/learnitguide/nagios-plugins-2.0.3

[root@RHEL5 downloads]# cd nagios-plugins-1.5
[learnitguide@nagiosserver nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[learnitguide@nagiosserver nagios-plugins-2.0.3]# make
[learnitguide@nagiosserver nagios-plugins-2.0.3]# make install

7. Verify Nagios configuration file


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 smooth it will show up similar to below output.


[learnitguide@nagiosserver nagios-plugins-2.0.3]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

8. Add Nagios Services to System Startup


To make Nagios work across reboots, we need to add nagios and https with chkconfig command.
[learnitguide@nagiosserver nagios-plugins-2.0.3]# chkconfig --add nagios
[learnitguide@nagiosserver nagios-plugins-2.0.3]# chkconfig --level 35 nagios on
[learnitguide@nagiosserver nagios-plugins-2.0.3]# chkconfig --add httpd
[learnitguide@nagiosserver nagios-plugins-2.0.3]# chkconfig --level 35 httpd on

Restart Nagios to make the new settings take effect.


[learnitguide@nagiosserver nagios-plugins-2.0.3]# service nagios start

nagios is stopped
Starting nagios:                                           [  OK  ]

Note : Please turn off your iptables and selinux or add the nagios ports to allow.

Login to Nagios Web Interface

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

Please check other posts for configuring or adding linux clients and windows clients to the nagios server.

Related Content on Linux might be useful to you to improve your Linux Skills.

Keep practicing and have fun. Leave your comments if any.

Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.