Bobcares

Installing and Configuring Nagios

by | Feb 20, 2006

This article attempts to provide complete and easy steps for Nagios installation on a Webserver or a Local cluster.

 

Hire Bobcares Linux Server Administrators
Get super reliable servers and delighted customers

See how we do it!

 

 

Getting Nagios

 

You need root access on the server, where you would like to install Nagios.
* Login as root.

* Create a directory for downloads.

#mkdir -p /usr/src/backs/nagios

#cd /usr/src/backs/nagios

 

Download source of nagios and nagios-plugins at http://www.nagios.org/download/

#wget http://keihanna.dl.sourceforge.net/sourceforge/nagios/nagios-1.2.tar.gz

#wget http://easynews.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.3.1.tar.gz

 

Implement custom monitoring by Bobcares.
 

Compilation and installation of Nagios

 

Login as root and create a user, say “nagios”

 

#su
#adduser nagios
#passwd nagios
Changing password for user nagios.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
In some servers normal users may not have permission to use ‘mail’ inorder to send alerts.
usermod -G mail nagios
Make a directory for working with the source code.
cd /usr/src/works/nagios/
tar -zxvf /usr/src/backs/nagios/nagios-1.2.tar.gz
cd nagios-1.2/
./configure

The default is fine for normal operation.
for details see the file ‘INSTALL’
.

./configure –prefix=prefix –with-cgiurl=cgiurl
–with-htmurl=htmurl –with-nagios-user=someuser
–with-nagios-grp=somegroup

./configure
make all
make install
make install-init # Needed to add the service ‘nagios’.
make install-commandmode
make install-config

Install the plugins
cd ../
tar -zxvf /usr/src/backs/nagios/nagios-plugins-1.3.1.tar.gz
cd nagios-plugins-1.3.1/
./configure

NOTE:- For mysql and postgresql plugins to work,
their libraries have to be installed. so to avoid
installing those we will use ‘check_tcp’
Instead later with seperate port for mysql and postgresql
.

make
make check
make install
Libraries will be installed in ‘/usr/local/nagios/libexec’ position by the default installation.
If there is no contents do the following.
mkdir /usr/local/nagios/libexec
mv /usr/lib/nagios/plugins/* /usr/local/nagios/libexec/
ln -s /lib/libcrypto.so.0.9.7a /lib/libcrypto.so.4

Post install Configuration of Nagios

Edit apache’s httpd.conf file. (the location of the httpd.conf file may differ)

vim /etc/httpd/conf/httpd.conf

Add the following line at the end of the file.

Include /etc/httpd/conf/nagios.conf

Create the file ‘/etc/httpd/conf/nagios.conf’.

vi /etc/httpd/conf/nagios.conf

Add the following contents to this file.
————————————————-
ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/
<Directory ?/usr/local/nagios/sbin/?>
AllowOverride AuthConfig
Options ExecCGI
Allow from all
Order allow,deny
</Directory>

Alias /nagios/ /usr/local/nagios/share/
<Directory ?/usr/local/nagios/share?>
Options None
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
————————————————–

Make sure the updations done with http is fine and restart apache.

#service httpd restart

Create ‘.htaccess’ file in ‘/usr/local/nagios/share/’ and ‘/usr/local/nagios/sbin/’.

#touch /usr/local/nagios/share/.htaccess
#touch /usr/local/nagios/sbin/.htaccess

Add the following contents to both these files.

AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user

Create the username, password for logging into the Nagios interface.

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

Make it available for the user who runs httpd.

chmod o+r /usr/local/nagios/etc/htpasswd.users

Restart the httpd service.

service httpd restart

Advanced Nagios Configurations.

Rename the sample files to the real names.

cd /usr/local/nagios/etc/
for i in *sample ; do mv $i `echo "$i" |sed s/-sample//` ; done

Edit the main conf file, nagios.cfg. and change only these lines.

check_external_commands=1

Make these Cgi specific changes in cgi.cfg.

use_authentication=1
authorized_for_system_information=nagiosadmin
authorized_for_configuration_information=nagiosadmin
authorized_for_system_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin

Add servers that need to be monitored

Make the Host specific changes to the hosts.cfg.

 Generic host definition template
define host{
        name                            generic-host
        notifications_enabled          1
        event_handler_enabled          1
        flap_detection_enabled          1
        process_perf_data              1
        retain_status_information      1
        retain_nonstatus_information    1

        register                        0
        }

define host{
        use                    generic-host            ; Name of host
template to use

        host_name              <FQDN of server>
        alias                  <Any alias name for the host>
        address                <IP of server>
        check_command          check-host-alive
        max_check_attempts      10
        notification_interval  120
        notification_period    24x7
        notification_options    d,u,r
        }

Repeat for all the hosts we want to check.
Group them in hostgroups.cfg

define hostgroup{
        hostgroup_name  <Host group name>
        alias          <any alias name>
        contact_groups  <contact group name>
        members        <<host1>,<host2>,..>
}

Repeat for all the hosts groups.

Specify the services that need to be checked

Edit the details of all the services, we want checked by Nagios in services.cfg.

 Generic service definition template
define service{
        name                            generic-service
        active_checks_enabled          1
        passive_checks_enabled          1
        parallelize_check              1
        obsess_over_service            1
        check_freshness                0
        notifications_enabled          1
        event_handler_enabled          1
        flap_detection_enabled          1
        process_perf_data              1
        retain_status_information      1
        retain_nonstatus_information    1
        register                        0
        }

define service{
        use                            generic-service
        host_name                      <FQDN of server to check the service>
        service_description            <Service name>
        is_volatile                    0
        check_period                    24x7
        max_check_attempts              3
        normal_check_interval          3
        retry_check_interval            1
        contact_groups                  <contact group name for alerts
to send>
        notification_interval          120
        notification_period            24x7
        notification_options            w,u,c,r
        check_command                  <check command for the service>
        }

Repeat for each service on each host.

Specify Alert Contacts

In order to specify details of the contacts for alerts, we need to edit contacts.cfg.

 'nagios' contact definition
define contact{
        contact_name                    <contact name>
        alias                          <some nickname>
        service_notification_period    24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options      d,u,r
        service_notification_commands  notify-by-email,notify-by-epager
        host_notification_commands
host-notify-by-email,host-notify-by-epager
        email                          <email address of the contact>
        pager                          <pager or mobile no.(optional)>
        }

Repeat for all contacts.

Group the contacts

Edit contactgroups.cfg, in order to specify groups of contacts.

define contactgroup{
        contactgroup_name      <contact group name>
        alias                  <any nickname for the group>
        members                <members (comma seperated)>
        }

Repeat for all groups to include all contacts

Escalation with nagios

If you need to send selective alerts, for example when critical issues occur, simply configure the escalations.cfg file.

define serviceescalation{
        host_name                      <FQDN of the server>
        service_description            < name>
        first_notification              2
        last_notification              6
        contact_groups                  < groups (comma seperated)>
        notification_interval          0
        }

Repeat for all escalations Once again, check all the files, nagios.cfg cgi.cfg hosts.cfg hostgroups.cfg, services.cfg, contacts.cfg, contactgroups.cfg, escalations.cfg and checkcommands.cfg Restart httpd and then Nagios.

service httpd restart

Add Nagios to system services.

chkconfig --add nagios
service nagios restart

Check for any errors reported, and solve them one by one if any.
Enable nagios in runlevels, so that it starts on boot.

chkconfig nagios on

Create cron.daily entry if we want to restart the service daily. Here is the script.

vi etc/cron.daily/nagios-restart.cron
#!/bin/sh
/sbin/service nagios restart >/dev/null 2>&1

Make it executable

chmod +x etc/cron.daily/nagios-restart.cron

And finally, Check if nagios is working fine.!!! 😉

http://NAGIOS-SERVER-NAME/nagios/index.html

Articles by Shivin S HameedAbout the author:
Shivin S. Hameed has worked in Bobcares.com as a Technical Support Engineer for the last 1.5 years.


6 Comments

  1. Alpha Monk

    This is good information here. I work for companies who insist on using open source software when open source software is best of breed in a market like Nagios is.

    I have written documentation like this on my blog, but you are a much better writer than I am.

    Reply
    • Visakh S

      Thank you Alpha Monk! 🙂

      Reply
  2. edward baddouh

    is there a way to obfuscate the configuration file?

    Reply
  3. Sergio

    Great information!!! Thanks!!!!

    Reply
  4. hosney

    this is good information that help me really to configure nagious monitor tool

    Reply
  5. ramesh

    I am the beginner for using nagios, this info is easy to understand and to follow.

    Reply

Trackbacks/Pingbacks

  1. Cpanel Httpd.conf Template | Cloud Hosting Service - […] Installing and Configuring Nagios – … – This article attempts to provide complete and easy steps for Nagios installation…

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.