How-To Install Nagios on Ubuntu Linux
Posted by Brian Bohanon
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:
- Download and install Ubuntu
- Download, install, and configure Apache
- 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 compilerssudo apt-get install libgd2-xpm-dev:Install GD Librariessudo apt-get install apache2: Install Apache2sudo apt-get install php5-common php5 libapache2-mod-php5:Install PHP for Apache2
- 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
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=voxelDownload 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=voxelExtract the Nagios tarball:
sudo tar -zxvf nagios-3.1.0.tar.gzand change to the nagios-3.1.0 directory
cd nagios-3.1.0Create a user to run the service and a group to run external commands:
sudo useradd -m nagiossudo passwd nagiossudo groupadd nagcmdsudo usermod -a -G nagcmd nagiossudo usermod -a -G nagcmd www-data
sudo ./configure --with-command-group=nagcmdsudo make allsudo make installsudo make install-initsudo make install-configsudo make install-commandmodesudo make install-webconf
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadminAdd the directives to Apache for Nagios:
In a terminal type:
sudo vim /etc/apache2/apache.confPaste 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
</Directory>
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
</Directory>
ServerName localhost
sudo /etc/init.d/apache2 restartExtract and compile the plugins that were downloaded earlier:
cd ~/tar -zxvf nagios-plugins-1.4.13.tar.gzcd nagios-plugins-1.4.13sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagiossudo makesudo make install
sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagiosVerify the config:
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgStart Nagios:
sudo /etc/init.d/nagios startYou 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.


9 comments:
Why didn't you just use the nagios packages?
"sudo apt-get install nagios3"
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!
Hi,
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.
Regards,
Lalli.
Howdy,
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
Thanks Brian.
A great tutorial...
Thank you very much. Francisco -Brazil
great job! Nagios is up and running ! how about the adds on
Great article!
with 9.04/9.10 it's just one package now
https://help.ubuntu.com/community/Nagios3
(nagios3)
Enjoy.
-rp
Post a Comment