12 - NAGIOS MONITORING

 NAGIOS MONITORING
  • Infrastructure Monitoring
    • Server, Hardware, Port, Router, processor CPU, Memory ......
  • Opensource, continuous monitoring tools
  • Detailed Monitoring ( 1 minute)
  • Extendable Architecture - Plugins
  • VictorOps (Calling on mobile) integrated with Nagios
  • Nagios Web Interface (GUI)
    • Nagios core 

Nagios Process Scheduler
  1. Nagios Executive Plugins  - ( NRPE services )
  2. Plugins check the Status and get Results
  3. Plugins send Results to Nagios to process 

-> Notifies the Admin about the Status processed by Scheduler
-> Remote Resource Servies 
-> Plugins check the status and get results

Nagios Core -> Plugins -> Scheduler  --> GUI

Plugin is compiled executable or scripts in Perl or non-Perl
Office Nagios Plugin -> There are 50 official Nagios plugins
Community plugins -> around 250
Custom plugins -> write your own plugins

NRPE - Nagios Remote Plugin Executor
  • NRPE allows you to remotely execute Nagios plugins on other Linux/Unix machines. This allows you to monitor remote machine 
  • Install on Server and Nodes
Nagios Remote Data Processor - NRDP
NSClient++ is used to monitor Windows machines
NRPE is used to monitor for Linux/Unix

Nagios Object
  • Services  : services HTTP, POP3, FTP and associate with attributes (CPU load, Disk usage) 
  • Service Groups
  • Hosts : Host is physical server, workstation, devices 
  • Host Groups
  • Contacts : Contact are people involved in the notification process
  • Contact Groups
  • Commands: Used to tell Nagios what programs, script will execute to perform
  • Time Periods: during various days .. like 1 or 5 minutes

Nagios Configuration Files
  • Nagios.cfg - main configurations files
  • services.cfg
  • hosts.cfg
  • contacts.cfg
  • checkcommands.cfg
  • misccommands.cfg
  • timeperiods.cfg

Nagios Service Checks
Service states are: OK , WARNING, CRITICAL, UNKNOWN


NAGIOS LAB 

1 - Nagios
4 GB - RAM
2 - CPU
vagrant ssh
sudo su -
hostnamectl set-hostname nagios.example.com
bash
vi /etc/hosts
192.168.33.20 nagios.example.com

** Install epel
epel = extra package enterprise linux
yum install epel-release -y
** Install nagios and plugins
yum install nagios -y
yum install nagios-plugins*

systemctl enable nagios
systemctl start nagios
** Backup configuration
mv /etc/httpd/conf.d/nagios.conf /etc/httpd/conf.d/nagios.conf.bak
vi /etc/httpd/conf.d/nagios.conf
<VirtualHost *:80>
ServerName nagios.example.com
ServerAdmin support@example.com
ErrorLog logs/nagios.example.com_log
CustomLog logs/nagios.example.com_log common

DocumentRoot /usr/share/nagios/html 
ScriptAlias /nagios/cgi-bin "/usr/lib64/nagios/cgi-bin/"
ScriptAlias /cgi-bin "/usr/lib64/nagios/cgi-bin/"
Alias /nagios "/usr/share/nagios/html"

<Directory "/usr/lib64/nagios/cgi-bin/">
Options +ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /etc/nagios/passwd
Require valid-user
</Directory>

<Directory "/usr/share/nagios">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /etc/nagios/passwd
Require valid-user
</Directory>

</VirtualHost>

** Create Nagios user and permisson
htpasswd /etc/nagios/passwd nagiosadmin 
chown -R apache:apache /usr/share/nagios 
chown -R apache:apache /usr/lib64/nagios 
id apache 
usermod -a -G nagios apache 
systemctl restart nagios 
** check apachectrl verification 
apachectl -t 
apachectl start 
systemctl status nagios 
** create host entry in windows host file entry
windows/system32/etc/drivers/hosts
192.168.33.20 nagios.example.com
** Install Plugins and NRPE services 
** Dependencies install first 

mkdir nagios-download
cd nagios-download

yum install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel 
wget http://www.nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz

ls -ltr
       -rw-r--r--.  1 root root 2728818 Apr 19  2017 nagios-plugins-2.2.1.tar.gz
       -rw-r--r--.  1 root root  518015 Sep  1  2017 nrpe-3.2.1.tar.gz
tar -xvf nagios-plugins-2.2.1.tar.gz
cd nagios-plugins-2.2.1
** compile code
./configure 

** verify compile code 
make 
** insall compile code 
make install
** NRPE Services
cd ..
tar -xvf nrpe-3.2.1.tar.gz
cd nrpe-3.2.1
** Build NRPE service
./configure --enable-ssl 
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios

*** only add user in node server ***
useradd nagios
****************************************
make all 
make install-plugin 
make install-daemon 
make install-config
make install-inetd
make install-init 
systemctl start nrpe
systemctl status nrpe
vi /usr/local/nagios/etc/nrpe.cfg
  modify ip address with nagios server ip
  server_address=192.168.33.20         ## do not update this line in other node
  allowed_hosts=192.168.33.20
   
systemctl restart nrpe
systemctl status nrpe

** How to verify NRPE
/usr/local/nagios/libexec/check_nrpe -H 192.168.33.20 -c check_load ## if host node then put node ip address
*** How to add host for monitor
cd /etc/nagios/
mkdir conf.d
cd conf.d
vi hosts.cfg
## Default Linux Host Template ##
define host{
name                            linux-box               ; Name of this template
use                             generic-host            ; Inherit default values
check_period                    24x7
check_interval                  5
retry_interval                  1
max_check_attempts              10
check_command                   check-host-alive
notification_period             24x7
notification_interval           30
notification_options            d,r
contact_groups                  admins
register                        0                       ; DONT REGISTER THIS - ITS A TEMPLATE
}

## Default
define host{
use                             linux-box               ; Inherit default values from a template
host_name                       unixcloudfusion         ; The name we're giving to this server
alias                           CentOS 7                ; A longer name for the server
address                         192.168.33.20            ; IP address of Remote Linux host
}

vi services.cfg
define service{
use                     generic-service
host_name               unixcloudfusion
service_description     CPU Load
check_command           check_nrpe!check_load
}

define service{
use                     generic-service
host_name               unixcloudfusion
service_description     Total Processes
check_command           check_nrpe!check_total_procs
}

define service{
use                     generic-service
host_name               unixcloudfusion
service_description     Current Users
check_command           check_nrpe!check_users
}

define service{
use                     generic-service
host_name               unixcloudfusion
service_description     SSH Monitoring
check_command           check_nrpe!check_ssh
}

define service{
use                     generic-service
host_name               unixcloudfusion
service_description     FTP Monitoring
check_command           check_nrpe!check_ftp
}
**** Define 
pwd
/etc/nagios/confi.d 
mkdir objects
cd objects
vi commands.cfg

###############################################################################
# NRPE CHECK COMMAND
#
# Command to use NRPE to check remote host systems
###############################################################################

define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
*** add more cfg files in nagios.cfg 
vi ../../nagios.cfg
cfg_file=/etc/nagios/conf.d/hosts.cfg
cfg_file=/etc/nagios/conf.d/services.cfg
cfg_file=/etc/nagios/conf.d/objects/commands.cfg
** check configuration if any error and warning before restart
nagios -v /etc/nagios/nagios.cfg
Total Errors 0
Total Warnings 0
systemctl restart nagios 
system status nagios 
** Go to Nagios GUI
nagios.example.com

2 - Node 1

** Install Plugins and NRPE services 
mkdir nagios-download
cd nagios-download

yum install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel 
wget http://www.nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz

tar -xvf nagios-plugins-2.2.1.tar.gz
        cd nagios-plugins-2.2.1
** compile code
./configure 

** verify compile code 
make 
** insall compile code 
make install
** NRPE Services
cd ..
tar -xvf nrpe-3.2.1.tar.gz
cd nrpe-3.2.1
** Build NRPE service
./configure --enable-ssl 
*** only add user in node server ***
useradd nagios

make all 
make install-plugin 
make install-daemon 
make install-config
make install-inetd
make install-init 
systemctl start nrpe
systemctl enable nrpe
vi /usr/local/nagios/etc/nrpe.cfg
  modify ip address with nagios server ip
  allowed_hosts=192.168.33.70
   
systemctl restart nrpe
systemctl status nrpe

Comments

Popular posts from this blog

05 - Docker - Containers

08 - PUPPET - Configuration Management

06 - Docker Swarm - Container Orchestration