How to install NAGIOS in linux or windows server?

Solution.

INSTALLATION

Download the latest version of nagios from the following link
http://www.nagios.org/download/
Then, unpack the Nagios distribution, use the following command
#tar xzf nagios-2.6.tar.gz
Navigate  to the newly created directory
#cd nagios-version (nagios-2.6)
Run the configure script
# ./configure –prefix=/usr/local/nagios –with-cgiurl=/nagios/cgi-bin —
with-htmurl=/nagios/ –with-nagios-user=nagios –with-nagios-
group=nagios –with-command-group=nagios

where
–prefix=/usr/local/nagios is the Nagios root folder
–with-cgiurl=/nagios/cgi-bin is the Nagios CGI folder
–with-htmurl=/nagios/ is the Nagios HTML/Website folder
–with-nagios-user=nagios is the Nagios user
–with-nagios-group=nagios is the Nagios group
–with-command-group=nagios is the Nagios command group which has
webserver user (Apache) and the nagios user as members.
If we want more options just type the following command
#./configure –help

#make all
this will Compile Nagios and the CGIs
#make install
This will Install the binaries and HTML files (documentation and main
web page)
#make install-init
This will install the Startup scripts(to /etc/rc.d/init.d/nagios)
# make install-commandmode
This will Create the required directory for command file and assign
appropriate permissions to it for the external commands.
# make install-config

This installs SAMPLE config files in /usr/local/nagios/etc .We’ ‘ll have to
modify these sample files before we can use Nagios.
This will complete the installation Now we need to know the Directory
Structure and File locations. After navigating to  /usr/local/nagios , we
would see 5 sub-directories:
* bin/ Nagios core program
* etc/ Main, resource, object, and CGI configuration files should be put
here
* sbin/ CGIs
* share/ HTML files (for web interface and online documentation)
* var/ Empty directory for the log file, status file, retention file,etc.

Next thing we need to concentrate is /usr/local/nagios/etc directory
where all the sample configuration files like nagios.cfg-sample,cgi.cfg-
sample stores.
So, we need to rename these sample configuration files to .cfg files.
Hence, the basic installation of nagios is completed.

INSTALL NAGIOS PLUGINS:

Plugins are usually installed in the libexec/ directory of your Nagios
installation (i.e. /usr/local/nagios/libexec).
a) Download Nagios Plugins
b) Untar the downloaded file and navigate to nagios plugin dir.
c) ./configure and make && make install
This should install the plugins in the /usr/local/nagios/libexec directory.

SETTING UP THE WEB INTERFACE FOR NAGIOS:

1) Create configuration entries for nagios in httpd.conf
2) Restart Apache
3) Setup User Authentication:  This can be done by,
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Enter the required password when prompted. This will setup htaccess
on the site by creating a new file named htpasswd.users under
/usr/local/nagios/etc/ with the first user nagios admin.
You can add as many user you wish by
# htpasswd /usr/local/nagios/etc/htpasswd.users (username)

For the CGIs to use Authentication on Nagios, edit the file
/usr/local/nagios/etc/cgi.cfg and set  “use_authentication=1”

You can now access the web interface at http://HOSTNAME>/nagios/

NAGIOS CONFIGURATION:

Main Configuration file:  nagios.cfg
Resource File: resource.cfg
Commands Config File: commands.cfg

Other Object Configuration files are:
 hosts.cfg
 hostgroup.cfg
 services.cfg
 servicegroup.cfg
 contacts.cfg
 contactsgroup.cfg
 timeperiod.cfg

Syntax Check and Nagios Reload:
/usr/local//nagios/bin/nagios -v /usr/local//nagios/etc/nagios.cfg
/etc/rc.d/init.d/nagios reload

HOSTS.CFG

define host{
        host_name               my-host
        alias                   my-host.domain.ac.uk
        address                 168.192.0.1
        check_command           check-host-alive
        max_check_attempts      10
        check_period            24×7
        notification_interval   120
        notification_period     24×7
        notification_options    d,r
        contact_groups          unix-admins
        register                1
        }

SERVICES.CFG

     define service{
     name                            ping-service
     service_description             PING
     is_volatile                     0
     check_period                    24×7
     max_check_attempts              4
     normal_check_interval           5
     retry_check_interval            1
     contact_groups                  unix-admins
     notification_options            w,u,c,r
     notification_interval           960
     notification_period             24×7
     check_command    check_ping!100.0,20%!500.0,60%
     hosts                           my-host
     register                        1
     }

HOSTGROUPS.CFG

# ‘hong-kong’ host group definition
define hostgroup{
hostgroup_name hong-kong
alias Hong Kong Group
contact_groups hk-admins*
members HK1,HK2
}

# ‘new-york’ host group definition
define hostgroup{
hostgroup_name new-york
alias New York Group
contact_groups ny-admins*
members NY1,NY2
}

NAGIOS LOG FILES

Nagios.log
Status Log:  nagios/var/status.log
Downtime Log File:  nagios/var/downtime.log
Comment log File: nagios/var/comment.log
Nagios Lock File: nagios.lock => Nagios creates this file when it runs as
a daemon. This file contains the process id (PID) number of the running
Nagios process.
State Retention File: nagios/var/status.sav                              This
is the file that Nagios will use for storing service and host state
information before it shuts down. When Nagios is restarted it will use the
information stored in this file for setting the initial states of services and
hosts before it starts monitoring anything.

NAGIOS DEFAULT PLUGINS

Some of the common plugins installed by default with installation of
Nagios are:
check_by_ssh: execute a command on a remote host using SSH
check_disk: check the percent of used disk space on a mounted file
system and generate an alert if percentage is above one of the threshold
values.
check_dns: uses the nslookup program to obtain the IP address for the
given host/domain query.
check_ftp: tests FTP connections with the specified host.
check_http: tests the HTTP service on the specified host.
check_load: tests the current system load average.
check_ping: Use ping to check connection statistics for a remote host.
check_pop: This plugin tests POP connections with the specified host.
check_smtp:  tests the SMTP service on the specified host.
check_time:  Checks time on the specified host.
check_imap : Tests the IMAP connections with the specified host.

NAGIOS EVENT HANDLER

– optional commands that are executed whenever a host or service state
change occurs.
– ability for Nagios to proactively fix problems before anyone is notified
– logs service or host events to an external database.

Event Handlers are executed when a service or host is in a ‘soft’ state ,
initially goes to a ‘hard state’ or recovers from a soft or hard state.

E.g:
define service{
        host_name                       somehost
        service_description             HTTP
        max_check_attempts              4
        event_handler                   restart-httpd
        …other service variables…
        }

===========================================
                       
                        Thank you 🙂

Leave a Reply