Share, , Google Plus, Pinterest,


Posted in:

Install Nagios Core 4 on Ubuntu 12.04 LTS

Nagios is IT Infrastructure Monitoring Tool. There is a free open source Nagios Core edition available for download and payable Nagios XI edition which costs $1,295 $4995 (updated) for unlimited hosts. Nagios XI has enhanced AJAX based user interface, built in graphing, dynamic dashboard, … With Nagios Core you need to install and configure additional open source software to get same or similar results. If you want a free of charge solution you need to download Nagios Core from Nagios Homepage and install it on your server.

In this post we will explain step-by-step how to install Nagios Core 4 on Ubuntu Server 12.04 LTS.

Nagios Core 4 on Ubuntu
Nagios Core 4 on Ubuntu

Let’s Install Nagios Core 4 on Ubuntu 12.04 LTS!

1. Install required software packages

geekpeeknet@foo1:~$ sudo apt-get update
geekpeeknet@foo1:~$ sudo apt-get install build-essential apache2 php5-gd wget libgd2-xpm libgd2-xpm-dev libapache2-mod-php5 sendmail daemon

2. Create Nagios Core user and group

Create nagios user and nagcmd group. Add nagios user to nagcmd group

geekpeeknet@foo1:~$ sudo useradd nagios
geekpeeknet@foo1:~$ sudo groupadd nagcmd
geekpeeknet@foo1:~$ sudo usermod -a -G nagcmd nagios

3. Download the latest Nagios Core tarball

geekpeeknet@foo1:~$ sudo wget

4. Extract Nagios Core tarball

geekpeeknet@foo1:~$ sudo tar -xvzf nagios-4.0.2.tar.gz

5. Run configure

Move to extracted nagios directory and run configure with additional options.

geekpeeknet@foo1:~$ cd nagios-4.0.2/
geekpeeknet@foo1:~/nagios-4.0.2$ sudo ./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-mail=/usr/bin/sendmail

Configure should end with configuration summary that looks like this:

config.status: creating t-tap/Makefile
config.status: creating include/config.h
config.status: creating lib/snprintf.h
config.status: creating lib/iobroker.h

Creating sample config files in sample-config/ ...

*** Configuration summary for nagios 4.0.2 11-25-2013 ***:

 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/apache2/conf.d
             Mail program:  /usr/bin/sendmail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

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

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

6. Make everything

geekpeeknet@foo1:~/nagios-4.0.2$ sudo make all
geekpeeknet@foo1:~/nagios-4.0.2$ sudo make install
geekpeeknet@foo1:~/nagios-4.0.2$ sudo make install-init
geekpeeknet@foo1:~/nagios-4.0.2$ sudo make install-config
geekpeeknet@foo1:~/nagios-4.0.2$ sudo make install-commandmode
geekpeeknet@foo1:~/nagios-4.0.2$ sudo make install-webconf

7. Copy eventhandlers and change ownership

geekpeeknet@foo1:~/nagios-4.0.2$ sudo cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
geekpeeknet@foo1:~/nagios-4.0.2$ sudo chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

8. Create Nagios Web Access user

Create Nagios web access user and set it’s password.

geekpeeknet@foo1:~/nagios-4.0.2$ sudo htpasswd -cm /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: 
Re-type new password: 
Adding password for user nagiosadmin

9. Edit Nagios init script

If you will try to start Nagios at this point you will get the following error:

geekpeeknet@foo1:~$ sudo /etc/init.d/nagios start
/etc/init.d/nagios: 20: .: Can't open /etc/rc.d/init.d/functions


There is a problem with Nagios init script on Ubuntu. We have to edit init script and change a few lines. I could not get it to work with none of the hacks i found on the internet so i created my own by first running “start-stop-daemon” and then killing the daemon PID since a defunct Nagios process hangs. If you do not like this hack do not use it – but it works!

Please read my post “Ubuntu Nagios 4 Init Script Fix” how to do this!

11. Download and Install Nagios plugins

geekpeeknet@foo1:~$ sudo wget
geekpeeknet@foo1:~$ sudo tar -xvzf nagios-plugins-1.5.tar.gz
geekpeeknet@foo1:~$ cd nagios-plugins-1.5/
geekpeeknet@foo1:~/nagios-plugins-1.5$ sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
geekpeeknet@foo1:~/nagios-plugins-1.5$ sudo make
geekpeeknet@foo1:~/nagios-plugins-1.5$ sudo make install

12. Copy and link Nagios Apache configuration

geekpeeknet@foo1:~$ sudo cp /etc/apache2/conf.d/nagios.conf /etc/apache2/sites-available/nagios
geekpeeknet@foo1:~$ sudo ln -s /etc/apache2/sites-available/nagios /etc/apache2/sites-enabled/nagios

13. Change group ownership of /usr/local/nagios/var/rw/

Change ownership of directory before your first time Nagios run!

Please read my post on “Nagios Error: Could not open command file for update” how to do this!

14. Check Nagios configuration for errors

geekpeeknet@foo1:~$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios Core 4.0.2
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 11-25-2013
License: GPL

Reading configuration data...
   Read main config file okay...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
    Checked 8 services.
    Checked 1 hosts.
    Checked 1 host groups.
    Checked 0 service groups.
    Checked 1 contacts.
    Checked 1 contact groups.
    Checked 24 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 5 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

15. Make Nagios and Apache start at boot

geekpeeknet@foo1:~/nagios-4.0.2$ sudo ln -s /etc/init.d/nagios /etc/rcS.d/S98nagios
geekpeeknet@foo1:~/nagios-4.0.2$ sudo ln -s /etc/init.d/apache2 /etc/rcS.d/S99apache2

16. Start Nagios Core 4.0.2 service

geekpeeknet@foo1:~/nagios-plugins-1.5$ sudo service nagios start

17. Start Apache service

geekpeeknet@foo1:~/nagios-plugins-1.5$ sudo service apache2 start

18. Visit Nagios URL in your browser

We finished installing Nagios Core 4 on Ubuntu 12.04 LTS! Open http://IPADDRESS/nagios or http://FQDN/nagios in your browser and enter username and password created in step 8! Read more about how to configure Nagios hosts and services in my post on Nagios Configuration!

  • Cameron Halter

    On Step #17, you will need to restart apache if you didn’t while you copied over your apache config file (Step #13). Otherwise, you’ll get a 404.

    • Mitch

      Hi Cameron! Thanks for the info. I will update the step 17.
      Although this how to presumes, you made a first install of apache and nagios so apache service was never started and step 17 should do the trick.

      Thanks and Regards,

  • Alexandre

    Very good article, helped me a lot.
    Thank you very much!

    • Mitch

      Thanks Alexandre, good to hear! Regards, Mitch

  • Pingback: How To Write Nagios Plugin - Bash Script | GeekPeek.Net()

  • Navneet Patel

    I have completed all the steps successfully…but when i first time run on browser i get an error :

    “Site error
    An error was encountered while publishing this resource. The requested resource does not exist.
    Please click here to return to the Zenoss dashboard”

    and when i click on that link login page apeared. i have tried to login using the username and password which i have choosen in step#8. but gets erron :
    Your session has expired,
    or the entered password, or
    the username is incorrect.

    i am sure that my username and password are right..

    Can any one help me….

    • Mitch

      Hi Navneet! Did you even read the error you are getting? It says “..return back to Zenoss dashboard”. Do you have Zenoss installed? Are you trying to login to Zenoss dashboard with wrong username and password? Please check your configuration again.. Regards, Mitch

      • Navneet Patel

        yes, i have installed it…but i have removed it…once again i have installed the nagios using above steps but now getting 404 not found !!!

        • Mitch

          If you are getting the 404 error the problem is in your Apache configuration. Please check your Nagios Apache virtualhost config file points to the right location of Nagios HTML files and check the rights on those files and folders. Regards, Mitch

          • Navneet Patel

            Thanks !! Now It will work !!
            default.conf file was misplaced….!!
            it must be in etc/apache2/site-available directory.

  • Kevin

    Great script, thanx. Saves me a lot of work.

    • Mitch

      Hi Kevin and thanks, glad it does what it’s intended to 😉 regards, Mitch

  • bryan

    Hello Guys,

    Where can I edit my nt.cfg?

    Thank you in advance

  • Abdul Wajid

    snmp_check is missing.

  • Bryan

    How can I add to monitor windows services, If I can’t find the nt.cfg? I think the nt.cfg is missing? Please need help.

    • Mitch

      Please read my post on “Nagios Configuration“. In short: “You can keep all of the hosts and services in one configuration file if you like, but i prefer you separate hosts and services based on operating systems.” So it is up to you to create the desired .cfg files and separate hosts and services. Regards, Mitch

  • Amrish

    You are just awesome.

    After countless attempts to get this running. your guide allowed me to do so.

    Many thanks

    • Mitch

      Thanks Armish!

  • Adam

    Hi..Mitch, above post very helpfull to me… i gets successfully run in first attempt.
    i was trainee student, i will work on a project in which i have to integrate the nagios core tools in our Framework which is Based on Java, The aim is to monitor a database server for performance enhancement, i have installed the check_postgres plugin, and it will run as i need. so can you help me how to integrate nagios core to our framework, or specific web-service for nagios or any JAVA API ?

    • Mitch

      Hi Adam! I am not sure i am able to help you anyhow, since i am no expert in Java API. Anyway send me an email with short description of project on info[at] and we will see where we stand. Regards, Mitch

  • Antonio

    Thank you so much. I follow your tutorial and i didn’t have problems. Even don’t know english very well i could understand everything because it is clear and really complete

  • Blink

    Really good stuff! Helped me a lot!

  • Hi Mitch,

    I’m trying to find something like Nconf for Core 4. Do you know of anything?

    • Mitch

      Hi Richard.Sorry, but I can’t help you much here. What i know is Nconf and Thruk – tested it on Core 3 – don’t know about Core 4. Regards, Mitch

  • For the complete video tutorial visit the link below

  • ejaz

    Thanks Sir

  • ejaz

    how can i use nagios

    • Mitch

      Hi Ejaz! You can use Nagios to monitor your servers and their services. Regards, Mitch

  • Julius

    Very good tutorial. I still cant understand where to insert parameters for monitoring Remote windows machines. Please maybe somebody could suggest a tutorial how to configure Nagios for Windows remote machine process monitoring. I need to monitor 4 process (programs) on hosts and get alerts if they are not running. I understand concept but nagioshome/etc/ *.cfg files makes no sence for me, I have read this And done some configurations but nothing works. enviroment >> I am running Nagios as VM.

    • Mitch

      Hi Julius and sorry for late reply. You can monitor Windows machines with check_nt Nagios check. You must first install and configure NSClient on Windows clients. You can add Windows hosts to Nagios just like any other host (linux or something else) the only difference is you must be calling checks to windows hosts with check_nt (and additional parameters of course) check. I intend to write a tutorial about adding Windows hosts to Nagios but can’t find the time currently. Regards, Mitch

  • Hi MItch – Thanks for posting this article and helping people with Nagios and Linux in general. I just wanted to point out the Nagios XI information is wrong in one area. The price for the unlimited node license for Nagios XI is $4995 🙂 Thanks again… If you would ever like to attend the Nagios World Conference you should fill out a speaker application. I can put a good word in for you.


    Nagios Sales Guy 🙂

    • Mitch

      Hi Mike! Thanks for your info – i updated the price immediately 🙂 Nagios World Conference is very tempting but not as a speaker. I still think there are better Nagios experts out there with lots of stuff to say and present 🙂 If there is any chance you could get me a Nagios XI trial to test it out i would be thrilled Mike. Thanks again and regards, Mitch.

      • Mike

        Hi Mitch –

        Any one can get a free fully functional 60 day trial at nagiosDOTcom. If you email me we can talk more. The conference always has a ton of people who are new and advanced when it comes to Nagios so we tend to have speakers that range from beginner to advanced. Either way shoot me an email, I assume you can access it via my posting.

  • Sirajuddin Khan

    I followed each and every steps but getting this error message please help:

    The requested URL /nagios/ was not found on this server.

    Apache/2.4.7 (Ubuntu) Server at Port 80

    • Sirajuddin Khan

      I am using Ubuntu 14.04 LTS.

    • Mitch

      Hi! Seems like your apache configuration for Nagios is not ok! Please re-chech apache configuration and nagios alias. Regards, Mitch

      • Gilbert

        Hi, I am also having the problem with the apache.

        I am using debian.

        Restarting web server: apache2[Thu May 08 01:58:50 2014] [warn] The ScriptAlias directive in /etc/apache2/sites-enabled/nagios at line 8 will probably never match because it overlaps an earlier ScriptAlias.
        [Thu May 08 01:58:50 2014] [warn] The Alias directive in /etc/apache2/sites-enabled/nagios at line 25 will probably never match because it overlaps an earlier Alias.
        … waiting [Thu May 08 01:58:52 2014] [warn] The ScriptAlias directive in /etc/apache2/sites-enabled/nagios at line 8 will probably never match because it overlaps an earlier ScriptAlias.

  • Prashant Chougule

    Hi Mitch,
    I am new to Nagios , I followed your steps and installed Nagios, but when I am trying to open it in browser I am getting Welcome to nginx!
    Is it right or am I missing something ?

    • Mitch

      Hi Prashant! This guide describes how to install and configure Nagios with Apache. It seems you are using Nginx. Regards, Mitch

  • eduardo

    Hi Mitch,
    Is this tutorial valid for ubuntu 13.10?

    Thanks in advance

    • Mitch

      Hi Eduardo, i can’t say 100% because i haven’t tested it out but i think it should work withoug any problems on ubuntu 13.10 also. Regards, Mitch

  • shirin

    thanks alot it helped alot , but once i wanted to open the http://ipaddress/nagios i got the below error
    internal server error . i typed the . : is the statsic ip of eth0 . can you please help me i ‘m new to linux sys.

  • shirin

    thanks alot it was very helpful

  • shirin

    i just have one question in the last part 18 , i used and i entered the users name nagios admin and the password set in step 8 but i got the internal server error can you please help me ? i ‘m new to linux , i do no know how to see the error log even.
    Apache /2.2.22 st port 80

  • Pingback: Install Nagios Core 4 on Ubuntu 12.04 LTS | zpp5359()

    • ejaz

      nagios installed completed done and thanks……. . but how to configure service ..
      how to configure ubuntu 12.04 server nagios command.cfg contacts.cfg localhost.cfg printer.cfg switch.cfg templates.cfg timeperiods.cfg windows.cfg and
      what configure nrpe client server side …

      • Mitch

        Hi Ejaz, there are a lot of templates and well explained already in conf files, did you check? Anyhow there is also my post on Nagios Configuration, please check:


  • habeeb

    Thanks i have finished the installation for nagios 4.0.2 and i also access the console via browser.Can anyone provide me how do i add the clients (other ubuntu workstations) to monitor the systems

  • Julian

    Good Tutorial!

    But now in Step 11 the “conf.d” directory ist missing 🙁

    • Julian

      And of course the contained file “nagios.conf”

      • Mitch

        Hi Julian! It should not be missing if you did Step 6 and “make install-webconf”. Regards, Mitch

  • ajith

    Unable to locate package libgd2-xpm
    I am getting this above error while running 2nd command

  • ajith

    any help would be appreciated
    Thanks in advance