Step by Step Guide on How to Install Nagios in Ubuntu Jaunty To EC2 Instance from Source

Nagios is a good open source montoring tool. When trying to install nagios to our ubuntu server, I find there are lot of scattered documentation on the web, but not a single complete one that walk you step by step on how to install it to Ubuntu 9.04 Jaunty server. After encounter many dependency problems, espeically with the nagios plugin, I decided to do a total clean install in a valila server and record each steps. Hopefully, it will be useful to others who might want to install Nagios 3 to Ubuntu Jaunty.

Step I : Get a basic Ubuntu Jaunty OS server ready.

I am using an EC2 instance to install Nagios, you can launch an EC2 instance either through command line or through amazon AWS webconsole.
I launched a AMI image with just a base install of Ubuntu 9.04 jaunty.

Once the AMI has been successfully launched, if you use a public image, make sure to change the root password by using passwd at the ssh console. Also make sure that you use the keys that amazon provide and configure the security group to something not default.

Step II: Get the Server Ready for Nagios Installation

Prepare the server environment

  • Figure out the Kernel version -- Just to know

    $ cat /etc/issue

    Ubuntu 9.04 \n \l

  • Check the ubuntu package sources, make a copy of the source list file and them modify the source list file to make sure you have access to the adequate amount of repositories. Here are the code to use:
    $ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    $ sudo vi /etc/apt/sources.list

  • Update your system to use the updated sources
    $ sudo apt-get update
  • Upgrade your system
    $ sudo apt-get upgrade
  • Since we are installing it from source (so we have the updated version of nagios), we need to make sure that we can build from the source by installing the "build essential" library
    $ sudo apt-get install build-essential
  • Since Nagios uses web interface to interact with users, we will have to install a web server. There are a few webervers available. But we will be using apache 2 here.
    $ sudo apt-get install apache2 wget
  • As mentioned before, there are a few dependency libraries needed to install ngaios and its plugins.
    $ sudo apt-get install bind9-host dnsutils libbind9-40 libdns45 libdns46 libisc45 libisccc40 libisccfg40 liblwres40 libdns46 rblcheck libradius1 qstat snmp snmpd radiusclient1 libperl5.10 libsensors3 libsnmp-base libsnmp15 libsysfs2 lm-sensors libsensors4 qstat sensord read-edid i2c-tools defoma fontconfig fontconfig-config libcairo2 libdatrie0 libdirectfb-1.0-0 libfontconfig1 libfontenc1 libfreetype6 libpango1.0-0 libpango1.0-common libpixman-1-0 libpng12-0 librrd4 libthai-data libthai0 libts-0.0-0 libxcb-render-util0 libxcb-render0 libxfont1 libxft2 libxrender1 ttf-dejavu ttf-dejavu-core ttf-dejavu-extra x-ttcidfont-conf xfonts-encodings xfonts-utils libdatrie0 libdirectfb-1.0-0 libfontconfig1 libfontenc1 libfreetype6 libpango1.0-0 libpango1.0-common libpixman-1-0 libpng12-0 librrd4 libthai-data libthai0 libts-0.0-0 libxcb-render-util0 libxcb-render0 libxfont1 libxft2 libxrender1 read-edid sensord ttf-dejavu ttf-dejavu-core ttf-dejavu-extra x-ttcidfont-conf xfonts-encodings xfonts-utils
  • $ sudo apt-get install mailx libapache2-mod-php5 php5 php-pear php5-gd php5-ldap php5-snmp apache2-mpm-prefork libapache2-mod-php5 libgd2-xpm libjpeg62 libt1-5 libxpm4 php-pear php5 php5-cli php5-common
  • $ sudo libgd-tools autoconf automake automake1.4 autotools-dev libgd-tools libltdl7 libltdl7-dev libssl-dev libtool m4 php5-dev shtool zlib1g-dev
  • $ sudo apt-get install librrd4 librrds-perl rrdtool
  • Some of those dependencies are installed automatically. Since I have all of them in my notes, so they are listed all here.

  • Make sure apache starts fine

    $ sudo /etc/init.d/apache2 start

  • Test apache: wget http://127.0.0.1
    Get the following response:
    --2010-02-04 21:36:56-- http://127.0.0.1/
    Connecting to 127.0.0.1:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 45 [text/html]
    Saving to: `index.html'

    100%[===============================================================================>] 45 --.-K/s in 0s

    2010-02-04 21:36:56 (10.7 MB/s) - `index.html' saved [45/45]



  • More libaries that can make nagios an eye candy:
    $ sudo apt-get install libgd2-noxpm-dev libpng12-dev libjpeg62 libjpeg62-dev
  • Install MySQL and client
    $ sudo apt-get install mysql-server
    $ sudo apt-get install php5-mysql

    $ sudo apt-get install libmysqlclient15-dev
  • Nagios will not run as root, for better security, therefore, we have to make a system user to run nagios. nagios and group nagcmd, this group will have nagios and www-data as its member
    $sudo /usr/sbin/useradd nagios
    $ sudo passwd nagios
    $ sudo /usr/sbin/groupadd nagcmd
    $ sudo /usr/sbin/usermod -g nagcmd nagios
    $ sudo /usr/sbin/usermod -g nagcmd www-data




Step III: Installing the Monitoring Server -- Nagios

Tried the official downloads and find that it is not the latest version of Nagios 3.2.0 and 1.4.14 for nagios plugins. So I decided to download from source.

$ sudo cd /usr/src

$ sudo wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.0/nagios-3.2.0.tar.gz/download

$ sudo wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.14/nagios-plugins-1.4.14.tar.gz/download

$ sudo wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.12/nrpe-2.12.tar.gz/download

$ sudo wget http://sourceforge.net/projects/nagios/files/nsca-2.x/nsca-2.7.2/nsca-2.7.2.tar.gz/download

$ sudo wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b9/ndoutils-1.4b9.tar.gz/download







    Compiling Nagios from Source

  • First, we unpack the tar ball
    $ tar xzf nagios-3.2.0.tar.gz
  • $ cd nagios-3.2.0
  • $ ./configure --with-command-group=nagcmd
  • Check the output

  • $ sudo make all
    Here is the output from make
  • $ sudo make install
    Make Install output here
  • $ sudo make install-config
    You can check the Make Install config outputhere
  • $ make install-commandmode
    /usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
    chmod g+s /usr/local/nagios/var/rw

    *** External command directory configured ***

    Made sure the configurations are all fine.


  • $ make install-init
    /usr/bin/install -c -m 755 -d -o root -g root /etc/init.d
    /usr/bin/install -c -m 755 -o root -g root daemon-init /etc/init.d/nagios

    *** Init script installed ***


  • Make the following sym link so that nagios will start with the system
    $ sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
  • Now, install the web interface:
    $ sudo make install-webconf
    $ sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/conf.d/nagios.conf
    *** Nagios/Apache conf file installed ***

  • Add access control for the web access
    $ cd /usr/local/nagios/etc/
    $sudo htpasswd -c htpasswd.users nagiosadmin
    New password:
    Re-type new password:
    Adding password for user nagiosadmin



    • Install Nagios Plugin Now:

      • Install more libraries
        $ sudo apt-get install fping libnet-snmp-perl libldap2-dev libgnutls-dev libradiusclient-ng2
      • Install the plugins
        $ cd /usr/src
        $ tar xzf nagios-plugins-1.4.14.tar.gz
        $ cd nagios-plugins-1.4.14
        $ sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd

        Here is the output
        $ sudo make
        Output here



      Test your installation

      Now is time to test your installation. First make sure you added your requirement into the configuration files, like your contact information, the host your want to monitor, the command that you are using etc. You can find the format in the sample configuration. Once you changed the configuration file to your liking, it 's time to see if all you have done is not in vain.

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

      You get the following output, or something like this:

      Nagios Core 3.2.0
      Copyright (c) 2009 Nagios Core Development Team and Community Contributors
      Copyright (c) 1999-2009 Ethan Galstad
      Last Modified: 08-12-2009
      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 20 services.
      Checking hosts...
      Checked 9 hosts.

      Checking host groups...
      Checked 1 host groups.
      Checking service groups...
      Checked 0 service groups.
      Checking contacts...

      Checked 2 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


      Congradulations! You are ready to rock. Let's start nagios

      $ sudo /etc/init.d/nagios start

      Here is the output: Starting nagios:No directory, logging in with HOME=/
      done.



      find this very interesting article