Share, , Google Plus, Pinterest,

Print

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 http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.2.tar.gz

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 http://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
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

Website: http://www.nagios.org
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!

Share, , Google Plus, Pinterest,

51 Comments

Leave a Reply

2 Pings & Trackbacks

  1. Pingback:

  2. Pingback: