Nagios is very lightweight monitoring tool. We are using this tool for past 1-2 years but somehow one day it get crash and to setup/restore Nagios it took more than 4hours(on premises). 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.

Below steps to install Nagios Core and get it running on an Amazon IaaS was known as an EC2 instance using the Amazon Linux AMI as a base OS.

To Start Nagios Core Installation you must have your EC2 instance up and run and have already configured SSH access to the instance.

These instructions will work equally well with Linux on a bare metal server running any Red Hat variety of Linux such as CentOS.

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):

# sudo yum install httpd php
# sudo yum install gcc glibc glibc-common
# sudo yum install gd gd-devel

Step 2: Create Account Information

You need to setup a Nagios user. Run the following commands:

# sudo adduser -m nagios
# sudo passwd nagios

Type the new password twice.

# sudo groupadd nagcmd
# sudo usermod -a -G nagcmd nagios
# sudo usermod -a -G nagcmd apache

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).

# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz
# wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz

Step 4: Compile and Install Nagios

Extract the Nagios source code tarball.

# tar zxvf nagios-4.0.8.tar.gz
# cd nagios-4.0.8

Run the configure script with name of the group you created earlier

# ./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.
# sudo make install
# sudo make install-init
# sudo make install-config
# sudo make install-commandmode

Step 5: Customize Configuration

Change E-Mail address with nagiosadmin contact definition you’d like to use for receiving Nagios alerts.

# sudo vim /usr/local/nagios/etc/objects/contacts.cfg

Step 6: Configure the Web Interface

# 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.
# sudo service httpd restart            //Restart Service

Step 7: Compile and Install the Nagios Plugins

Extract the Nagios plugins source code tarball.

# cd ~/downloads
# tar zxvf nagios-plugins-2.0.3.tar.gz
# cd nagios-plugins-2.0.3

Compile and install the plugins.

# ./configure –with-nagios-user=nagios –with-nagios-group=nagios
# make
# sudo make install

Step 8: Start Nagios

Add Nagios to the list of system services and have it automatically start when the system boots.

# sudo chkconfig –add nagios
# sudo chkconfig nagios on

Verify the sample Nagios configuration files.

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

If there are no errors, start Nagios.

# sudo service nagios start

Step 9: Update AWS Security Group

you need to open port 80 on the new AWS EC2 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 of 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

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.

e.g. http://ec2-xx-xxx-xxx-xx.ap-west-1.compute.amazonaws.com/nagios/

References