Nagios Installation On Ubuntu 10.04 (Lucid Lynx) - Page 3

Want to support HowtoForge? Become a subscriber!
 
Submitted by rbishop (Contact Author) (Forums) on Fri, 2011-02-18 17:09. ::

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.

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:

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

 

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 "*******************************************"

}

Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Fri, 2012-03-23 21:56.
error 404- wget http://prdownloads.sourceforge.net/nagios/nagios-3.2.3.tar.gz
 should be updated to wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz

 

 

Submitted by Anonymous (not registered) on Wed, 2012-01-25 22:59.

Why do you use Ubuntu, and then compile everything from source?

 The only useful part of Ubuntu is the package management.

 Scrap this entire howto, and replace it with:

"aptitude install nagios3 nagios-plugins" (or apt-get)

Submitted by thiyagi (not registered) on Fri, 2011-05-20 16:05.

thanks for the tutorial..
but i think u left one step , before make the nagios-plugins...

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

and then make, make install.. everything else worked fine

Submitted by Vidyadhar (not registered) on Thu, 2011-02-24 15:25.

You can following below steps to install nagios on Ubuntu,

http://www.techienote.com/2011/02/netflow-on-ubuntu.html

You can also configure nagios through nconf, see this

http://www.techienote.com/2011/01/nconf-on-ubuntu.html
Submitted by Anonymous (not registered) on Thu, 2011-02-24 08:37.

One too many "d's", should be enable instead of enabled:

postconf -e 'smtp_sasl_auth_enabled = yes'

Submitted by Anonymous (not registered) on Thu, 2011-02-24 06:48.

Thanks for the excellent howto; it's the first Nagios install text I've gone through that just works! One question: towards the end, just after restarting Postfix you write "Now that this all has been completed you can restart your system." Could you explain why that is necessary?

Submitted by withanHdammit (not registered) on Mon, 2011-02-21 16:58.

Your text would not let me make/make install the plugins.  I checked your script to see what was in there and it appears the text of your walk-through is missing this line:

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

Submitted by Anonymous (not registered) on Sat, 2011-02-19 03:34.
I think there's an error on page 3 of the guide.

echo "nagios mailusername@yourmailserver.com" /etc/postfix/canonical

should be

echo "nagios mailusername@yourmailserver.com" >> /etc/postfix/canonical

Right?

I'd rather this comment not be published - just correct the directions.