Ubuntu 8.04 Nagios Install

Nagios server monitoring is one of the best – if not the best open source server, switch and router monitoring platforms I’ve used. Best of all, because it is open source, it is free. I’ve documented here the method I used to get Nagios 3.

Introduction

If you follow these instructions the plan is you’ll end up with:

Nagios and the plugins will be installed underneath /usr/local/nagios
Nagios will be configured to monitor a few aspects of your local system (CPU load, disk usage, etc.)
The Nagios web interface will be accessible at http://localhost/nagios/ or at http://yourWANip/nagios/

Before you start

You’ll need to have a command line editor – I recommend Putty for this. Its easier to be logged on as root but if you are not, use the sudo command before typing a command. I’ve put the sudo command in the below just for good practise really. With Putty, you can just higlight the below commands one at a time and then right click in the Putty window to paste them in. When I did this for the first time it took be 20 mins typing. I had a Nagios install complete within 5 mins on the second install I did using the copy paste function.

Installing Required Packages

As good practice, make sure you have updated your sources.list file to include the deb universe updates:

vi /etc/apt/sources.list

Highlight and copy the lines below:

deb http://us.archive.ubuntu.com/ubuntu/ hardy universe
deb-src http://us.archive.ubuntu.com/ubuntu/ hardy universe
deb http://us.archive.ubuntu.com/ubuntu/ hardy-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ hardy-updates universe

Use your arrow keys to find the end of the last line and press I (which is for insert). Then if you right click it will paste the line in. Press escape to go back to the mode where you can move the cursor around. You may have to delete the extra letter you have from the end of the last line. Press X to delete the higlighted character. Press I to insert any characters that are missing.

To save and come out of the vi editor hold shift and press ZZ

Update the packages on your system by typing

sudo apt-get update

Make sure you’ve installed the following packages on your Ubuntu installation before continuing.

Apache 2
PHP
GCC compiler and development libraries
GD development libraries
You can use apt-get to install these packages by running the following commands:

sudo apt-get install apache2

sudo apt-get install libapache2-mod-php5

sudo apt-get install build-essential

sudo apt-get install libgd2-xpm-dev

Now we can begin to install Nagios.

 

Step 1: Create Account Information

Become the root user.

sudo -s

Create a new nagios user account and give it a password.

/usr/sbin/useradd -m -s /bin/bash nagios

passwd nagios

Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.

/usr/sbin/groupadd nagcmd

/usr/sbin/usermod -a -G nagcmd nagios

/usr/sbin/usermod -a -G nagcmd www-data

 

Step 2: Download Nagios and the Plugins

Create a directory for storing the downloads.

mkdir ~/downloads

cd ~/downloads

Download the source code tarballs of both Nagios and the Nagios plugins (visit http://www.nagios.org/download/ for links to the latest versions). These directions were tested with Nagios 3.2.0 and Nagios Plugins 1.4.14.

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.0.tar.gz

wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.14.tar.gz

 

Step 3: Compile and Install Nagios

Extract the Nagios source code tarball.

cd ~/downloads

tar xzf nagios-3.2.0.tar.gz

cd nagios-3.2.0

Run the Nagios configure script, passing the name of the group you created earlier like so:

./configure –with-command-group=nagcmd

Compile the Nagios source code.

make all

Install binaries, init script, sample config files and set permissions on the external command directory.

make install

make install-init

make install-config

make install-commandmode

Nearly done, just a couple more steps to go…

 

Step 4: Customize Configuration

Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. You’ll need to make just one change before you proceed…

Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your and change the email address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts. It’s in the part that says ‘Put your email here’

vi /usr/local/nagios/etc/objects/contacts.cfg

 

Step 5: Configure the Web Interface

Install the Nagios web config file in the Apache conf.d directory.

make install-webconf

Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account – you’ll need it later.

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

Restart Apache to make the new settings take effect.

/etc/init.d/apache2 reload
 

 

Step 6: Compile and Install the Nagios Plugins

Extract the Nagios plugins source code tarball.

cd ~/downloads

tar xzf nagios-plugins-1.4.14.tar.gz

cd nagios-plugins-1.4.14

Compile and install the plugins.

./configure –with-nagios-user=nagios –with-nagios-group=nagios

make

make install

 

Step 7: Start Nagios

Configure Nagios to automatically start when the system boots.

ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Verify the sample Nagios configuration files.

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

If there are no errors, start Nagios. If there are errors, let me know in the comments below and we’ll get them sorted so others can see what the fix is too.

/etc/init.d/nagios start

Sometimes its worth a reboot of your server if possible now. Just to make sure everything that needs to restart has restarted.
 

Step 8: Login to the Web Interface

You should now be able to access the Nagios web interface at the URL below. You’ll be prompted for the username (nagiosadmin) and password you specified earlier.
http://localhost/nagios/ or if installing on a VPS http://yourVPSWANIPaddress/nagios
Click on the “Service Detail” navbar link to see details of what’s being monitored on your local machine. It will take a few minutes for Nagios to check

all the services associated with your machine, as the checks are spread out over time.

 

Step 9: Other Modifications

If you want to receive email notifications for Nagios alerts, you need to install the mailx (Postfix) package.

sudo apt-get install mailx

sudo apt-get install postfix

You’ll have to edit the Nagios email notification commands found in /usr/local/nagios/etc/objects/commands.cfg and change any ‘/bin/mail’ references to ‘/usr/bin/mail’. Once you do that you’ll need to restart Nagios to make the configuration changes live.

sudo /etc/init.d/nagios restart

 

What’s Next?

Part two will cover setting up configuration files, alerts and adding devices to your setup.

Please remember – if this helped – please donate to keep the site free.

Leave a Reply