Running Nagios on Amazon EC2

This howto shows how to get Nagios up and running on an Amazon EC2 Instance using Apache web server to serve the Nagios UI. You could argue that a more light-weight web server would be better, but I'd argue that it doesn't really matter. Performance is not a great issue for a few administrators looking at the Nagios UI.

Update 1: Use this installation guide for Fedora on Nagios.org instead.

Update 2: You can now get Nagios XI preinstalled AMI’s http://labs.nagios.com/2012/01/20/using-nagios-xi-in-amazon-ec2-cloud/

Step 1: Create an EC2 micro instance running Amazon Linux AMI (64 bit)

Step one is to get an Amazon Linux instance. I created a new Amazon Linux micro 64 bit instance and placed the instance in a security group called "monitoring". You can use 32 bit if you want, but I've tested with 64 bit.

Next, open up ports 22 and 80 on the security group. Here I use the ec2 commandline tools, but you can also do it from the AWS Management Console:

ec2-authorize monitoring -p 22
ec2-authorize monitoring -p 80

Next log in to the instance using ssh

ssh -i path-to-pem-file ec2-user@your-ec2-instance

Step 2: Install Nagios software

Use yum to install nagios (at the time of writing this is version Nagios 3.2.3):

sudo yum install nagios nagios-plugins-all

Add nagios to run-level 3:

chkconfig --level 3 nagios on

Apache and PHP are used to serve the Nagios UI, but PHP is not installed by the yum command above. You can install PHP with yum:

sudo yum install php

Step 3: Add a user to Nagios

Add a Nagios user for logging into the Nagios UI. You can use this script:

#!/usr/bin/perl
use strict;
if ( @ARGV != 2 ){
	print "usage:./htpasswd.pl <username> <password>\n";
} 
else {
	print $ARGV[0].":".crypt($ARGV[1],$ARGV[1])."\n";
}

Run it like this:

perl htpasswd.pl some_username some_password

Copy-paste the output onto a new line of /etc/nagios/passwd, e.g. using vi

sudo vi /etc/nagios/passwd

Step 4: Configure Nagios

Enter your contact_name, alias and email address in the "contact" section of contacts.cfg:

sudo vi /etc/nagios/objects/contacts.cfg

Step 5: Start Nagios and log into the management application

Start Nagios:

sudo service nagios start

Visit your new Nagios home page, e.g. at http://your-ec2-instance-id.compute.amazonaws.com/nagios/.

Final hints

See a list of all the plugins installed:

ls /usr/lib64/nagios/plugins/

Check the last 100 log messages from nagios:

sudo tail -n 100 /var/log/nagios/nagios.log

4 thoughts on “Running Nagios on Amazon EC2”

  1. Pingback: 在Amazon EC2主机上安装Nagios进行系统监控 | FrankHe's Blog

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.