Installing Nagios on Ubuntu Server 11.10 then Monitoring Windows and Exchange Servers–Part 1–Configuring Ubuntu for the Installation of Nagios Core…

by Andy Grogan on January 7, 2012 · 45 comments

in Linux, Monitoring, Nagios, Ubuntu

[ NOTE: ] This part has been updated to reflect some suggestions from readers of the site. Sections that have changed are:
Installing Nagios Core – added the sed commands before the “Make” process, this fixes an issue with the Make file which prevents the Nagios home page from being displayed, as well as some issues with the RSS feed – many thanks to Michael for pointing this out, and Simon Krenger for the actual fix.

I have also changed the Verifying Nagios Permissions section to reflect Michael’s suggestions – this fixes an issue when trying to schedule a service recheck which is related to permissions on the “nagios.cmd” file.

I have also removed the suggestion for an FTP server within the configuration – in essence you should be using SSH transfers via FileZilla.

Every now and then I like to ramble off and do something with a technology that I would not normally blog about, which also I am by no means an expert in – as it is a learning experience and can be fun!.

Recently I have been looking at monitoring solutions mainly in the context of a new role that I have been appointed to, but also because I have not focussed on any real form of monitoring throughout the history of this site and I thought that it would be good to share some of my experiences.

I have been looking at SCOM (and I will get around to posting a little tip that I discovered recently during the installation of Operations Manager) as well as a few other products (some good, some bad). However what I would like to focus my next few posts upon is Nagios Core.

For those whom don’t know; Nagios Core is a popular monitoring system based around Linux and PHP which in its “Core Edition” is available for free. With Nagios you can monitor a large number of facets of your network (including but not limited to Servers, Switches, Routers, Firewalls) and their respective services. You can also do some basic (in the Core release) business intelligence and performance / capacity management functions.

There is a huge community of plug-ins, skins and alternative interfaces for Nagios which allow for some pretty impressive expansion of the product and pretty much has everything for your monitoring needs.

Before I get into the meat of the article I should point out that I am not a Linux or Nagios expert (more a dabbler to be honest) – but over the years I have played with Ubuntu in the context of a reverse proxy for OWA and looked at Nagios as a monitoring tool a few times ~ but never really have used them in anger, therefore with that considered there are probably some processes that I will describe in this series that could be done better or more efficiently.

It is probably also worth pointing out, that there are a number of articles on the Internet which explain how to install Nagios core, but there are not many (or none that I could find) that give you an end-to-end scenario of Server installation to Server client and Exchange monitoring – so I thought that I would put one together.

As mentioned I have decided to use Nagios on Ubuntu (as it is the Linux Distro that I am the most familiar with), but I will not be explaining the actual Ubuntu install. What I will say is that I have installed Ubuntu Server into my VMWare workstation environment using the “Easy Setup” function – which automated the entire process, and all I really needed to do was create a new Virtual Machine and point the Ubuntu ISO at it.

Prerequisite Steps

Updating you Ubuntu Installation to the latest version

NOTE: The following steps all assume that you have a working, vanilla version of Ubuntu Server in your environment, if you would like to know how you can set install Ubuntu 11.10 within VMWare Workstation 8 – please see my video overview located here

From the Ubuntu Console type in the following commands (every command should then be followed by pressing <Enter>):

sudo apt-get update

Which will give you some output similar to the following (only there will be much more of it):

Ign http://security.ubuntu.com oneiric-security InRelease
Ign http://us.archive.ubuntu.com oneiric InRelease
Ign http://us.archive.ubuntu.com oneiric-updates InRelease
Ign http://us.archive.ubuntu.com oneiric-backports InRelease
Hit http://security.ubuntu.com oneiric-security Release.gpg
Hit http://security.ubuntu.com oneiric-security Release

Then type the following command;

sudo apt-get dist-upgrade

This will then begin the process of updating your Ubuntu Server components to the latest versions.

Installing OpenSSH

Whereas you do not need to install OpenSSH on your Ubuntu server, it is a very useful tool to have in place later on when you are administering the system and making modifications to various configuration files.

OpenSSH provides an encrypted remote administration environment for telnet and FTP applications (like PuTTY and Filezilla ~ more on these later).

Whereas you can administer your server from the console (or if like me you are working in a virtual environment the VMWare tools) it is far easier to install OpenSSH so you can perform tasks on your local Windows machine (I can already hear many Linux aficionados scoffing at the prospect Smile).

In order to install OpenSSH onto your Ubuntu box use following command on the console:

sudo apt-get install openssh-server

Configuring your Ubuntu Server with a Static IP address and configuring DNS

Naturally your Nagios monitoring server will need a static IP address, rather than one that is assigned from DHCP – therefore the following steps can be used to assign a static IP.

From the Ubuntu console type in the following command:

sudo nano /etc/network/interfaces

This will open up a console based text editor with the interfaces IP configuration (some people may prefer to use VI – but I have to admit I am a wimp and cannot get on with it!).

You will initially be presented something that looks like the following configuration:

auto eth0
iface eth0 inet dhcp

You will need to change the above to reflect the settings within your environment – for example mine looks like this:

auto eth0
iface eth0 inet static
        address 172.31.253.159
        netmask 255.255.255.0
        network 172.31.253.0
        broadcast 172.31.253.255
        gateway 172.31.253.129

When you have finished editing the file in Nano press the CTRL-O key and then <Enter> to save the file, and then press CTRL-X to exit and return to the console.

You should then configure the DNS Servers for your environment – from the console type in the following command:

sudo nano /etc/resolv.conf

This command will present you with a file that looks like the following:

domain telnetport25.com
search telnetport25.com
nameserver 172.31.253.138

You should change all of the values within the configuration file to reflect those within your own environment, when done you will need to press CTRL-O and then <ENTER> and then CTRL-X to exit.

Now that you have configured both a static IP address and your nameserver configurations you will need to restart the networking Daemons for the settings to take effect. This is done by entering in the following command to the console:

sudo /etc/init.d/networking restart

Setting up PuTTy to administer your server

You are now in a position to administer the Ubuntu server with a remote tool such as PuTTy. I say PuTTy as it is still one of the most versatile Terminal tools on the market that is also free.

You can download PuTTy from the following location: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

PuTTY is very easy to use – after you have downloaded it – double click on the executable and from the Session screen provide the IP address of your server and ensure that the SSH radio button is selected – see below:

NagiosCore001

When you are done click on the “Open” button – you might be presented with a Certificate Error screen. This is generated because the OpenSSH server will have generated a self signed SSL certificate which naturally will not be trusted by the local PuTTY client. You will need to accept and trust the certificate.

When you have done that you will be presented with a Terminal window that looks like the following:

NagiosCore002

You can now remotely administer your server from PuTTY.

Installing a Compiler on your Server

Nagios and its associated components is supplied in a pre-compiled form which is compressed and tar-balled (tag.gz) therefore before you can install it you will need to compile it using a compiler. Ubuntu server does not come with a built in compiler, but there are a number in the Linux community which are free to download and use.

For the purposes of this article we will be using “Build-Essential” which can be installed onto your server using the following command line from your PuTTY session:

sudo apt-get install build-essential

Upon executing this command you will be asked to confirm the installation – ensure that you select “Y

Installing the GD Libraries

The Ubuntu (or Debian) GD libraries are in essence binaries that allow for applications to dynamically draw images. These are most likely used by Nagios’ reporting tools.

To install the GD libraries type in the following command:

sudo apt-get install libgd2-xpm-dev

Installing Apache and PHP 5

Apache should really need no introduction with it still being one of the most popular web server platforms on the planet. Apache is naturally required to support the web interface of Nagios, and PHP5 is the platform language which does all of the cool stuff in the user front end.

To install Apache enter in the following command into the PuTTY terminal window:

sudo apt-get install apache2

When Apache has installed enter in the following commands to install PHP5:

sudo apt-get install php5-common php5 libapache2-mod-php5

Installing Nagios Core

Creating the Nagios service user and group for commands

Nagios needs a service user and a group which has the relevant permissions to run commands within the monitoring system. The need to be created before you being the fill Nagios install.

In order to create them type in the following commands into your Terminal window:

sudo useradd -m nagios

sudo passwd nagios – you will be prompted for a password for the Nagios Service user here

sudo groupadd nagcmd

sudo usermod -a -G nagcmd nagios

sudo usermod -a -G nagcmd www-data

Download the Nagios Core and Plug in files

We are now at the stage where we can download the Nagios Core and Plugins source to your Server.

Within the Terminal window type in the following commands:

sudo –s

mkdir downloads

cd downloads

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.3.1.tar.gz (this is the latest stable release)

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

tar –zxvf nagios-3.3.1.tar.gz

tar –zxvf nagios-plugins-1.4.15.tar.gz

Installing Nagios Core

Now that you have downloaded the relevant files to your server we can now begin the installation process, from the Terminal Windows type in the following commands (please ensure that you are in the “downloads” folder that you created in the previous step):

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


sed -i 's:for file in includes/rss/\*;:for file in includes/rss/\*.\*;:g' ./html/Makefile


sed -i 's:for file in includes/rss/extlib/\*;:for file in includes/rss/extlib/\*.\*;:g' ./html/Makefile make all make install make install-init make install-config make install-commandmode make install-webconf

We will now create the administration user for the Nagios Core System (this is the account that will be used to log into the web interface)

mkdir /usr/local/nagios/etc

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

You will then be prompted for a password for the admin user.

Installing the Nagios plugins

The Nagios plugins provide around 50 pre-configured monitoring functions and services, without them your Nagios installation is not going to do very much so it is important that they are compiled and integrated into the environment.

In order to install them from the terminal window, type in the following commands:

Navigate to the downloads folder (if you have been following the sequence this could be cd .. and then cd nagios-plugins-1.4.15).

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

make

make all

make install

Creating a Symbolic Link for the Nagios Service

We now have an almost functional Nagios system, however before we can start the system up, we need to create a symbolic link to the Nagios service so that it can be started with the O/S automatically.

In order to do this type the following command into the Terminal window:

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

Verify permissions and file system

During the configuration of the Nagios environments for this article I have encountered some small problems with file system permissions and a folder not being created by the installation process. Therefore I have added in this step which cleans up the permissions on the Nagios folders and ensures the correct directories are in place.

From the terminal window type in the following commands

chown nagios.nagcmd /usr/local/nagios/var/rw

 

chmod g+rwx /usr/local/nagios/var/rw

 

chmod g+s /usr/local/nagios/var/rw

 

/etc/init.d/nagios restart

Verifying the installation

Just before we start the Nagios server up, as a penultimate step we should now verify the configuration – this is done by executing the following command from the Terminal window:

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

Which should result in the following output:

Nagios Core 3.3.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 07-25-2011
License: GPL

Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/localhost.cfg'...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking services...
    Checked 8 services.
Checking hosts...
    Checked 1 hosts.
Checking host groups...
    Checked 1 host groups.
Checking service groups...
    Checked 0 service groups.
Checking contacts...
    Checked 1 contacts.
Checking contact groups...
    Checked 1 contact groups.
Checking service escalations...
    Checked 0 service escalations.
Checking service dependencies...
    Checked 0 service dependencies.
Checking host escalations...
    Checked 0 host escalations.
Checking host dependencies...
    Checked 0 host dependencies.
Checking commands...
    Checked 24 commands.
Checking time periods...
    Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

Starting up Nagios and Accessing the Management Site

We can now start Nagios Core – therefore from the Terminal Window type in the following command:

/etc/init.d/nagios start

When the service has completed starting up – you can open a Web Browser to you the Nagios Core installation via:

http://<addressOFyourServer>/nagios

NagiosCore003

In the next part

In the next part of this series I will go through how you can configure some basic monitoring of some Windows Servers within your infrastructure.

{ 45 comments… read them below or add one }

Leave a Comment

*

Previous post:

Next post: