Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

Nagios Installation On Ubuntu 10.04 (Lucid Lynx)


This tutorial shows how to set up Ubuntu Lucid Lynx (10.4) server with the Nagios Monitoring System. Nagios is a powerful, highly configurable monitoring and alarming system, which can monitor a wide variety of systems (network, server, daemons, applications). Monitoring could be done for instance for availability or utilization. The monitoring could be restricted to services which are connectable from the outside (e.g. a webserver on port 80/tcp), or with the help of NRPE (Nagios Remote Plugin Executor) plugins for testing could also be executed remote.  There is a lot of info about nagios in the net, so feel free to use your preferred search engine to find whatever you need about it.  One new feature for Nagios 3.2.3 is the ability to have multiple escalations. One person(s) can be notified at first notification, if no one has responded alternate people can be alerted to the issue. We will be installing Nagios, Nagios Plugins, and Postfix with this tutorial. Postfix will be configured to send email via your alternate email server. This tutorial will only give you the basic configuration with Postfix, any additional settings can be found in multiple places on the Internet. A great place to start looking is http://wiki.nagios.org/index.php/Forums the Nagios Forums.

I have created a script that will do all of the leg work for you. It will install all of the requirements for Nagios, Nagios Plugins, and Postfix. I will lay out the commands to enter manually if you would like to take care of business that way, or you can use the included script. The script in its entirety will be at the end of this tutorial.

 

Basic Install Of Ubuntu Server

First thing you will want to do is start with a fresh install of Ubuntu with only SSH server installed. Please follow the below instructions on setting up your initial server.

Select English, or your language of preference.

0001

Now select Install Ubuntu Server:

0002

Again select your language of preference:

0003

Now choose your region here:

0004

Now select No to Detect Keyboard Layout:

0005

Now select where your keyboard is from:

0006

Now select your keyboard layout:

0007

Now we will continue on with the installation:

0008

Now select your time zone (Ubuntu will automatically detect its best guess for you):

0009

Now we are preparing for the partitioning of the hard drive:

0010

I always use the entire disk when I set up a new server:

0011

Now hit Enter to continue using your selected hard drive:

0012

Select Yes to write the changes to the hard drive:

0013

Now the system will partition your hard drive:

0014

Now your base system will begin to be installed:

0015

Now type the full name for your new user:

0016

Now type your password for the new user:

0017

Now type your password for the new user:

0018

Now type your password for the new user:

0018

Now you will be presented with the option to encrypt your home directories. I do not do this.

0019

Enter your HTTP Proxy information if you have one:

0020

The system will continue installing necessary packages:

0021

Do not install automatic updates. It’s always much easier to track down a problem if you know exactly what was installed on the system… especially when it comes to updates or patches.

0022

Now we are getting ready to select our basic install packages:

0023

Select OpenSSH Server and continue:

0024

Now the rest of the packages will be installed:

0025

Select Yes to install the Grub boot loader:

0026

Now we are almost complete with the install:

0025

Now select Continue to restart your server:

0028

Now your server is rebooting:

0029

Now We Will Disable AppArmor

/etc/init.d/apparmor stop

update-rc.d -f apparmor remove

aptitude remove apparmor apparmor-utils

 

Create Folder For Nagios And Nagios Plugins

mkdir /downloads

 

Now Let’s Install The Required Programs For Nagios

Make sure you select Smarthost option when installing Postfix:

aptitude -y install apache2 libapache2-mod-php5 build-essential libgd2-xpm-dev postfix

Now let’s update everything on this system:

aptitude update

aptitude safe-upgrade

 

Nagios User Setup

useradd -m -s /bin/bash nagios

passwd nagios

usermod -G nagios nagios

groupadd nagcmd

usermod -a -G nagcmd nagios

 

Download And Unzip Nagios And Nagios Plugins

cd /downloads

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

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

tar -zxf /downloads/nagios-3.2.3.tar.gz

tar -zxf /downloads/nagios-plugins-1.4.15.tar.gz

 

Install Nagios

cd /downloads/nagios-3.2.3

./configure –with-command-group=nagcmd

make all

make install

make install-init

make install-config

make install-commandmode

make install-webconf

 

Nagios Password

This is the password you will need to look at the nagios pages. If you install Nagios to a different directory please change this command to where the Nagios etc. folder will be.

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

Enter your password when prompted.

Now we will restart Apache to make sure all of the changes take effect:

/etc/init.d/apache2 restart

 

Install Nagios Plugins

cd /downloads/nagios-plugins-1.4.15/

make

make install

Now we need to make Nagios start at bootup:

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

 

Change Default Email Address For Nagios Admin

Open your favorite editor and open /usr/local/nagios/etc/objects/contacts.cfg and change this:

nagios@localhost

To this:

You@yourdomain.com

Once you have saved your changes to the contacts.cfg we need to verify that there are no errors in the configuration of Nagios.

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

Here is what you should see. It is okay to have a couple of warnings, but you can’t have any errors.

0030

Now we are going to start nagios:

/etc/init.d/nagios start

 

Postfix Configuration For A Smarthost Relay

postconf -e ‘relayhost=yourmailserver.com’

postconf -e ‘smtp_sasl_auth_enabled = yes’

postconf -e ‘smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd’

postconf -e ‘smtp_sasl_security_options =’

echo “yourmailserver.com emailusername:emailpassword” > /etc/postfix/sasl_passwd

Now we will need to change the password file attributes so only root has access to read it.

chown root:root /etc/postfix/sasl_passwd

chmod 600 /etc/postfix/sasl_passwd

postmap /etc/postfix/sasl_passwd

Now we are going to set the map that will change your outbound messages from nagios to your email server username/email address.

echo “nagios mailusername@yourmailserver.com” /etc/postfix/canonical

echo “canonical_maps = hash:/etc/postfix/canonical” >> /etc/postfix/main.cf

postmap /etc/postfix/canonical

Now we are going to restart Postfix:

/etc/init.d/postfix restart

Now that this all has been completed you can restart your system.

Once your system has come back up you will be able to login to the website and look at your first Nagios installation.

http://yourserver/nagios/

Now login with the nagiosadmin username and password we created earlier:

0031

Now here is what you will see once you are logged in.

0032

Installation Script For Nagios

Here is the installation script I have created to handle most of the work for installing Nagios. Please note the top of the script, you will need to define some of the variables for the installation to work correctly.

#!/bin/bash
#
# AUTHOR : rbishop
# DATE : 01.27.2011
#
# PROG.-NAME : nagios-setup.sh
#
# FUNCTION : Installing Nagios on your System
#
#
#######################################################################

#######################################################################
##                                                                   ##
##             Configurable Settings for this Script                 ##
##

WWWGROUP=www-data
WWWUSER=www-data
NAGIOSROOT=/usr/local/nagios
DOWNLOADS=/downloads
NAGIOSADMIN=nagiosadmin
POSTFIXETC=/etc/postfix
NAGIOSIP=
MAILSERVERDOMAIN=
MAILSERVERUSER=
MAILSERVERPASS=


##                                                                   ##
##            END Configurable Settings for Script                   ##
##                                                                   ##
#######################################################################
time {

set -e

echo "***** Starting Nagios Quick-Install:  *****"
echo ""
echo `date`

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**          Disabling AppArmor           **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

/etc/init.d/apparmor stop
update-rc.d -f apparmor remove
aptitude remove apparmor apparmor-utils

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**  Adding Required Folders for Install  **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

mkdir ${DOWNLOADS}

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "** Updating Software Packages on Server  **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

aptitude -y install apache2 libapache2-mod-php5 build-essential libgd2-xpm-dev postfix

aptitude update

aptitude -y safe-upgrade

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**  Adding Nagios user login for nagios  **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

useradd -m -s /bin/bash nagios
passwd nagios
usermod -G nagios nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www-data

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**   Downloading and Unzipping Nagios    **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

cd ${DOWNLOADS}

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

tar -zxvf ${DOWNLOADS}/nagios-3.2.3.tar.gz
tar -zxvf ${DOWNLOADS}/nagios-plugins-1.4.15.tar.gz

cd ${DOWNLOADS}/nagios-3.2.3

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**   Configuring nagios and installing   **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

read -p "Press Enter to continue..."

./configure --with-command-group=nagcmd

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**    Running Nagios Make All Command    **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

make all

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**  Running Nagios Make Install Command  **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

make install

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**   Running Make Install-Init Command   **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

make install-init

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**  Running Make Install-Config Command  **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

make install-config

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**   Running Make Install-CommandMode    **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

make install-commandmode

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**    Running Make Install-Webconf       **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

make install-webconf

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "** Adding htpasswd login for nagiosadmin **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

htpasswd -c ${NAGIOSROOT}/etc/htpasswd.users ${NAGIOSADMIN}

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**          Restarting Apache            **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

/etc/init.d/apache2 restart

echo "********************************************"
echo "********************************************"
echo "**                                        **"
echo "** Configuring Nagios-Plugins for Install **"
echo "**                                        **"
echo "********************************************"
echo "********************************************"

cd ${DOWNLOADS}/nagios-plugins-1.4.15/

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

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**   Running NagiosPlugin Make Command   **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

make

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**   Running NagiosPlugin Make Install   **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

make install

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**   Adding Nagios to Start on BootUp    **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

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

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**    Checking Nagios Configuration      **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

${NAGIOSROOT}/bin/nagios -v ${NAGIOSROOT}/etc/nagios.cfg

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**           Starting Nagios             **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

/etc/init.d/nagios start

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**         Configuring Postfix           **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

postconf -e 'relayhost =${MAILSERVERDOMAIN}'
postconf -e 'smtp_sasl_auth_enable = yes'
postconf -e 'smtp_sasl_password_maps = hash:${POSTFIXETC}/sasl_passwd'
postconf -e 'smtp_sasl_security_options ='

echo "${MAILSERVERDOMAIN} ${MAILSERVERUSER}:${MAILSERVERPASS}" > ${POSTFIXETC}/sasl_passwd

chown root:root ${POSTFIXETC}/sasl_passwd
chmod 600 ${POSTFIXETC}/sasl_passwd

postmap ${POSTFIXETC}/sasl_passwd

echo "${MAILSERVERDOMAIN}" > ${POSTFIXETC}/sasl_passwd

echo "nagios nagios@${MAILSERVERDOMAIN}" > ${POSTFIXETC}/canonical

echo "canonical_maps = hash:${POSTFIXETC}/canonical" >> ${POSTFIXETC}/main.cf

postmap ${POSTFIXETC}/canonical

/etc/init.d/postfix restart

echo "*****************************************"
echo "*                                       *"
echo "*     Ending Nagios Quick-Install:      *"
echo "*                                       *"
echo "*****************************************"

echo "*******************************************"
echo "*******************************************"
echo "**                                       **"
echo "**   Now go to ${NAGIOSIP}/nagios/   **"
echo "**                                       **"
echo "*******************************************"
echo "*******************************************"

}

Comments

comments