lundi 7 janvier 2008

Linux Nagios 2.6 Installation on Ubuntu 6.06 Linux Server

Nagios 2.6 Installation on Ubuntu 6.06 Linux Server

Nagios is an open source tool that monitors any device on a network that is IP addressable. I use it extensively on a daily basis at my workplace. It is easily configured to monitor a servers availability on the network from just simple TCP/IP ping requests, to more advanced service monitors such as http, dns, telnet, smtp and snmp. With additional plugins it can also monitor health status of devices such as CPU load, memory utilization and drive space consumption.This tutorial is created as a way for me to document the steps I took to install Nagios. There are many ways to install Nagios into a functional system, this just happens to be the way that I got it to work. If you are looking for an easy way to build your own Nagios server follow along and you’ll have your own running in no time.


Some assumptions are that you have basic Linux skills, and you have a freshly installed Ubuntu 6.06 LAMP server. Even though I’m going to give you a step-by-step walk through, a foundation of basic Linux knowledge would be preferred. If you need help installing Ubuntu Linux, take a look at my tutorial “Installing a Ubuntu 6.06 LAMP Server.”

(*note: Commands preceded by a “$” are run as a normal user and commands preceded by a “#” are run as root.)

System Requirements

The following software is required for a functional nagios server. This tutorial covers the installation of this software.

  • Apache2
  • GD Library
  • Nagios
  • Nagios Plugins
  • Basic Compilers

Installation

Starting from an unprivileged session, we need to change to root.

$ su

nagios_2-6_installation_on_ubuntu_6-06_linux4.png

Enter your root password.

nagios_2-6_installation_on_ubuntu_6-06_linux5.png

Now that we have root privileges, we need to install the “build-essential” package. This is really just a list of header files that assist with compiling software.

# apt-get install build-essential

nagios_2-6_installation_on_ubuntu_6-06_linux7.png

Press “y” to confirm the installation.

nagios_2-6_installation_on_ubuntu_6-06_linux9.png

Next, we need to install the GD Graphics Library.

# apt-get install libgd2-dev

nagios_2-6_installation_on_ubuntu_6-06_linux11.png

Once again, press “y” to confirm the installation.

nagios_2-6_installation_on_ubuntu_6-06_linux13.png

Next, we will install apache2.

# apt-get install apache2

nagios_2-6_installation_on_ubuntu_6-06_linux15.png

Notice how it says apache2 is already the newest version? I started this tutorial with a fresh install of a LAMP server so apache2 was already installed and ready.

nagios_2-6_installation_on_ubuntu_6-06_linux16.png

Now it’s time to download the nagios and nagios plugin package. I’m still in the home directory of my unprivileged account. This is where I want to download the files. In the command below, I used one of many download locations. If it doesn’t work for you another source can be found at nagios.com.

The following command will download nagios:

# wget http://umn.dl.sourceforge.net/sourceforge/nagios/nagios-2.6.tar.gz

nagios_2-6_installation_on_ubuntu_6-06_linux17.png

When the download is complete you will be returned to the command prompt.

nagios_2-6_installation_on_ubuntu_6-06_linux18.png

The following command will download the nagios plugins:

# wget http://umn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.5.tar.gz

nagios_2-6_installation_on_ubuntu_6-06_linux19.png

Again, you are returned to the command prompt when the download finishes.

nagios_2-6_installation_on_ubuntu_6-06_linux20.png

Do a directory listing to confirm that the files were downloaded.

# ls

nagios_2-6_installation_on_ubuntu_6-06_linux22.png

Next, we use the “tar” command to unwrap and extract the source files of nagios.

# tar -xvf nagios-2.6.tar.gz

nagios_2-6_installation_on_ubuntu_6-06_linux23.png

Let’s go into the newly extracted nagios folder.

# cd nagios-2.6

nagios_2-6_installation_on_ubuntu_6-06_linux25.png

Let’s do a directory listing and see what we have.

# ls

nagios_2-6_installation_on_ubuntu_6-06_linux27.png

Everything looks in order here.

nagios_2-6_installation_on_ubuntu_6-06_linux28.png

Before we proceed, it’s time to create an account for the purpose of running the nagios scripts.

# adduser nagios

nagios_2-6_installation_on_ubuntu_6-06_linux29.png

You will be asked to create a password. You can pick any password you like.

nagios_2-6_installation_on_ubuntu_6-06_linux30.png

You will be asked to confirm that password.

nagios_2-6_installation_on_ubuntu_6-06_linux31.png

Next you will be asked to enter some information pertaining to the new user. All of this information is optional.

nagios_2-6_installation_on_ubuntu_6-06_linux32.png

Press “y” to confirm. After confirming the information, the user is created.

nagios_2-6_installation_on_ubuntu_6-06_linux33.png

Next we need to make new home for our nagios installation. You can choose any location you like, however you will need to modify this tutorial to correspond to your installation. If this is your first install it may be best to use my suggested location.

# mkdir /usr/local/share/nagios

nagios_2-6_installation_on_ubuntu_6-06_linux35.png

Now we need to make the nagios user the owner of our nagios install folder.

# chown nagios.nagios /usr/local/share/nagios/

nagios_2-6_installation_on_ubuntu_6-06_linux37.png

Next, we need to create a group on our system that will be allowed to execute external commands from the web interface.

# /usr/sbin/groupadd nagcmd

nagios_2-6_installation_on_ubuntu_6-06_linux39.png

Now, we’ll add the apache user and the nagios user to the nagcmd group.

# /usr/sbin/usermod -G nagcmd www-data

nagios_2-6_installation_on_ubuntu_6-06_linux41.png

# /usr/sbin/usermod -G nagcmd nagios

nagios_2-6_installation_on_ubuntu_6-06_linux43.png

Now we’re ready to prepare the installation scripts.

# ./configure --prefix=/usr/local/share/nagios --with-cgiurl=/nagios/cgi-bin --with-htmurl=/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd

nagios_2-6_installation_on_ubuntu_6-06_linux45.png

If the previous command comes back without reporting any errors you can run the following commands. If errors are reported, fix them and run “make clean” before running the previous command again.

# make all

nagios_2-6_installation_on_ubuntu_6-06_linux47.png

# make install

nagios_2-6_installation_on_ubuntu_6-06_linux49.png

The following command creates the initialization scripts for nagios.

# make install-init

nagios_2-6_installation_on_ubuntu_6-06_linux51.png

The following command creates the folder permissions nagios needs.

# make install-commandmode

nagios_2-6_installation_on_ubuntu_6-06_linux53.png

Create the sample configuration files.

# make install-config

nagios_2-6_installation_on_ubuntu_6-06_linux55.png

Let’s move up one directory

# cd ..

nagios_2-6_installation_on_ubuntu_6-06_linux57.png

A directory listing will show us the contents.

# ls

nagios_2-6_installation_on_ubuntu_6-06_linux60.png

It’s time to extract the nagios plugin scripts.

# tar -xvf nagios-plugins-1.4.5.tar.gz

nagios_2-6_installation_on_ubuntu_6-06_linux61.png

Next, we change to the nagios plugins folder.

# cd nagios-plugins-1.4.5

nagios_2-6_installation_on_ubuntu_6-06_linux63.png

Now, we configure the plugin installation scripts.

# ./configure --prefix=/usr/local/share/nagios --with-cgiurl=/nagios/cgi-bin

nagios_2-6_installation_on_ubuntu_6-06_linux65.png

If the previous command comes back without reporting any errors you can run the following commands. If errors are reported, fix them and run “make clean” before running the previous command again.

# make

nagios_2-6_installation_on_ubuntu_6-06_linux67.png

Install the plugins.

# make install

nagios_2-6_installation_on_ubuntu_6-06_linux69.png

# make install-root

nagios_2-6_installation_on_ubuntu_6-06_linux71.png

Change directories up one level.

# cd ..

nagios_2-6_installation_on_ubuntu_6-06_linux73.png

Now, it’s time to configure apache2 to serve up the nagios web interface.

# nano /etc/apache2/conf.d/nagios.conf

nagios_2-6_installation_on_ubuntu_6-06_linux76.png

Type or past the following lines into the nano editor.

ScriptAlias /nagios/cgi-bin /usr/local/share/nagios/sbin


Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/share/nagios/etc/htpasswd.users
Require valid-user


Alias /nagios /usr/local/share/nagios/share


Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/share/nagios/etc/htpasswd.users
Require valid-user

nagios_2-6_installation_on_ubuntu_6-06_linux78.png

nagios_2-6_installation_on_ubuntu_6-06_linux79.png

Press “ctrl-x” to close the file. Press “y” to confirm saving when asked.

nagios_2-6_installation_on_ubuntu_6-06_linux80.png

Use the default location of “/etc/apache2/conf.d/nagios.conf” for saving the file.

nagios_2-6_installation_on_ubuntu_6-06_linux81.png

Reload apache to apply the new settings.

# /etc/init.d/apache2 restart

nagios_2-6_installation_on_ubuntu_6-06_linux83.png

Create a password file for users authorized to access the nagios web interface. Here I’ll use “nagiosadmin” as the username.

(* The “-c” option tells htpasswd to create a new file. If you are adding multiple users don’t use the “-c” option or else you will continually create a new file, erasing the previous entries before them.)

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

nagios_2-6_installation_on_ubuntu_6-06_linux85.png

Choose a secure password for the nagiosadmin account.

nagios_2-6_installation_on_ubuntu_6-06_linux86.png

Confirm your password.

nagios_2-6_installation_on_ubuntu_6-06_linux87.png

nagios_2-6_installation_on_ubuntu_6-06_linux88.png

We’re finished using root access for now, time to logout.

# exit

nagios_2-6_installation_on_ubuntu_6-06_linux89.png

We can now proceed to a computer with a web browser. In the address bar, type http:///nagios where is the IP address of the nagios server.

nagios_2-6_installation_on_ubuntu_6-06_linux93.png

You should get an authentication prompt. You can enter your nagiosadmin user-name and password here and click ok.

nagios_2-6_installation_on_ubuntu_6-06_linux95.png

What should appear next is your nagios server’s web interface.

nagios_2-6_installation_on_ubuntu_6-06_linux96.png

What next?

At this point you have nagios installed. It isn’t useful yet because we haven’t configured it, nor have we started the nagios service on the server. The next step is to follow my guide for configuring nagios.

If you find any errors, typos, omissions or have any questions, please give me a shout. Thanks!

Credits

Jon aka cavern
http://ubuntuforums.org/showthread.php?t=223498

Aucun commentaire: