Nagios

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

Need of monitoring

• High Availability
• Reduce downtime
• Adding redundancy to the system
• Support both physical/ virtual machines
Why Nagios ?
• Check to see if a server is up and running
• Notify you if a server is down (by email/pager/SMS)
• Check to see if a service is running (mail, http, pop, ssh)
• Check to see if a process (or Windows service) is running
• Gather performance statistics on a server
• Allow specific alerts to only go to particular groups/individuals
• Get reports of downtime on your servers
Nagios Architecture

Config files Windows

Plugin
Daemon
Nagios Server
Linux
Vmplayer and centos

• http://kb.vmware.com/selfservice/micr
osites/search.do?language=en_US&cmd
=displayKC&externalId=2053973
• https://my.vmware.com/web/vmware/f
ree#desktop_end_user_computing/vm
ware_workstation_player/12_0
• http://isoredirect.centos.org/centos/7/
isos/x86_64/CentOS-7-x86_64-DVD-
1503-01.iso
Prerequisites
• Apache (httpd)
• PHP
• GCC compiler (gcc, glibc,glibc-common)
• GD
• Perl
• make

% yum install httpd php gcc glibc* gd gd-devel


Installation…
• 1) Create Account Information
• Become the root user.
• su -l
Create a new nagios user account and give it a password.
• /usr/sbin/useradd -m nagios
passwd nagios
• Create a new nagcmd group . Add both the nagios user
and the apache user to the group.
• /usr/sbin/groupadd nagcmd
• /usr/sbin/usermod -a -G nagcmd nagios
• /usr/sbin/usermod -a -G nagcmd apache
Download Nagios
• http://prdownloads.sourceforge.net/sourceforg
e/nagios/nagios-3.2.3.tar.gz
• https://www.nagios.org/downloads/nagios-plu
gins/#/nagios-plugins-2.1.1.tar.gz

• wget
http://sourceforge.net/projects/nagios/files/na
gios-4.1.1.tar.gz

• wget
http://www.nagios-plugins.org/download/nagi
Compile and install Nagios
• Extract the Nagios source code tarball.
• cd /root/Downloads/nagios/
• tar xvzf nagios-3.2.3.tar.gz
• cd nagios-3.2.3
Run the Nagios configure script, passing the name of the group you created
earlier:
• ./configure --with-command-group=nagcmd
• Compile the Nagios source code.
make all
• Install binaries, init script, sample config files and set permissions on the external
command directory.
make install
make install-init
make install-config
make install-commandmode,
make install-webconf
• Create a nagiosadmin account for logging into the Nagios web interface.
htpasswd -b -c /usr/local/nagios/etc/htpasswd.users nagiosadmin nagiosadmin
• Restart Apache
service httpd restart
Compile and Install the Nagios Plugins
• Extract the Nagios plugins source code tarball.
• cd ~/downloads
• tar xvzf nagios-plugins-2.1.1.tar.gz
• cd nagios-plugins-2.1.1
• Compile and install the plugins.
• ./configure --with-nagios-user=nagios --with-nagios-group=nagios
• make
• make install
• Verify the sample Nagios configuration files.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
• If there are no errors, start Nagios.
– service nagios start
Nagios service start
• Service nagios status
• Nagios Startup script - /etc/rc.d/init.d/nagios
• Verify the nagios config file:

• Service nagios start


• Check the process
• Check the process id in nagios.lock (/usr/local/nagios/var/nagios.lock)
• Check the nagios log (/usr/local/nagios/var/nagios.log)
• Add the nagios and httpd service in chkconfig entry
– chkconfig --add nagios
– chkconfig nagios on
– chkconfig --level 5 nagios off

OR
Systemctl status nagios.service
Systemctl start nagios.service
Directory structure
• /usr/local/nagios/bin – binary files (nagios,nagiosstat)
• /usr/local/nagios/sbin – CGI files ( ex:tac.cgi)
• /usr/local/nagios/libexec – (plugins ex:check_ping)
• /usr/local/nagios/share – ( PHP files )
• /usr/local/nagios/etc – ( configuration files )
• /usr/local/nagios/var – ( logs, lock)
Configuration files
• Configuration done in text files, based on templates.
• Nagios reads its configuration from a directory. You determine
how to divide your configuration files.
• Uses parallel checking and forking for scalability

• Heart of the Nagios


– /usr/local/nagios/etc/nagios.cfg
• Supporting files (/usr/local/nagios/etc/objects)
– templates.cfg
– contacts.cfg
– localhost.cfg
– timeperiods.cfg
– commands.cfg
Notification Options
Host States
==========
• Down (d)
• Unreachable (u)
• Recovery (r)
• None (n)

Service States
============
• Warning (w)
• Unknown (u)
• Critical (c)
• Recovery (r)
How checks work
• A node/host/device consists of one or more service checks (PING, HTTP, MYSQL,
SSH, etc.)
• Periodically Nagios checks each service for each node and determines if state has
changed. State changes are:
- CRITICAL
- WARNING
- UNKNOWN
• For each state change you can assign:
- Notification options (as mentioned before)
- Event handler
• Parameters
- Normal checking interval
- Re-check interval
- Maximum number of checks.
- Period for each check
• Node checks only happen when services respond.
- A node can be:
* DOWN
* UNREACHABLE
Plugins
• Plugins are used to verify services and devices:
– Nagios architecture is simple enough that writing new plugins is
fairly easy in the language of your choice
– There are many, many plugins available (thousands)
 http://exchange.nagios.org/

 http://nagiosplugins.org/
User plugins
# check_mem.pl – save this file in libexec dir
# usage : check_mem.pl 10
#!/bin/perl
$CPU=`top -b -n1 | grep "Cpu(s)" | awk '{print \$2 + \$4}'`;
chomp($CPU);
print " CPU : $CPU ";

if ($ARGV[0] < $CPU) {


print "[Warning] \n";
exit 1;
}else{
print "[OK]\n";
exit 0;
}
=======================
define command {
command_name RHEL_6x_check_process
command_line $USER1$/check_by_ssh -H $HOSTADDRESS$ -C \
"/u/nbbuild/scripts/check_process.pl" -l $ARG1$ -E
}
Check using SSH
• Nagios executes the check_by_ssh plugin
• To run a plugin deployed on the remote machine
• Based on asymetric keys to log without typing a password

CLIENT
NAGIOS

sshd (daemon)
Check_by_ssh
ssh connection
NETWORK
check_xyz(plugin)
Priv. key
Pub. key
Passwordless ssh
% ssh-keygen -t rsa
This will generate the public keys
• Copy the entry from “~nagios/.ssh/id_rsa.pub”
• Go to the destination server & paste the entry into
“~nagios/.ssh/authorized_keys”
• Alternatively you can do the below to copy the content
% ssh-copy-id -i /home/nagios/.ssh/id_rsa.pub user@server2.com
Service and hostgroup
define hostgroup {
hostgroup_name demo-group
alias hosts supporting DNS
members server1, server2, server3
}

define service {
hostgroup_name demo-group
service_description dns service
check_command check_name_for_given_dns
max_check_attempts 3
normal_check_interval 5
retry_check_interval 1
check_period 24x7
notificationinterval 180
notification_period 24x7
notification_options w, c , r , f , u
contact_groups administrators
}
Making configuration more simple
• Monitoring the same service on several hosts
– setting the host name attribute of the service as
a comma separated list of host names
– or setting an hostgroup name attribute for the
service
• Defining template-based objects
– Notion of inheritance
– Factorizing many low-interest attributes
– register attribute to define a template
– use attribute to inherite from a template

You might also like