Tuesday, March 17, 2009

How-To Install Nagios on Ubuntu Linux

After many attempts and how-tos, I was finally able to get Nagios installed on (Ubuntu) Linux. My first attempt was downloading an appliance from Jumpbox, then Fedora 10, and finally, Ubuntu. This how-to will be broken out into three parts:
  1. Download and install Ubuntu
  2. Download, install, and configure Apache
  3. Download, install, and configure Nagios

Download and install Ubuntu:

  • Download Ubuntu (I used version 8.10 of Ubuntu Desktop)
  • In VMWare Server, I booted to the ISO image
  • Choose "Install Ubuntu"
  • Choose English as the language
  • Choose Time Zone
  • Keyboard
  • Select the Guided (use entire disk) option
  • Fill in the user and computer information
  • Click Install
  • Click Restart

Once Ubuntu is installed, you can begin installing the prerequisites.

All commands will be issued with sudo command. If you prefer, you can just su as root and run everything that way.

Download, install and Configure Apache

  • sudo apt-get install build-essential :this will install some necessary compilers
  • sudo apt-get install libgd2-xpm-dev :Install GD Libraries
  • sudo apt-get install apache2 : Install Apache2
  • sudo apt-get install php5-common php5 libapache2-mod-php5 :Install PHP for Apache2
Configure Apache to use PHP:
  • Run in a terminal: sudo vim /etc/apache2/apache2.con
  • Paste the following into the file:
    DirectoryIndex index.html index.php index.cgi

  • and restart the server with the command
    sudo /etc/init.d/apache2 restart

At this point, build-essentials, libgd2-xpm-dev and Apache with PHP support should be installed. You can test this by opening a browser and going to http://localhost/ to test Apache.
To test PHP, create a new text file and enter
<?php phpinfo( );?>
Save the file as test.php in your root web directory (should be /var/www). Then go to http://localhost/test.php and this should display the PHP version information in the browser.

If you can view the Apache start page and the PHP version info page, it's time to download and install Nagios.

If you can't view the Apache start page: check that all of the packages are installed and the Apache service is running.

If you can't view the PHP version info page: verify that PHP was installed.

Download, install, and configure Nagios

Change to your home directory:

cd ~/

Download the current version of Nagios: http://sourceforge.net/project/showfiles.php?group_id=26589:

sudo wget http://downloads.sourceforge.net/nagios/nagios-3.1.0.tar.gz?use_mirror=voxel

Download the current version of the Nagios Plugins: http://sourceforge.net/project/showfiles.php?group_id=29880:

sudo wget http://downloads.sourceforge.net/nagiosplug/nagios-plugins-1.4.13.tar.gz?use_mirror=voxel

Extract the Nagios tarball:

sudo tar -zxvf nagios-3.1.0.tar.gz

and change to the nagios-3.1.0 directory

cd nagios-3.1.0

Create a user to run the service and a group to run external commands:

  • sudo useradd -m nagios
  • sudo passwd nagios
  • sudo groupadd nagcmd
  • sudo usermod -a -G nagcmd nagios
  • sudo usermod -a -G nagcmd www-data
Now install the Nagios tarballs that were downloaded previously:

  • sudo ./configure --with-command-group=nagcmd
  • sudo make all
  • sudo make install
  • sudo make install-init
  • sudo make install-config
  • sudo make install-commandmode
  • sudo make install-webconf
Add a user for the Nagios interface:

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

Add the directives to Apache for Nagios:

In a terminal type:

sudo vim /etc/apache2/apache.conf

Paste the text below into the conf file:

ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin

<Directory "/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user

Alias /nagios /usr/local/nagios/share

<Directory "/usr/local/nagios/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user

ServerName localhost

Restart Apache:

sudo /etc/init.d/apache2 restart

Extract and compile the plugins that were downloaded earlier:

  • cd ~/
  • tar -zxvf nagios-plugins-1.4.13.tar.gz
  • cd nagios-plugins-1.4.13
  • sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
  • sudo make
  • sudo make install
Create a link to start the service:
sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
Verify the config:

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

Start Nagios:

sudo /etc/init.d/nagios start

You should now be able to log into the Nagios web interface (http://localhost/nagios) using the nagiosadmin user and password.

This how-to is actually a combination of the Nagios official documentation (Ubuntu Quickstart), Albasit's Nagios/Ubuntu/VMWare how-to, and some of my own work in-between. I appreciate the help I got from all of these documents.


Keith said...

Why didn't you just use the nagios packages?

"sudo apt-get install nagios3"

Alexandre Racine said...

Thanks for your doc. Pretty nice.

Just to let you know, I'll put small corrections here has I do the procedure.

-This line "# Run in a terminal: sudo vim /etc/apache2/apache2.conf" is actually missing the "f" in "apache2.conf".

-Just under it, the "DirectoryIndex" actually install himself when you install the libapache2-mod-php5 package in the /etc/apache2/mods-enabled and /etc/apache2/mods-available/dir.conf files.

-When you edit again the apache.conf file to add the nagios configuration, this is already done with "make install-webconf". Nagios actually install the /etc/apache2/conf.d/nagios.conf file.

Have a nice day!

selvi said...


1. I have installed Apache WebServer on Ubuntu server.
2. I have installed nagios-3.1.0.
3. I am able to view the web-interface successfully in apache server as http://ip address/nagios.

4. I have downloaded nagios-php-0.5.1.tar from the net. I would like to configure the PHP web-interface for Negios. What are the configuration steps ? Any help is highly appreciated.


SirAble said...

This guide was very helpful. I now have nagios up and running. My next step is to go in and configure it.

Can I make a few corrections?
1. You refer to a group nagcmd in four places and then call it nagios at the bottom. Change them all to nagios.

2. Your lines running ./configure and make(the ones with no parameter) should not be run under sudo. Not only is that bad practice, it is not needed.

3. Another dependency is libglib2.0-dev. That is the package name in Ubuntu 9.04 and I suspect 8.10 used the same name

4. Near the top, under "Configure Apache to use PHP:", you refer to the file /etc/apache2/apache2.con and it should be /etc/apache2/apache2.conf. You get that file name right later on.

5. take the sudo off the two wget commands.

6. After your final step, I could get nagios to respond to web requests. But, it had no data and said the service was likely not running. Restarting the machine fixed it. I bet there is a way short of restarting, but I'd mention something about it.

Good day,
Ralph Green

Shifaz said...

Thanks Brian.

Francsico & Flávia said...

A great tutorial...
Thank you very much. Francisco -Brazil

Miguel said...

great job! Nagios is up and running ! how about the adds on

megam.info said...

Great article!

Roger Pack said...

with 9.04/9.10 it's just one package now




Jeeba said...

Greatissimo! Thanks for the tutorial, now im going to install some Drupal Plugins there

alvin said...

sudo vim /etc/apache2/apache.conf (command invalid)