Sunday, October 17, 2010

Installing Nagios - the simple way


Nagios is a network monitoring application. Using nagios we can monitor the hosts and services and it will alert the users when things go wrong.

Configuration

For configuring nagios first we want to compile apache and php.

And also make sure that gcc glibc glibc-common gd gd-devel openssl is installed in your system.

Then create Nagios User account and group

useradd -m nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache

Download the following packages from nagios.org

1. nagios core
2. nagios plugins
3. nagios addons (nrpe)

then extract all the files.

Nagios Core

Get into the nagios core directory:

./configure -with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf #Installing nagios web interface:




If you are not making any changes, it will install nagios to /usr/local/nagios by default. And Nagios Web Interface will be installed to /usr/local/nagios/share ( http conf file added to /etc/httpd/conf.d/nagios.conf )

restart apache: /usr/local/apache/bin/apachectl restart

Now we want to tell the apache, where the nagios is located. For that
vim /usr/local/apache/conf/httpd.conf

paste this to anywhere on the file
Include “/usr/local/apache/conf/nagios.conf”
Then manually create the nagios.conf file and the following entry to it.
vim usr/local/apache/conf/nagios.conf

ScriptAlias /nagios/cgi-bin “/usr/local/nagios/sbin”

Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName “Nagios Access”
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
Alias /nagios “/usr/local/nagios/share”

Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName “Nagios Access”
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user


Nagios Plugin

Get into the nagios plugin dir:
We need openssl-devel package installed to compile plugins with ssl support.

yum -y install openssl-devel

/configure -with-nagios-user=nagios -with-nagios-group=nagios -with-openssl

make
make install

Specifying the email id for alerts:
vi /usr/local/nagios/etc/objects/contacts.cfg

there you can see an entry
email nagios@localhost change this to whatever you want.


Verifying the configuration files:

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

If you are not made any mistakes then there will be zero warnings and errors. If there is some errors it will display the error files with the line numbers.

Enable Nagios to start at system startup :

chkconfig --add nagios

chkconfig nagios on


Start the Nagios:
service nagios start

Now you can access the web interface by typing this into your browser:

http://ip-address/nagios/


NRPE Installation and Setup:



Get into the nrpe dir:
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd


Then open the nrpe file
vi /etc/xinetd.d/nrpe
there you can see an entry like this


only_from = 127.0.0.1
either comment that line or specify the addresses of all networks you want to allow.


vi /etc/services


add the nagios entry to it


nrpe 5666/tcp # NRPE

Restart Xinetd and Set to start at boot:

chkconfig xinetd on
service xinetd restart

To check NRPE daemon is running and listening on port 5666:
type

netstat -at |grep nrpe

Output should be:-
tcp 0 0 *:nrpe *.* LISTEN
or you can try

netstat -plan | grep 5666
tcp 0 0.0.0.0:5666 0.0.0.0:* LISTEN 15721/xinetd

Check nrpe daemon is functioning:

/usr/local/nagios/libexec/check_nrpe -H localhost

if nrpe daemon is functioning you will get an otput like this
NRPE v2.12

Make sure to open port 5666 on the firewall of the remote server so that the Nagios monitoring server can access the NRPE daemon.

Then open the nagios.cfg and add entries

cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg

some entries may be already there. So check before you adding.

Open the file /usr/local/nagios/etc/objects/commands.cfg and add the following entry to it.

vi /usr/local/nagios/etc/objects/commands.cfg
define command{
command_name check_nrpe
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}



Then manually create the hosts.cfg and specify the details about hosts:
vi /usr/local/nagios/etc/objects/hosts.cfg

define hostgroup{
hostgroup_name server1
alias server2
members server1.example.com
}
define hostgroup{
hostgroup_name server2
alias server2
members server2.example.com
}




then give the ipaddress of the hosts
define host{
use generic-host ; Name of host template to use
host_name server1.example.com
alias server1
address specify the ipaddress
check_command check-host-alive
max_check_attempts 3
notification_interval 300
notification_period 24×7 #check timeperiods.cfg and give the entry correctly or create a new one
notification_options d,u,r
contact_groups admins
}

define host{
use generic-host ; Name of host template to use
host_name server2.example.com
alias server2
address specify the ipaddress
check_command check-host-alive
max_check_attempts 3
notification_interval 300
notification_period 24×7
notification_options d,u,r
contact_groups admins
}




Client Side Setup

create Nagios user account on the client

useradd nagios
passwd nagios


we need the openssl-devel package installed to compile plugins with ssl support
yum -y install openssl-devel
get into the nagios plugins dir


./configure -with-nagios-user=nagios -with-nagios-group=nagios -with-openssl
make
make install
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec

yum install xinetd

NRPE Daemon



Get into the nrpe dir:

./configure

make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd


then open the nrpe file
vi /etc/xinetd.d/nrpe

and do the same what we had done in server side

# only_from = 127.0.0.1

then add entry for nrpe daemon
vi /etc/services
nrpe 5666/tcp # NRPE


Restart Xinetd and Set to start at boot:
chkconfig xinetd on
service xinetd restart

Test NRPE Daemon Install

Check NRPE daemon is running and listening on port 5666:

netstat -at |grep nrpe

Output should be:-
tcp 0 0 *:nrpe *.* LISTEN
or
netstat -plan | grep 5666

output should be
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 15721/xinetd


Check NRPE daemon is functioning

/usr/local/nagios/libexec/check_nrpe -H localhost

Output should be NRPE version:
NRPE v2.12

vi /etc/nrpe.conf


command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 5,100,100 -c 10,100,100
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_procs]=/usr/local/nagios/libexec/check_procs -w 500 -c 1000
command[check_cron]=/usr/local/nagios/libexec/check_procs -w 1:5 -c 1:20 -C crond
command[check_mem]=/usr/local/nagios/libexec/check_mem -w 90 -c 95
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 10% -c 5%


Test Connection to NRPE daemon on Remote Server:-


Make sure that the NRPE on ther Nagios server can talk to the NRPE daemon on the remote server (Client) we want to monitor.
Execute the command:-

/usr/local/nagios/libexec/check_nrpe -H

output should be

NRPE v2.12

If you got this as well thats it. You have installed the nagios successfully. You can access the nagios interface from the browser by entering your serverIP/nagios .

0 comments:

  © Blogger templates Newspaper III by Ourblogtemplates.com 2008

Back to TOP