Pages

Monday, April 1, 2013

Basic Nagios installation

This article is about basic Nagios installation in Slackware. It is not about configure Nagios completely, adding hosts etc. It is just a basic tutorial howto install Nagios from sources.
Before you begin create a directory where you can store the Nagios sources:

# mkdir -p /usr/src/nagios && cd /usr/src/nagios

Then download the nagios and the nagios-plugins sources:

# wget -c "http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.5.0.tar.gz"
# wget -c "http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz"


Before you continue create a nagios group and a nagios user:

# groupadd -g 96 nagios
# useradd -c "Nagios User" -d /opt/nagios -g nagios -m nagios -s /bin/bash -u 96


Now you can begin to compile the nagios sources. First extract the nagios source package:

# tar xf nagios-3.5.0.tar.gz
# cd nagios


Then run the configure script. I have added a few specific Slackware options for the Apache configuration and rc scripts:

# ./configure --prefix=/opt/nagios/3.5.0 --with-httpd-conf=/etc/httpd/extra --with-init-dir=/etc/rc.d
...
*** Configuration summary for nagios 3.5.0 03-15-2013 ***:

 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagios
            Embedded Perl:  no
             Event Broker:  yes
        Install ${prefix}:  /opt/nagios/3.5.0
                Lock file:  ${prefix}/var/nagios.lock
   Check result directory:  ${prefix}/var/spool/checkresults
           Init directory:  /etc/rc.d
  Apache conf.d directory:  /etc/httpd/extra
             Mail program:  /usr/bin/mail
                  Host OS:  linux-gnu
 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  /usr/bin/traceroute


If you see an output like above then run make to compile the sources:

# make all
...


Then install the binaries, the rc script, the Apache configuration and the basic configuration - step by step. Begin with the binaries:

# make install
...


Then link the new /opt/nagios/3.5.0 to /opt/nagios/latest:

# ln -s /opt/nagios/3.5.0 /opt/nagios/latest

Install the rc script and move it to /etc/rc.d/rc.nagios:

# make install-init
...
# mv /etc/rc.d/nagios /etc/rc.d/rc.nagios


Install the Apache configuration for Nagios:

# make install-webconf
...


Install the basic Nagios configuration and link it to /etc

# make install-config
...
# ln -s /opt/nagios/latest/etc /etc/nagios


Before you can start Nagios you need to create one additional directory. Use the prior created Nagios user for creating the directory:

# su - nagios
$ mkdir -p /opt/nagios/latest/var/rw/


Next continue and configure Apache. You need to enable cgi, php, add index.php as DirectoryIndex diective and add the new Nagios configuration file for Apache (I assume you have an untouched Apache configuration shipped with Slackware):

# vi /etc/httpd/httpd.conf
...
LoadModule cgi_module lib64/httpd/modules/mod_cgi.so
...
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
...
# Uncomment the following line to enable PHP:
#
Include /etc/httpd/mod_php.conf
...
# Nagios
Include /etc/httpd/extra/nagios.conf


Before you can navigate to your new Nagios in your browser you need to create a user for authentication. A user nagiosadmin is already defined in the cgi.cfg for Nagios, the only thing you need to do is to create a htpasswd file and set a password for the nagiosadmin user (run htpasswd as nagios user):

# su - nagios
$ htpasswd -c /opt/nagios/latest/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagios


Since the Apache user needs access to the Nagios web files it is a wise choice to add the Apache user to the Nagios group:

# usermod -a -G nagios apache

Then run chmod on the rc.https script to make it executable and start Apache daemon httpd:

# chmod 755 /etc/rc.d/rc.httpd
# /etc/rc.d/rc.httpd start


Do the same with the rc script for nagios:

# chmod 755 /etc/rc.d/rc.nagios
# /etc/rc.d/rc.nagios start

At this point you should be able to navigate your browser to the Nagios URL, eg. http://hq01/nagios/. The first thing you need to do is to apply your username (nagiosadmin) and password you have choosen for the htpasswd command. You can navigate a little through the Nagios web interface but currently there is not too much to see since only localhost is configured. More worse, if you list all the hosts (click on 'Services' on the left navigation bar) then localhost seems to be down. That's because the ping plugin is missing but I'll show you how to install the plugins in the next section.

Change back to the location where you've stored the Nagios sources:

# cd /usr/src/nagios

Then extract the nagios-plugins sources and change in the new directory:

# tar xf nagios-plugins-1.4.16.tar.gz
# cd nagios-plugins-1.4.16


Run the configure script with the same prefix as used for Nagios configure script:

# ./configure --prefix=/opt/nagios/3.5.0
...
            --with-apt-get-command:
              --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
               --with-ping-command: /bin/ping -n -U -w %d -c %d %s
                       --with-ipv6: yes
                      --with-mysql: /usr/bin/mysql_config
                    --with-openssl: yes
                     --with-gnutls: no
               --enable-extra-opts: no
                       --with-perl: /usr/bin/perl
             --enable-perl-modules: no
                     --with-cgiurl: /nagios/cgi-bin
               --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
                   --enable-libtap: no


No more action needed, just run make followed by make install:

# make
...
# make install
...


When the plugins are installed (/opt/nagios/latest/libexec) then navigate your browser back to localhost in the Nagios web interface. After some time localhost should be appear as 'up'.
That's it. Nagios is up and running and ready for more hosts, services etc.
If you want to start Nagios during boot then add the following line to your rc.local script:

echo "/etc/rc.d/rc.nagios start" >> /etc/rc.d/rc.local

With this line Nagios will always start when you boot your system.


No comments:

Post a Comment