Install and configure nagios core 4 on Ubuntu 12.04 LTS

In this tutorial we will install and configure nagios core 4 on Ubuntu 12.04 LTS. Nagios Core 4 has recently been released,at the time of writing this post Nagios core 4.0.2 was available.

Nagios is one of the most popular,reliable and robust Monitoring System.You can find number of plugins to monitor the network and server resources.
Best thing is Nagios Core is open source.You can modify the monitoring system as per your requirement.You can also create your own nagios plugins.We suggest you to submit your Nagios related contribution in exchange.nagios.org

Nagios team has added lots of new feature in Nagios Core 4.x Version over last version.To read about new feature in Nagios Core 4.x here is the referral link .
We also suggest you to read about version history(Referral link : Nagios core 4.x Version history)

Install and configure Nagios Core 4 in Ubuntu

We are doing this practical in Ubuntu 12.04 LTS. Given below are the brief description of our specs

Operating System : Ubuntu 12.04 LTS (x86_64)
Package Name : Nagios Core 4.0.2
Apache Version : 2.2.22-1ubuntu1.4
IP Address of Nagios Server : 192.168.56.101

Note: The practical has been performed in Freshly installed Ubuntu 12.04 LTS

Follow the given below steps to install and configure Nagios core 4.x in Ubuntu

Step 1 : Login in Server and become super user. Now install dependencies require for Nagios core 4 version

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

Step 2 : Download the Nagios core 4 package

wget http://nchc.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.2/nagios-4.0.2.tar.gz

Step 3 : Now untar the downloaded nagios package

tar -xvzf nagios-4.0.2.tar.gz

Step 4 : Create user nagios and group nagcmd. Add the nagios user in supplementry group nagcmd

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios

Step 5 : Compile and install nagios

cd nagios-4.0.2/
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf


Step 6 :
Copy eventhandlers directory into nagios base directory . Change the owner and group to nagios

cp -rvf contrib/eventhandlers/ /usr/local/nagios/libexec/

chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

Step 7 : Set nagiosadmin user password.It is a default user for Nagios dashboard administration .
Give the password for nagiosadmin and we will use it in Nagios Dashboard

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

Step 8 : Enable the rewrite apache module.Restart the apache after this.

a2enmod rewrite

/etc/init.d/apache2 restart

Step 9 : Starting the Nagios . We found problem while starting the nagios.Hence we will create service init script for nagios to start/stop the nagios service

Note: As per new nagios, the init script for nagios has problem with functions of Ubuntu/Debian system.

Below given is the error ,which we have found while running the command /etc/init.d/nagios start

root@ubuntu:~# /etc/init.d/nagios start
/etc/init.d/nagios: 20: .: Can’t open /etc/rc.d/init.d/functions
root@ubuntu:~#

Create a new file in /etc/init with name called nagios.conf
For service init script,we have taken reference from ssh.conf and rsyslog.conf file (path is /etc/init/ssh.conf and /etc/init/rsyslog.conf)

vi /etc/init/nagios.conf

## paste the below given content in /etc/init/nagios.conf

# nagios4 init script
### use command 'service nagios start|stop|restart'

description     "nagios 4.x core"

start on filesystems
stop on runlevel [1246]

respawn

setuid nagios
setgid nagcmd
console log

script
        exec /usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg
end script 

Step 10 : Now start the nagios service

service nagios start

Note 1: To stop the Nagios service

service nagios stop

Note 2: To check the status of Nagios service

service nagios status

Step 11 : There is one more problem i.e with eventhandlers found in Ubuntu.(See in this referral link)To fix this issue ,run below given command

chmod 666 /usr/local/nagios/var/rw/nagios.cmd

Step 12 : After starting nagios service.Open the web browser and type the URL appended with /nagios

example http://192.168.56.101/nagios
(Replace the 192.168.56.101 with your server ip address or domain name)

Nagios core 4 ubuntu

When you click on Services tab in Nagios Dashboard,you may see lots of Red area which means plugin is not installed.. For this we will install Nagios plugins.

Nagios core 4 Services

Install and configure Nagios plugin in Nagios Server

Now we will install nagios plugins in Nagios server for local alert check .

Step 13 : Download the nagios plugins in Nagios Server

cd ~
wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz

Step 14: Untar the compressesed nagios-plugins-1.5.tar.gz file

tar -xvzf nagios-plugins-1.5.tar.gz

Step 15 : Change to extracted nagios-pligins directory and install the plugins

cd nagios-plugins-1.5
 
./configure --with-nagios-user=nagios --with-nagios-group=nagios
 
make
 
make install 

Step 16 : Wait for a minimum 90 Seconds.The dashboard will be updated and all checks will be active. You can notice all Red colors change to Green colors

Nagios Core 4

Note : Rather then waiting, you can reschedule the check in nagios.

Click on any Service for eg. “Current Load” . Now see at right hand side. There is a link called “Re-schedule the next check of this service“. Click on it, and after giving reschedule time,click ok. The Nagios Server will check and update the information in new re-schedule time.

Below is the reference screenshot of “Service Commands” section

Nagios Service Commands

35 thoughts on “Install and configure nagios core 4 on Ubuntu 12.04 LTS”

  1. Hello,
    I have recently discovered “Nagios” and I’m using it for supervision. The thing is I need to monitor the bandwidth in a company..
    I have understood that I need to install a plug-in capable of doing that, well does anyone have a plug in that actually works while integrated, I’ve tried something like 2 or 3 plugs in but none of them gave me a good result..
    Thank’s a lot..

    Reply
    • Hi wolfyy,

      For network devices you have to use the snmp based plugins like check_snmp. As well as you have to configure SNMP server in network devices.
      For knowledge point of you , I strongly suggest to read about snmp, snmpwalk,snmpget commands.

      All the best!

      Regards
      Sharad

      Reply
  2. Hi Sharad,

    My machine Ubuntu 17.04. I tried to install its showing following message:
    root@ubuntu:/home/ubuntu# apt-get install wget build-essential apache2 php5 open ssl perl make php5-gd wget libgd2-xpm libgd2-xpm-dev libapache2-mod-php5 libperl -dev libssl-dev daemon
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Package build-essential is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    Package libapache2-mod-php5 is not available, but is referred to by another pack age.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    Package php5 is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    Package make is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    Package php5-gd is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    Package libssl-dev is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    Package libgd2-xpm-dev is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    Package libperl-dev is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    E: Package ‘build-essential’ has no installation candidate
    E: Package ‘php5’ has no installation candidate
    E: Package ‘make’ has no installation candidate
    E: Package ‘php5-gd’ has no installation candidate
    E: Unable to locate package libgd2-xpm
    E: Package ‘libgd2-xpm-dev’ has no installation candidate
    E: Package ‘libapache2-mod-php5’ has no installation candidate
    E: Package ‘libperl-dev’ has no installation candidate
    E: Package ‘libssl-dev’ has no installation candidate

    Reply
  3. i am getting this message. What should i do?
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Note, selecting ‘libgd-dev’ instead of ‘libgd2-xpm-dev’
    Package libapache2-mod-php5 is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    Package php5 is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    Package php5-gd is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    E: Package ‘php5’ has no installation candidate
    E: Package ‘php5-gd’ has no installation candidate
    E: Unable to locate package libgd2-xpm
    E: Package ‘libapache2-mod-php5’ has no installation candidate

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.