Thursday, August 22, 2013

Implement a Free Virtualized monitoring system

Nagios implementation / ESXi VM


After testing and searching for a proper fast, reliable and up-to-date network monitoring systems I have stumbled upon the Nagios distribution. I have tested and implemented several Nagios monitoring systems in a core production networks and the results were great. 
We can look at the Nagios distribution as a core component of the monitoring system, that many othe GUI oriented management and reporting services can rely on (Cacti, Nagvis, Centreon etc.).

In this blog I will show you people how to install Nagios in a completely free scenario. We will use:
  1. Free ESXi hypervisor
  2. Ubuntu server as a VM
  3. Nagios package 
I assume that everyone has an hypervisor laying around, and in couple of minutes has setup-ed a Ubuntu server. Monitoring systems should use static IP address. These settings you can modify in the /etc/network/interfaces file.

First steps are to upgrade the current version the Ubuntu server you have. I am using version 12. You need a user with the root permissions for this action.

apt-get update
apt-get upgrade
apt-get dist-upgrade

Nagios needs additional packets to function. We should install these also.

apt-get install gcc make g++ lsb-release tofrodos apache2 apache2.2-common apache2-doc apache2-mpm-prefork apache2-utils libapache2-mod-python libexpat1 ssl-cert libapache2-mod-php5 php5 php5-common php5-gd php5-mysql php5-imap phpmyadmin php5-cli apache2-suexec php-pear php-auth php5-mcrypt mcrypt libapache2-mod-suphp php5-snmp php5-ldap mysql-server rrdtool librrds-perl libconfig-inifiles-perl libcrypt-des-perl libgd-gd2-perl snmp snmpd libnet-snmp-perl libsnmp-perl libgd2-xpm libgd2-xpm-dev bsd-mailx postfix


After this one should reboot a machine - shutdown -r now
Next step is adding a user and a group for a Nagios setup.

/usr/sbin/useradd -m -s /bin/bash nagios
passwd nagios
/usr/sbin/groupadd nagios

We should associate the group with the user and add it to the WWW group of the Apache server to receive the parent permissions for web GUI we will use later on in Nagios reporting.

/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagcmd nagios
/usr/sbin/usermod -G nagcmd www-data

You should the choose the random folder for the installation , and we will download the package then. I myself like to use the /usr/local folder to keep the packages together.

wget http://downloads.sourceforge.net/project/nagios/nagios-3.x/nagios-3.4.1/nagios-3.4.1.tar.gz?r=http%3A%2F%2Fwww.nagios.org%2Fdownload%2Fcore%2Fthanks%2F&ts=1340721679&use_mirror=garr
mv nagios-3.4.1.tar.gz\?r\=http\:%2F%2Fwww.nagios.org%2Fdownload%2Fcore%2Fthanks%2F nagios-3.4.1.tar.gz
tar xzfv nagios-3.4.1.tar.gz
cd nagios/

Next step is to configure a the Nagios with the package scrypts and parameters we have configured before.

./configure --with-nagios-group=nagios --with-nagios-user=nagios --with-command-group=nagcmd
Creating sample config files in sample-config/ ...

After the the compiling is finished you should see no errors. If you do, you should try other versions of Nagios, or see if all packages have been installed on the Ubuntu server. Next step is to install the compiled package.

make all
make install
make install-commandmode
make install-config
make install-init

make install-webconf

To restrict the unknown user to use the Nagios web GUI we should create an admin user.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:

Using the ln command in linux is great. This can add a few lines of text to the config files in just one line. We will use this command to add the location for the Nagios in the autostart init.d script files.

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

To spice up some of the Nagios features we should install the Nagios plugins.


wget http://downloads.sourceforge.net/project/nagiosplug/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz?r=http%3A%2F%2Fwww.nagios.org%2Fdownload%2Fplugins%2F&ts=1340722460&use_mirror=dfn
mv nagios-plugins-1.4.15.tar.gz\?r\=http\:%2F%2Fwww.nagios.org%2Fdownload%2Fplugins%2F nagios-plugins-1.4.15.tar.gz
tar xzfv nagios-plugins-1.4.15.tar.gz

./configure
make
make install


Finally we can start the Nagios engine.

/etc/init.d/nagios start


Very important thing to follow up is the nagios log file. This log file is located in the parent directory of nagios/var/nagios.log. Here the nagios engine will log all the errors , if there are any.

On further blogs I will write how to implement a Web GUI called centreon to easily administer routers, servers and other equipment that comply with the standard monitoring protocols. For now you can add and test some router performance using the switch.cfg file as the input.

/usr/local/nagios/etc/objects/switch.cfg

I have added one router with simple service that failed the SNMP check to showcase the Nagios respond. Nagios is very fast so the host details are in sync with the routers.




This is all for now.

Feel free to give me some feedback.

No comments:

Post a Comment