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. Hi i am getting thise
    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

    Apache/2.2.22 (Ubuntu) Server at 10.1.31.243 Port 80

    Reply
  2. Firstly, thank you for answering Sharad and secondly, I was wrong, I said “bar” instead of “bin” and in the step 9, you indicate create a file (nagios.conf):

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

    That directory: /usr/local/nagios/bin/nagios doesn’t exist.

    How can I fix it?

    Reply
    • Hello Jose,

      This is default location of bin directory in Nagios. I generally follow my document and still so far not found such issue.
      Just recently setup 4 different nagios project for different client.
      Can you follow the document once again.

      Or send me the screenshot of “ls -l /usr/local/nagios/” command.
      I also need output of command , “find / -name nagios”

      Regards
      Sharad

      Reply
      • Thank you answering Sharad.

        Output of “ls -l /usr/local/nagios/”:
        drwxrwxr-x 3 nagios nagios 4096 abr 30 15:25 etc
        drwxr-xr-x 4 root root 4096 abr 30 15:20 libexec
        drwxr-xr-x 3 root root 4096 abr 30 15:19 var

        Output of “find / -name nagios”:
        /root/nagios-4.0.8/base/nagios
        /etc/init.d/nagios
        /usr/local/nagios

        Regards
        José Manuel

        Reply
  3. Hi, I just installed Nagios 4.0.8 on Ubuntu 12.04, but when I run the service I get an error (start: Unknown job: nagios), I think that is because in /usr/local/nagios only exist 3 directories: etc, libexec and var and there (I think) also must be a directory: “bar”, but it doesn’t exist.

    Reply
  4. Hello Sharad,

    First of all I would like to say thanks for such a wonderful post. But as you know Ubuntu and Nagios both has released their updated versions. So if you have some time could you also post the same post with Nagios 4.0.8 on Ubuntu 14.04 server?

    Thanks in advance 🙂

    Regards

    Sunil

    Reply
  5. hello, i just installed nagios3 on ubuntu 14.04, i need to monitor a PACKETEER(snmp) through my nagios using this plugins for the packeteer but seems am still stack with just the nagios installation, any help?

    Reply
    • Hello Seth,

      I will recommend you to install new Nagios Version that is 4.x . I will write a post on Nagios 4 on Ubuntu 14.04 which was pending from my side.
      Although I have written a post for CentOS 6.
      Soon some new posts on Nagios will be written.

      Can you elaborate more, what error or problem are you getting.

      Regards
      Sharad

      Reply
      • Thanks. My nagios crushes anytime I restart it.cant even locate my local host. I need to locate a given ip address with a host name. Maybe am not doing or using the right plugins or methods approaching this task.

        Reply
        • Alright, Which Operating system are you using right now.If it is different we will check.
          Read all steps carefully.

          As you said, your nagios crushes anytime. Is it physical server or Virtual server. How much memory have you given to the system

          Regards
          Sharad

          Reply
          • Thanks Akash,

            In case of Ubuntu 14.04 LTS , the apache 2.4 is default version. Check the configuration settings in apache, like DocumentRoot , Grant All etc., it will surely work. I have not written any doc on 14.04 LTS, soon I will write it.

            Regards
            Sharad

  6. hello, i have installed nagios3 on my ubuntu 14.04 and am suppose to monitor PACKETEER(snmp) through my nagios but i have not gotten any appropraite plugins for it. any help.

    Reply
  7. hello
    I installed nagios 4.0.5 and 2.0.1 plugins on ubuntu 12.04.1
    I always error and nagios.cmd file is missing:

    Error: Could not stat () command file ‘/ usr / local / nagios / var / rw / nagios.cmd’!
    The external command file May be missing, Nagios May not be running, and / or Nagios May not be checking external commands.
    An error occurred while Attempting to commit your command for processing.

    Can you or someone help to resolve the issue?

    Reply
  8. stuck at the first setp.

    apt-get install wget install build-essential apache2 php5 openssl 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
    E: Unable to locate package install
    root@msd-P5KPL-VM-S:~#

    Reply
  9. Hi Sharad,
    Could you please help in adding linux servers in Nagios Core 4 in Ubuntu for monitoring, what are the requirements do we require for that also help me in configuring email alerts and sms alerts to mobile.

    Please help me on the above with step-by-step procedures.
    I have installed Nagios Core 4.0.2 on Ubuntu 12.04 LTS, configured local host, network printers.
    Facing defficulties in Email notifications, sms also configuring remote linux hosts for monitoring.

    Regards
    Venkat

    Reply
    • Hello Venkat,

      As per Monitoring Server architecture, Nagios Server and its client both should be communicating to each other.
      I expect,your Nagios Server is up and running by following this post.

      Now, you have to add clients (other systems,devices) to be monitored in Nagios server.
      There are some methods,out of which I generally prefer NRPE.
      In case,you have Ubuntu/Debian system as a nagios client,follow this post
      In case of Red Hat based OS(RHEL/CentOS/Scientific Linux), follow this post

      Adding email notification in Nagios

      By default in nagios, contacts related files are already well set. You only have to add email id in contacts.cfg file.
      Now here requirement is how you will send email either by directly from system by using mail command or using any package to deliver email.
      In case of sending email directly from system by using mail command, we simply add email id in contacts.cfg file. I suggest you to read and explore nagios configuration file,it will help you to understand nagios engine mechanism.This thing will take time but once you understand the file structure,you can setup Nagios server in your own style.

      If you have any mail server and wants to deliver nagios notification email by using mail server username and passwd.(means authentication). You can use ssmtp or phpmailer or any mailer script.
      In one example,I have used Gmail id to send nagios notification.You can read this post

      SMS nagios notification

      I worked with some free SMS service but did not find reliable.I did long back ago this practical with free sms service but later I did not find long term working.Only for reference you can read this post but it will not work because “SMS service provider” is now using captcha.
      I suggest you to take 3rd party sms service.

      Reply

Leave a Comment

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