Introduction to Linux - A Hands on Guide | Linux Bible | Linux From Scratch | A Newbie's Getting Started Guide to Linux | Linux Command Line Cheat Sheet | More Linux eBooks

Monday, 19 May 2014

How To : Install Nagios Core 4 on Ubuntu Linux

    Nagios is one of the most popular Open Source application being used for the purpose of IT Infrastructure and Network Monitoring. Basically, this tool is available in two editions, namely, Nagios Core edition which is Open Source and absolutely free to download and Nagios XI edition that has to be purchased by the user. Of course, Nagios XI will have additional features as compared to Nagios Core, but when configured with additional open source plugins and softwares, Nagios Core can provide you with similar or exact results as those in Nagios XI. But, using open source tools is always preferred by most of the users.

    So, this article we guide you to install Nagios Core 4 on your Ubuntu System. The upcoming commands are tested on Ubuntu 13.04 and you will see the screenshots of the same.

He we begin!

1. Install the Necessary Packages

First of all, login as the Superuser, update the packages and then install the dependencies required by Nagios.

sudo su -

apt-get update

apt-get install wget build-essential apache2 php5 openssl perl make php5-gd wget libgd2-xpm libgd2-xpm-dev libapache2-mod-php5 libperl-dev libssl-dev daemon
2. Create a User and a Group

We are going to create a user 'nagios' using useradd command and a group 'naggrp' using groupadd command, then add the user 'nagios' to the group 'naggrp'.

sudo useradd nagios

sudo groupadd naggrp

sudo usermod -a -G naggrp nagios
3. Download the Nagios Core 4 Package

sudo wget
4. Unarchive the Tarball

sudo tar -xvzf nagios-4.0.2.tar.gz
5. Compile the Source Code

cd nagios-4.0.2/

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

6. Install the Programs

make all

make install

make install-init

make install-config

make install-commandmode

make install-webconf

7. Copy the 'eventhandlers' directory

cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
8. Create a User 'nagiosadmin'

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

9. Restart the Apache2 Service

service apache2 restart


/etc/init.d/apache2 restart
10. Start the Nagios Service

If you try starting the nagios service at this stage, you will be faced with an error as follows:

sudo /etc/init.d/nagios start
/etc/init.d/nagios: 20: .: Can't open /etc/rc.d/init.d/functions

The reason behind this is the init script. As a remedy, we create a file 'nagios.conf' in the /etc/init/ directory and edit it as follows:

description "nagios 4.x core"
start on filesystems
stop on runlevel [1246]
setuid nagios
setgid naggrp
console log
        exec /usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg
end script 
Now, start the nagios service and it should work smoothly.

sudo /etc/init.d/nagios start

11. Nagios Apache Configuration

cp /etc/apache2/conf.d/nagios.conf /etc/apache2/sites-available/nagios
ln -s /etc/apache2/sites-available/nagios /etc/apache2/sites-enabled/nagios
12. Check the Nagios Configuration

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

13. The Last Touch

sudo /etc/init.d/nagios start

If you click 'Services' on the left side, at this point of time, you will meet following situation, indicating that you will have to install Nagios Plugins in order to proceed. How to do that? We will see in the upcoming tutorial.

That's all for now !

1 comment:

  1. During initial steps.

    sudo useradd nagios

    what is the password for the user during initial set up?