How to install Nagios on Ubuntu server - gHacks Tech News

How to install Nagios on Ubuntu server

Are you one of those special geeks that think there is never TMI (too much information)? If that describes you then Nagios is the monitor for you. Once installed, Nagios will keep you busy with more information about your system than you ever thought possible. But it's not just a matter of running apt-get install nagios. No, there's more to the installation than that.

In this article you will see how to install Nagios on a working Ubuntu Server installation. The release I used was 9.04, but you should be able to use 8.04 just as easily.

Features

You want features? Nagios is full of them. Nagios can monitor your entire network, you can handle problem remediation, you can plan network downtime, you can watch hosts, systems, services, applications..there's very little you can't do with Nagios.

But let's think about this installation. The best (and really only good) way to install Nagios is from source. This means you are going to have to do some compliation. Don't worry, it's not hard...when you have a step-by-step guide that is.

Before you start

If you are using, as I did, a Ubuntu server installation, you will need to install a few tools first. So from the command line (on your Ubuntu server) issue the following commands:

sudo apt-get install php5-gd

sudo apt-get install gcc

sudo apt-get install make

The above commands will install the tools you need in order to get Nagios installed. If you don't install the above, you won't be able to complete the installation.

Installing Nagios - preflight

Before you actually run the installation you will need to take care of some user/group accounting first.

Create the user nagios:

sudo useradd -m nagios

Give the nagios user a password:

sudo passwd nagios

NOTE: You will have to enter the new password twice for the above command.

Create the group nagios:
sudo groupadd nagios

Add the user nagios to the group nagios:

sudo usermod -G nagios nagios

Create the group nagcmd:

sudo groupadd nagcmd

Add the user nagios to the group nagcmd:

sudo usermod -a -G nagcmd nagios

Add the Apache user to the group nagcmd:

sudo usermod -a -G nagcmd www-data

Installing Nagios and Nagios Plugins

The first thing to do is to download the files you need. Issue the commands:

wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.6.tar.gz

and

wget http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-
plugins-1.4.11.tar.gz

to download the files you need.

Untar the Nagios file with:

tar xvzf nagios-3.0.6.tar.gz

Change into the newly created Nagios directory with the command:

cd nagios-3.0.6

Now run the configure script using the nagcmd defined as the command group with the command:

sudo ./configure --with-command-group=nagcmd

Time to compile:

sudo make all

Time to install everything:

make install

make install-init

make install-config

make install-commandmode

Almost ready to finalize the installation of Nagios (before moving on to installing the plugins.) There is one simple configuration to take care of (for the basic installation). Open up the /usr/local/nagios/etc/objects/contacts.cfg file and add your email address as the contact email address. That's the only configuration to change for now.

Configuring for the Web interface

There are just a few commands to run to configure the Web interface:

make install-webconf

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

/etc/init.d/apache2 reload

The final command above simply restarts Apache.

Install the plugins

Before you log into your Nagios installation you have to install your plugins first. Change to the directory you downloaded the Nagios files to and untar the plugins file:

tar xvzf nagios-plugins-1.4.11.tar.gz

Now change into the newly created directory:

cd nagios-plugins-1.4.11

Compile the plugins with the command:

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

Now install the plugins with the following commands:

make

make install

Fire it up!

Of course you want to make sure Nagios starts any time the system is restarted. Do this with the command:

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

And finally, before you start up Nagios, make sure there are no errors with the command:

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

If you see no errors reported, it's time to start it up. Issue the command:

sudo /etc/init.d/nagios start

Nagios is ready to go. Point your browser to:

http://ADDRESS_OF_NAGIOS_SERVER/nagios

You should be ready to enjoy all that is Nagios. Congratulations.

Advertisement

We need your help

Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.

If you like our content, and would like to help, please consider making a contribution:


Previous Post: «
Next Post: »

Comments

  1. server support said on June 8, 2009 at 1:47 pm
    Reply

    Nagios is a free, open-source tool that can be used to monitor network components and services. When it detects a problem, it can send

    alert messages by either e-mailr. then server engineer easily can manage his network. It can also be configured so that only designated

    personnel can view status information for particular services or equipment.

    Installation:
    Nagios3 is in the repository for Ubuntu 8.10.

    we can watch that it will install a number of packages to make it all work.
    The following extra packages will be installed:
    libfreetype6 libgd2-noxpm libjpeg62 libnet-snmp-perl libperl5.10 libpng12-0
    libradius1 libsensors3 libsnmp-base libsnmp15 libsysfs2 libtalloc1
    libwbclient0 nagios-images nagios-plugins nagios-plugins-basic
    nagios-plugins-standard nagios3-common nagios3-doc radiusclient1
    samba-common smbclient snmp

    Suggested packages:
    libfreetype6-dev libgd-tools libcrypt-des-perl libdigest-hmac-perl
    libdigest-sha1-perl libio-socket-inet6-perl lm-sensors nagios2 nagios-text
    nagios whois nagios-nrpe-plugin smbfs
    The following NEW packages will be installed:
    libfreetype6 libgd2-noxpm libjpeg62 libnet-snmp-perl libperl5.10 libpng12-0
    libradius1 libsensors3 libsnmp-base libsnmp15 libsysfs2 libtalloc1
    libwbclient0 nagios-images nagios-plugins nagios-plugins-basic
    nagios-plugins-standard nagios3 nagios3-common nagios3-doc radiusclient1
    samba-common smbclient snmp
    0 upgraded, 24 newly installed, 0 to remove and 0 not upgraded.
    Need to get 19.5MB of archives.
    After this operation, 54.6MB of additional disk space will be used.

    Once it is installed run a pre-flight check to verify it is working correctly.

  2. Jack Wallen said on June 8, 2009 at 2:37 pm
    Reply

    if you do install it this way (via apt) you will install it with the command:
    sudo apt-get install nagios3

    you will have to answer a few questions during the installation – most of them to do with email.

    WARNING: i did try to run this type of installation and nagios wound up working but no plugins would work with it. installing via source didn’t have these problems.

  3. tho said on June 15, 2009 at 4:43 pm
    Reply

    Hi Jack.

    I’m pretty new to linux but i followed your manual and everything worked out fine, no errors or warnings. How ever the last command “sudo /etc/init.d/nagios start” does not work – “command not found”. Any advice on how to fix this?

    Thanks for a straight forward and easy to use manual, just the thing I needed.

    tho.

  4. Adam Oakley said on June 17, 2009 at 8:35 pm
    Reply

    Jack,
    I am following your guide to install Nagios on a Ubuntu server. However when I get to the following command it does not seem to like it.
    The command is Sudo ./configure -with-command-group=magcmd

    After I input this command I get the following:
    Checking for a BSD-compatible install… /usr/bin/install -c
    Checking build system type… i686-pc-linux-gnulibc1
    Checking host system type… i686-pc-linux-gnulibc1
    Checking for gcc… gcc
    Checking for C compiler default output file name… configure: error: C compiler cannot create executables
    See ‘config.log’ for more details.

    All the steps leading up to this have worked great not sure why this one is giving me troubles. If anyone has any ideas please let me know. thank you.

    Adam

    1. Michael Lee said on October 21, 2009 at 4:28 pm
      Reply

      I got this error during the configure as well. Going through the nagios html docs I found a line to

      apt-get install build-essential

      after that everything worked as suggested.

  5. Brian Shacklett said on June 18, 2009 at 1:30 am
    Reply

    In my searches, I’ve noticed that a lot of people are installing Nagios from source on Ubuntu. I’m curious why you chose this route as opposed to installing the pre-built packages.

  6. server support said on June 25, 2009 at 10:39 am
    Reply

    This Tutorial is intended to provide you with simple instructions on how to install Nagios from source (code) on Ubuntu and have it monitoring your local machine inside of 20 minutes.

    If you follow these instructions, here’s what you’ll end up with:

    Nagios and the plugins will be installed underneath /usr/local/nagios

    Nagios will be configured to monitor a few aspects of your local system (CPU load, disk usage, etc.)

    The Nagios web interface will be accessible at http://localhost/nagios/

    Required Packages:
    ……………..

    Make sure you’ve installed the following packages on your Ubuntu installation before continuing.

    Apache 2
    GCC compiler and development libraries
    GD development libraries

    Preparing Your System

    First you need to install the following packages

    sudo apt-get install apache2

    sudo apt-get install build-essential

    sudo apt-get install libgd2-xpm-dev

    1) Create Account Information

    Become the root user.

    sudo -s

    Create a new nagios user account and give it a password.

    #/usr/sbin/useradd nagios

    #passwd nagios

    On Ubuntu server edition , you will need to also add a nagios group (it’s not created by default). You should be able to skip this step on desktop editions of Ubuntu.

    #/usr/sbin/groupadd nagios

    #/usr/sbin/usermod -G nagios nagios

    Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.

    #/usr/sbin/groupadd nagcmd

    #/usr/sbin/usermod -G nagcmd nagios

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

    2) Download Nagios and the Plugins

    Create a directory for storing the downloads.

    #mkdir ~/downloads

    #cd ~/downloads

    Download the source code tarballs of both Nagios and the Nagios plugins (visit http://www.nagios.org/download/ for links to the latest versions). At the time of writing, the latest versions of Nagios and the Nagios plugins were 2.10 and 1.4.10, respectively.

    #wget http://switch.dl.sourceforge.net/sourceforge/nagios/nagios-2.10.tar.gz

    #wget http://kent.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.10.tar.gz

    3) Compile and Install Nagios

    Extract the Nagios source code tarball.

    #cd ~/downloads

    #tar xzf nagios-2.10.tar.gz

    #cd nagios-2.10

    Run the Nagios configure script, passing the name of the group you created earlier like so:

    #./configure –with-command-group=nagcmd

    Compile the Nagios source code.

    #make all

    Install binaries, init script, sample config files and set permissions on the external command directory.

    #make install

    #make install-init

    #make install-config

    #make install-commandmode

    Don’t start Nagios yet – there’s still more that needs to be done…

    4) Customize Configuration

    Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. You’ll need to make just one change before you proceed…

    Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts.

    #vi /usr/local/nagios/etc/objects/contacts.cfg

    5) Configure the Web Interface

    Install the Nagios web config file in the Apache conf.d directory.

    #make install-webconf

    Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account – you’ll need it later.

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

    Restart Apache to make the new settings take effect.

    #/etc/init.d/apache2 reload

    6) Compile and Install the Nagios Plugins

    Extract the Nagios plugins source code tarball.

    #cd ~/downloads

    #tar xzf nagios-plugins-1.4.10.tar.gz

    #cd nagios-plugins-1.4.10

    Compile and install the plugins.

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

    #make

    #make install

    7) Start Nagios

    Configure Nagios to automatically start when the system boots.

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

    Verify the sample Nagios configuration files.

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

    If there are no errors, start Nagios.

    #/etc/init.d/nagios start
    8) Login to the Web Interface

    You should now be able to access the Nagios web interface at the URL below. You’ll be prompted for the username (nagiosadmin) and password you specified earlier.

    http://localhost/nagios/

    Click on the “Service Detail” navbar link to see details of what’s being monitored on your local machine. It will take a few minutes for Nagios to check all the services associated with your machine, as the checks are spread out over time.

    9) Other Modifications

    If you want to receive email notifications for Nagios alerts, you need to install the mailx (Postfix) package.

    #apt-get install mailx

    You’ll have to edit the Nagios email notification commands found in /usr/local/nagios/etc/commands.cfg and change any ‘/bin/mail’ references to ‘/usr/bin/mail’. Once you do that you’ll need to restart Nagios to make the configuration changes live.

    #/etc/init.d/nagios restart

  7. Juan said on December 1, 2009 at 6:19 pm
    Reply

    Whoops!

    Error: Could not read object configuration data!

    Here are some things you should check in order to resolve this error:

    1. Verify configuration options using the -v command-line option to check for errors.
    2. Check the Nagios log file for messages relating to startup or status data errors.

  8. none said on December 9, 2009 at 12:18 pm
    Reply

    Your detailed guide is out of date and won’t work.
    Some commands duplicate actions.
    e.g
    #/usr/sbin/groupadd nagios
    #/usr/sbin/usermod -G nagios nagios

    The previous useradd nagios command automatically creates the group nagios and adds nagions
    userid to it.

    # wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.6.tar.gz
    This file does not exist. Best to download it from nagios.org anyway.

    I stopped at this point.

  9. roger said on February 18, 2010 at 3:08 am
    Reply

    looks like with 9.10 / 9.04 you can avoid the source install:

    https://help.ubuntu.com/community/Nagios3

    it’s just one package now!

    Enjoy.

  10. nthato said on September 30, 2010 at 2:29 pm
    Reply

    Thank you … I have nagios3.0.6 installed on my ubuntu server … thank you for the guidance easy to follow and understand … thank you

  11. M Roeling said on November 19, 2010 at 2:40 pm
    Reply

    Hi,

    Great walkthrough, working without a flaw. One thing: when copying on a windows machine, and pasting into a shell, the hyphens (‘-‘) sometimes have to be re-entered.

    With regards,
    Mark

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

Please note that your comment may not appear immediately after you post it.