How to Setup Nagios 3.4.4 Network Monitoring On Ubuntu Server 12.04/12.10

in How To, Monitoring

This guide will shown you how to installing latest version of nagios 3.4.4 on Ubuntu Server 12.04/12.10. Nagios is free and open source tool with GPL License allowing to control and monitor the items and services on a network. When it detects a problem it sends alert messages, either by mail or by other techniques.

Step by Step Installing and Configure Nagios 3.4.4 in Ubuntu Server 12.04/12.10

Step 1. Before installing Nagios 3.4.4 on Ubuntu Server 12.04/12.10, make sure your Ubuntu Server is up to date. Enter the following commands one by one, and install any available updates:

sudo apt-get update
sudo apt-get upgrade -y

Step 2.  Install Apache 2, PHP5, GCC ( development libraries and compilation), GD ( development libraries) on other package

sudo apt-get install build-essential apache2 php5-gd wget libgd2-xpm libgd2-xpm-dev libapache2-mod-php5 libssl-dev

Step 3. Create users and groups for Nagios:

sudo mkdir -p /etc/nagios /var/nagios
sudo groupadd --system --gid 9000 nagios
sudo groupadd --system --gid 9001 nagcmd
sudo adduser --system --gid 9000 --home /usr/local/nagios nagios
sudo usermod --groups nagcmd nagios
sudo usermod --append --groups nagcmd www-data
sudo chown nagios:nagios /usr/local/nagios /etc/nagios /var/nagios

Step 4. Download the source code of both compressed Nagios and the Nagios plugins (visit http://www.nagios.org/download/ for links to the latest versions). At time of writing, the latest versions of Nagios 3.4.4 and the Nagios plugins 1.4.16

cd /usr/local/src/
wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.4.4/nagios-3.4.4.tar.gz
wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz

Step 5. Extract, Compile and Install source of nagios 3.4.4

sudo tar -xzvf /usr/local/src/nagios-3.4.4.tar.gz
cd /usr/local/src/nagios
sudo ./configure --sysconfdir=/etc/nagios --localstatedir=/var/nagios --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd --with-openssl=/usr/bin/openssl --enable-perl-modules --with-mail=/usr/bin/sendemail
sudo make all
sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode

Step 6. Edit file /etc/objects/contacts.cfg to change the email address that is associated with nagiosadmin contact with the email address where you want to be alerted.

sudo nano /etc/objects/contacts.cfg

Example:

define contact{
               contact_name   nagiosadmin ;
               use            generic-contact ;
               alias          Ubuntu Precise ;
               email          admin@ubuntuprecise.net ;
}

Step 7. Edit file /etc/nagios/objects/commands.cfg to change both sendemail references to match the correct sendemail syntax:

sudo nano /etc/nagios/objects/commands.cfg
define command{
 command_name notify-host-by-email
 command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/sendemail -s srv-mail:25 -f "admin <admin@ubuntuprecise.net>" -t $CONTACTEMAIL$ -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **"
}
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/sendemail -s srv-mail:25 -f "admin <admin@ubuntuprecise.net>" -t $CONTACTEMAIL$ -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **"
}

Step 7. Now we need to configure Nagios to access it via web interface.

  • Install the web configuration file in the Apache conf.d directory:
cd /usr/local/src/nagios
sudo make install-webconf
  • Create password for Account nagiosadmin to enter the Nagios web interface. Remember the password you assign to this account – you will need it later. then restart apache2 daemon
sudo htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
sudo /etc/init.d/apache2 reload
  • Edit file /etc/apache2/apache2.conf and add the following line:
sudo nano /etc/apache2/apache2.conf
DirectoryIndex index.html index.php index.cgi

Step 8. Check your Nagios 3.4.4 configuration file for errors by typing following command. Look for errors in red

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

Step 9. Extract, Compile and install Nagios Plugins 1.4.16

cd /usr/local/src
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
sudo tar -zxvf /usr/local/src/nagios-plugins-1.4.16.tar.gz
cd /usr/local/src/nagios-plugins-1.4.16
sudo ./configure --sysconfdir=/etc/nagios --localstatedir=/var/nagios --with-nagios-user=nagios --with-nagios-group=nagios
sudo make
sudo make install

Step 10. Set Nagios is started whenever the system boots up, then restart nagios daemon

sudo /usr/sbin/update-rc.d -f nagios defaults 99
sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
sudo /etc/init.d/nagios restart

If all goes well, we should now be able to enter a Web browser to access Nagios administrator panel. Open a web browser and enter:

http://domain/nagios/

We ask for the username (nagiosadmin) with the password you have chosen in step 7.  If all went well you should see the home page of Nagios Administrator Panel

Link Reference:

Advertisement:
  • Shake Chen

    /etc/objects/contacts.cfg is wrong. the right is :/etc/nagios/objects/contacts.cfg

  • teec

    Thanks, works perfectly, is the most comprehensive tutorial that I found so far for ubuntu 12.04/12.10 server. Good work!

    • AikoELarA

      is this also applicable for ubuntu 13.04?

  • Alex

    Thanks for the guide. This probably saved me couple of days, I am sure!

  • Shyam

    Can I install Nagios on Ubuntu 12.04 LTS Desktop version?

  • Gareth

    Ubuntu 13.04 Server:
    sudo /etc/init.d/nagios restart
    /etc/init.d/nagios: 20: .: Can’t open /etc/rc.d/init.d/functions

  • alex

    this tutoriel is really helpful, thx very much !

Previous post:

Next post: