Are you using Nagios to monitor a small environment and running it on some old hardware that is on its last legs? Or are you interested in learning more about Nagios, but don't have any spare hardware lying around to install it on so you can play with it? Nagios is very lightweight for small/lab environments so rather than running it on a machine that itself was constantly crashing I decided to move it onto Amazon Web Services EC2 platform using the Free Tier Entitlement you get when you first sign up. Therefore total cost to me to move it from home to the cloud was $0, at least for the first 12 months and not taking into account time.

These instructions explain the steps I undertook to install Nagios Core and get it running on an Amazon EC2 instance using the Amazon Linux AMI for the base OS.

To start you must have your EC2 instance up and running and have already configured SSH access to the instance. For this article we use amzn-ami-hvm-2014.03.2.x86_64-ebs (ami-d9fe9be3) AMI for the base image. These instructions will work equally well with Linux on a bare metal server running any Red Hat variety of Linux such as CentOS, just skip parts that relate to Amazon Web Services and you can su to root rather than adding sudo to each command.

10 Steps total

Step 1: Install Prerequisite Software

Nagios requires the following packages are installed on your server prior to installing Nagios:

* Apache
* PHP
* GCC compiler
* GD development libraries

You can use yum to install these packages by running the following commands (as ec2-user):

Step 3: Download Nagios Core 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 Core 4.0.8 and Nagios Plugins 2.0.3.

Step 5: 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 favorite editor and change the email address associated with the nagiosadmin contact definition to the address you'd like to use for receiving alerts.

-> sudo vim /usr/local/nagios/etc/objects/contacts.cfg

Step 6: Configure the Web Interface

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

-> sudo 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.
-> sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Type the new password twice. Restart Apache to make the new settings take effect.
-> sudo service httpd restart

Step 9: Update AWS Security Group

Assuming you havn't already done so you need to open port 80 on the new server to incoming traffic so you can connect to the new Nagios webpage.

* From the EC2 console select Security Groups from the left navigation pane.
* Select the Security Group applicable for the instance that Nagios was installed on and open the Inbound tab
* If there is no rule to allow HTTP traffic on port 80 then click edit in the Inbound tab to add a new rule
* Click on New Rule button
* Scroll down to select HTTP from the list under Type
* If you want to be able to access nagios from anywhere then select Save, otherwise enter the IP address or range of IP address you want to be able to access it from then select Save.

Step 10: Login to the Web Interface

You should now be able to access the Nagios web interface to do this you will need to know the Public DNS or IP for your instance, you can get this from the Instance section of the EC2 Console if you do not already know it. You'll be prompted for the username (nagiosadmin) and password you specified earlier.

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.

Congratulations! You successfully installed Nagios. You'll no doubt want to monitor more than just your local machine, so check out Nagios Core Documentation (link below) to learn how to add more hosts and services for Nagios to monitor. If you already had a working Nagios install you can simply copy over the .cfg files to the new server, although depending on how your network is setup you may need to make changes to the IP address and ports used if the services been monitored are behind a NAT router.