Thursday 7 July 2011

Nagios


Nagios

Nagios is a monitoring tool, which is used for monitoring Hosts, Application and Services. In the event of a failure, Nagios can alert to technical staff of a problem.
Nagios-Plugins: Plugins are like a tools which are release time-to-time by Nagios team for bug fixes, services etc.
Nagios-nrpe: Nagios Remote Plugin Executer. The nrpe add-on plugin is designed to allow we to execute Nagios Plugin on remote Linux/Unix machine. The main reason for doing this is to allow Nagios to monitor “local resources” (like CPU load, Memory usage etc.) or remote machines.
It is possible to execute Nagios plugins on remote Linux/Unix machine through ssh. There is a check_by_ssh plugin that allows us.
The nrpe add-on consists of two pieces:
1.    The check_nrpe plugin, which resides on the local machines.
2.    The nrpe daemon, which runs on the remote Linux/Unix machine.
Configuration files in Nagios:
1.   nagios.cfg: This is the main Nagios configuration file. It contain global settings fir the packages. It defines directory locations of packages, various components, the users and group, content for the daemon, log file rotation settings, various time out and performance related settings.
2.   Object configuration files: This class of files specifies which hosts and services are monitored. In addition, they can be used to define host and service test commands, host group alert and their recipient’s event handlers.
3.   cgi.cfg: This file holds settings related to the Nagios displays, including paths to webpage items and scripts. It also defines allowed access to Nagios data and commands.
4.   resource.cfg: This file defines global macros that may be used within configuration file for clarity and security purpose. Such as to hide passwords from view in CGI program.


Installing Nagios:
Download the latest version of Nagios from http://www.nagios.org/download and extract is at /home directory or anywhere.
Requirements: httpd, php, gcc and gd packages.
            Create a group named as nagcmd and user named as nagios.
# groupadd nagcmd
# useradd –G nagcmd,apache nagios
# id nagios
# passwd nagios
# tar –zxvf nagios-version.tar.gz        (It will make a nagios-version folder)
# cd nagios-version
# ./configure - -with-command-group=nagcmd
# make all
# make install
# make install-init                                   (It install the init script in /etc/rc.d/init.d)
# make install-config                             (It install sample config files in /usr/local/Nagios/etc)
# make install-commandmode        (It install and configure permissions on the directory for holding the external command file)
            We can change the nagios admin email id line no. 35 in contacts.cfg file according to requirement.
# vi /usr/local/nagios/etc/objects/contacts.cfg
# make install-webconf                        (It install Nagios/Apache configuration file)
# htpasswd –c /usr/local/nagios/etc/htpasswd.users nagiosadmin
   passwd:********
# vi /etc/httpd/conf/httpd.conf
            Go to line no. 391 and add the “index.php”
Example:
DirectoryIndex index.html index.html.var index.php
# chkconfig - -level 35 httpd on
# service httpd restart
            Installing Nagios Plugins: Download the nagios-plugin from the same website and extract them also at /home directory and move in to the nagios-plugin-version directory.
            All Nagios plugins are resides in “/usr/local/nagios/libexec” directory. If any plugins are missing relatded to configured services then these service are show critical and status information display “plugin may be missing”.
# cd nagios-plugin-version
            To install these plugin you need to run these commands.
# ./configure - -with-nagios-user=nagios - -with-nagios-group=nagios
# make
# make install
            To compile the nagios run this command
# /usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg
# chkconfig - -level 35 nagios on
# usermod –d /usr/local/nagios nagios
# service nagios restart
            Check the nagios running process.
# ps –aux | grep nagios
# chcon –R –t httpd_sys_content_t /usr/local/nagios/sbin
# chcon –R –t httpd_sys_content_t /usr/local/nagios/share
            Login to the web interface. http://localhost/nagios
            Check for nagios log:
# tail –f /usr/local/nagios/var/nagios.log

          Add the services in nagios:
# vi /usr/local/nagios/etc/objects/commands.cfg
            Define command {
                        Command_name        check_oracle
                        Command_line            $USER$/check_oracle –tns XE
                        }
            :wq      Save and quit the file.
# vi /usr/local/nagios/etc/objects/localhost.cfg
            Define services {
                        use                                            local service
                        host_name                               localhost
                        service_description                oracle
                        check_command                    check_oracle
                        notification_enable                 0
                        }
            :wq      Save and quit the file.
            Compile the programme:
# /usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg
# service nagios restart
            If Oracle plugin is not available in “/usr/local/nagios/libexec” directory, this service is show critical. So download Oracle plugin (check_oracle) and put it in libexec directory.
            Now open the browser by 127.0.0.1/nagios. It will ask the username and password. You will see the newly added service.
            Note: If any one service plugins is not available (like bearerbox, kannel etc) then we can download a plugin which is check the service by process name. This type of plugin is a script which checks services by process name. So we can check almost services by these plugin. Require some changes in this plugin for check particular services.
            Check for plugin work properly:
# cd /usr/local/nagios/libexec
# ./check_oracle

            Install the NRPE plug-in for nagios
            Download and extract the nrpe-2.12.tar.gz file in /home directory.
# cd /nrpe-2.12
# ./configure
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
# make install-xinetd
            Now you will get the file “/usr/local/nagios/libexec/check_nrpe” plugin, and another setup files “/usr/local/nagios/etc/nrpe.cfg” & “/etc/xinetd.d/nrpe”

            Configure NRPE plug-in for nagios:
To configure nrpe we configure and install one PC as NRPE Server and other as NRPE Client.
                 NRPE Server                                             NRPE Client
1.    Nagios server                                            ----------------
2.    NRPE server                                            NRPE Client
3.    NRPE plugin                                             Nagios Plugin
First of all we configure nrpe server.
·         Install the Nagios above given steps.
·         Install NRPE server (nrpe plugin)above given steps.
When we install NRPE server it automatically installed nrpe plugins.
Now configure NRPE server.
# vi /usr/local/nagios/etc/object/command.cfg
            define command {
                        command_name       check_nrpe
                        command_line           $USER$/check_nrpe $client ip address$ $ARG1$
                        }
# vi /usr/local/nagios/etc/object/switch.cfg
            define host {
                        use                               generic-switch
                        host_name                 nrpe-client-host-name
                        alias                             any name
                        address                      nrpe-client-address
                        hostgroup                  hostgroup
                        }
            Now define host group in same file.
            define hostgroup {
                        hostgroup_name      hostgroup
                        alias                              any name
                        }
            Now define service for nrpe.
            define service {
                        use                                generic-service
                        host_name                  nrpe-client-host-name
                        check_command       check_nrpe!check_oracle
                        }
            Now configure nrpe client.
# vi /etc/xinetd.d/nrpe                                   (Go to line number 15, put the nrpe server IP)
# vi /usr/local/nagios/etc/nrpe.cfg             (Go to line number 79, put the nrpe server IP)
# vi /etc/services                                            (Add the nrpe port number)
            nrpe                 5666/tcp                      #nrpe
# service xinetd restart
# vi /usr/local/nagios/etc/nrpe.cfg
            Add the following line
            Check_command[check_oracle]=/usr/local/nagios/libexec/check_oracle - -tns XE
            :wq      Save and quite the file.
            Now open the website on nrpe server 127.0.0.1/nagios. It ask the username and password. Now new nrpe service is added.
            NRPE is completed.

            Check for Nagios is working correctly:
·         If the define service in nagios show OK and Green indication on the services, it means nagios working properly.
·         If it will show Critical and Red indication, it means service is down.
·         If it will show Unknown, It means nagios plugins not configured properly.

Change Update (Refresh rate) time: Open cgi.cfg file with vi editor which is located in “/usr/local/nagios/etc” directory. Go line number 275 and change the refresh rate. The refresh rate is in second.
# vi /usr/local/nagios/etc/cgi.cfg
            refresh_rate=2
            :wq


     Change Service check time: Open nagios.cfg file which is located in “/usr/local/nagios/etc” directory.
# vi /usr/local/nagios/etc/nagios.cfg
            589  auto_rescheduling_window=120   #180
            609 service_check_timeout=5   #60
            610 host_check_timeout=5   #30
            611 event_handler_timeout=5   #30
            612 notification_timeout=5   #30
            652 retention_update_interval=5   #60
            718 interval_length=5   #60
            1015 service_freshness_check_interval=5   #60
            1035 host_freshness_check_interval=5   #60
            1045 additional_freshness_latency=5   #15

Wednesday 6 July 2011

RAM Disk

RAM Disk/Drive

           Ram disk or ram drive is a portion of RAM which is used as a disk drive. It has fixed sizes and act as physical disk partitions. Its access time is much faster than a physical drive. The ram disk is very useful for those data which is access by number of users frequently. However, any data stored on a RAM disk is lost when the system is shut down or power off.
         The Linux kernel version 2.4 has built-in support for ram disks. Ram disks are useful for a number of things, including:
·       Working with the unencrypted data from encrypted documents
·       Serving certain types of web content
·       Mounting Loopback file systems (such as run-from-floppy/CD distributions)
            In Red Hat Linux create 16 ram disks by default, but they are not active. Ram disk devices lists from ram0 – ram19, but only ram0 – ram15 (total 16) devices are usable by default. To check these block devices we can use the following command.
# ls -l /dev/ram*                    (It show ram disk block devices list)
# dmesg | grep RAMDISK            (It show the number of ram disk and its size)
            It show the default ram disk size is 4 MB.  It means we can create a ram disk that size only 4 MB. This is the default size of ram disk.

            Increase ram disk size: Ram disk size is controlled by a command-line option that is passed to the kernel during boot. The GRUB is the default boot loader of Red Hat Linux. So we will increase the ram disk size by modify new kernel option in “/etc/grub.conf” file.
            If we want to create a 32 MB of ram disk then go to the end of kernel line and enter “ramdisk_size=32000”.
# vi /etc/grub.conf

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/hda5
#          initrd /initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Linux (2.4.20-20.9)
        root (hd0,0)
        kernel /vmlinuz-2.4.20-20.9 ro root=LABEL=/ hdc=ide-scsi ramdisk_size=32000
        initrd /initrd-2.4.20-20.9.img
:wq
            Save the file and reboot the system. After reboot check again and confirm the changes of ram disk size.
# dmesg | grep RAMDISK                        (It show 16 RAM disks and size of 32000K or 32 MB)
            Creating File system on the ram disk: If we want to need only one ram disk, so we will format only “/dev/ram0”
# mke2fs -m 0 /dev/ram
            The -m 0 option keeps mke2fs from reserving any space on the file system for the root user.

            Mount the ram disk: First create a mount point then mount the ram drive on that mount point.
# mkdir /ramdisk
# mount /dev/ram0 /ramdrive
# df -h | grep ram0                          (Verify the new ram disk mount)
# tune2fs -l /dev/ram0                                (Show detail information of ram0 device)

            If we no more need to ram disk, unmount this but data will still be there.
# umount -v /ramdrive

            Automating ram disk creation:
            If we need to create and mount a ram disk automatically every time when boot, add some commands in the “/etc/rc.local” init script.
# vi /etc/rc.local
             # Format, mounts, and sets permissions on my 32MB ram disk.
            /sbin/mke2fs -q -m 0 /dev/ram0
            /bin/mount /dev/ram0 /ramdrive
            /bin/chmod 0750 /ramdrive
:wq
            After modify it Reboot the system.
            Now 32 MB RAM disk is create and mounted on /ramdisk.

Boot to UEFI Mode or legacy BIOS mode

Boot to UEFI Mode or legacy BIOS mode Choose UEFI or legacy BIOS modes while installing Windows. After Windows is installed, if you nee...