Popular Posts

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Saturday, 2 September 2017

Preparing Linux Server for Nagios monitoring tool

In this article we are going to discuss about the best practice to install an Linux server for nagios monitoring tool. As like regular installation will also work but we will face an issue later an while configuring the nagios alerts, integrating with nagvis and pnp4nagios. Preparing Linux Server for Nagios Monitoring tool
Just remember to follow the below steps to prepare an Linux server for nagios monitoring tool.

Preparing Linux server for Nagios monitoring tool

We have consider below steps to make best nagios monitoring tool implementation
  1. Do not install all packages all are not required
  2. Install Linux server with minimal installation
  3. Do remember to install php, perl, shell, basic tools, snmp, httpd, ssh, tar, wget, python and crond
  4. While installing make a separate partition for /usr/ using LVM (As a default installation location if you considered. if you want to change you also do that )
  5. Create all separate partition for Nagios archive Logs
  6. One important thing is to check version compatibility
  7. Use always stable versions to build production servers.

Nagios core Installation in RHEL7 / Centos 7 Step by Step Guide

Nagios Core 4 Installation Step by step guide in RHEL 7 / Centos 7. Nagios Core Installation is simple and easy process but when your doing for the first time you will little bit confused, Installation of Nagios core is plays major role because while installing we have to run configure as nagcmd group or else all the file permissions and configuration files we have to change later.

What is Nagios core..?? How to do Nagios Core Installation

Nagios core is an most popular and enterprise open source monitoring tool. Using this monitoring tool you can monitor any device in this world even UPS / Battery status. This tool will support almost all the scripting languages.
Prepare your Linux server to install Nagios monitoring tool
Nagios Version:  4.1.1

Prerequisites:

  • Nagios code is written in C language so you required an gcc++ compiler packages to compile and install Nagios.
  • Required wget package to download the nagios tool directly from web to server
  • To untar  the package required Rar / Zip RPM’s
  • Web / Apache / Httpd service to host the Nagios
  • Install php and perl packages to run Nagios plugins

Step1:> Installing prerequisites

~]# yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp perl perl-devel openssl
by using above command it will install all the required prerequisites

Step2:> Download the Nagios Core Package from web

~]#wget http://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.1.1/nagios-4.1.1.tar.gz
using above command you can download the NagiosCore 4.1.1 package

Step3:> Create Nagios User and Nagcmd group

~]#useradd nagios                ##Creating Nagios User
~]#groupadd nagcmd               ##Creating Nagcmd Group
~]#usermod -a -G nagcmd nagios   ##Adding nagios user to nagcmd group

Step4:> Untar the Package

~]#tar -xzvf nagios-4.1.1.tar.gz
above command will untar the tar file

Step5:> Compiling Nagios code

cd nagios-4.1.1
./configure --with-command-group=nagcmd
make all                                    ##To Make the package
make install                      ##To install the complied package 
make install-init        ##To install init script in /etc/rc.d/init.d
make install-config                    ##To Generate the config files
make install-commandmode        ##To install the command mode enable
make install-webconf                ##To Generate the Web config file
using all above commands in sequence will installation  nagios

Step6:> Copy the Event handler directory and change its ownership

~]#cp -rvf contrib/eventhandlers/ /usr/local/nagios/libexec/
Change ownership of copied directory using below command
~]#chown -R nagios:nagcmd /usr/local/nagios/libexec/eventhandlers

Step7:> Create nagiosadmin user and Generate the password to Web Login

create nagiosadmin user and generate password of nagiosadmin using htpasswd command. nagiosadmin we will use to login the web console.
~]#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Step8:> Start the httpd and nagios services

use below given command to start the httpd and nagios services
~]#systemctl start httpd.service 
~]#systemctl start nagios.service
Check the services status
~]#systemctl status httpd.service 
~]#systemctl status nagios.service

Step9:> Allow 80 port to access the Nagios using remote machine

in RHEL7 / Centos 7 instead of iptables firewalld is introduced use firewalld to allow 80 port
~]#firewall-cmd --zone=public --add-port=80/tcp -permanent 
~]#firewall-cmd --reload

Step10:> Access the Nagios using web browser

open the browser and type http://IPADDRESS/nagios
Nagios credentials - Tech tutorials
nagios screen - Tech Tutorials
in above screen you can able to see the Nagios dashboard is showing errors, because we did not yet installed the nagios plugins. After Nagios Core Installation We must install plugins are else we will get above error.
Lets install nagios plugins..!!

Install Nagios plugins on Nagios Server

Nagios plugins will play main role to monitor the service. Its very easy to install the nagios plugins.
nagios plugins are locate yet /usr/local/nagios/libexec/
Download the plugins bundle
~]# wget http://www.nagios-plugins.org/download/nagios-2.0.3.tar.gz
extract the package
~]# tar -xzvf nagios-plugins-2.0.3.tar.gz
Change to directory to install plugins
cd nagios-plugins-2.0.3 
./configure --with-nagios-user=nagios --with-nagios-group=nagcmd 
make 
make install
After installing an nagios plugins just wait for five minutes and open the nagios web console and see.
Nagios Webconsole - Tech Tutorials
That’s it…!! your Nagios Core monitoring tool is installed successfully. Nagios Core Installation is Successfully Now you can Monitor Servers / Devices using Nagios Core.
Please provide your valuable comments..!!
referred from ARKIT.CO.IN

Linux Server Monitoring using SNMP (Simple Network Management Protocol) Nagios

If you would like to monitor servers agent less ultimately the best solution is SNMP (Simple Network Management Protocol). Agent less server monitoring using Nagios. In this Article we are going to see how to Linux server Monitoring Using SNMP Nagios.
Why you would like to go with an Agent less monitoring? because when your server is already in production but you don’t want to modify / Install extra packages in them. In this case simple method is enabling SNMP in client which send traps to Nagios server.

Linux Server Monitoring Using SNMP Nagios

Open SNMP communication from Linux client and monitor using Nagios. Let’s see what are steps we have to follow in order to configure.
Complete Step by step guide for SNMP Installation and configuration
[root@Arkit-Serv~]# vi /etc/snmp/snmpd.conf

rocommunity commstring NAGIOS-SERVER-IP

:wq
Just check from Nagios server that SNMP is responding properly, if you get output like below then its working fine.
./check_snmp -H 192.168.1.23 -o .1.3.6.1.2.1.1.3.0 -C commstring
SNMP OK - Timeticks: (60558317) 7 days, 0:13:03.17 |

Define Commands

define command {
 command_name check_service_snmp
 command_line $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$
}
Now Define your Host and Service Definitions
###############################################################
# #
# ::: Host Defination ::: #
###############################################################

define host {
 host_name LinuxServer.arkit.co.in
 use generic_host
 address 192.168.1.2
 hostgroups linux-servers
 max_check_attempts 5
 check_interval 5
 retry_interval 1
 check_period 24x7
 contacts Linuxadmin
 contact_groups LinuxGroup
 notification_interval 0
 notification_period 24x7
 notifications_enabled 1
 }

###############################################################
# #
# ::: Service Defination ::: #
###############################################################
define service {
 host_name LinuxServer.arkit.co.in
 service_description / Disk Usage
 use Linuxsnmp_storage
 check_command check_service_snmp! -C commstring --v2c -m "^/$" -w 90 -c 95 -f
 max_check_attempts 5
 check_interval 10
 retry_interval 1
 check_period 24x7
 notification_interval 0
 notification_period 24x7
 contacts Linuxadmin
 contact_groups LinuxGroup
 }

define service {
 host_name LinuxServer.arkit.co.in
 service_description CPU Usage
 use linuxsnmp_load
 check_command check_service_snmp! -C commstring --v2c -w 90 -c 95 -f
 max_check_attempts 5
 check_interval 10
 retry_interval 1
 check_period 24x7
 notification_interval 0
 notification_period 24x7
 contacts Linuxadmin
 contact_groups LinuxGroup

}

define service {
 host_name LinuxServer.arkit.co.in
 service_description Memory Usage
 use Linuxsnmp_storage
 check_command check_service_snmp! -C commstring --v2c -m Physical -w 90 -c 95 -f
 max_check_attempts 5
 check_interval 10
 retry_interval 1
 check_period 24x7
 notification_interval 0
 notification_period 24x7
 contacts Linuxadmin
 contact_groups LinuxGroup

}

define service {
 host_name LinuxServer.arkit.co.in
 service_description Ping
 use genericnetdevice_ping_service
 check_command check-host-alive
 max_check_attempts 5
 check_interval 10
 retry_interval 1
 check_period 24x7
 notification_interval 0
 notification_period 24x7
 notifications_enabled 1
 contacts Linuxadmin
 contact_groups LinuxGroup

}

define service {
 host_name LinuxServer.arkit.co.in
 service_description Swap Usage
 use Linuxsnmp_storage
 check_command check_service_snmp! -C commstring --v2c -m 'Swap' -w 90 -c 95 -f
 max_check_attempts 5
 check_interval 10
 retry_interval 1
 check_period 24x7
 notification_interval 0
 notification_period 24x7
 contacts Linuxadmin
 contact_groups LinuxGroup

}
 That’s it Go and see in your Nagios web console you can see all specified service status.
Nagios Linux
Nagios Linux

Conclusion:

If you have Network latency / Network slowness then you will so many false positive alarms from Monitoring tool. If you use NRPE client which reduce little bit of false positive alerts. Nagios Server resource utilization will go high when you use SNMP. Linux server monitoring using snmp

Saturday, 26 August 2017

Configuring Nagios Server

Step 1: Install Required Dependencies 




We need to install required libraries like gcc, glibc, glibc-common and GD and its development libraries before installing.
[root@tecmint]# yum install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel
-------------- On Fedora 22+ Onwards --------------
[root@tecmint]# dnf install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel
Step 2: Create Nagios User
Create a new nagios user account and set a password.
[root@tecmint]# useradd nagios
[root@tecmint]# passwd nagios
Step 3: Install the Nagios Plugins
Create a directory for installation and all its future downloads.
[root@tecmint]# cd /root/nagios
Now download latest Nagios Plugins 2.1.2 package with wget command.
[root@tecmint nagios~]# wget https://www.nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
Step 4: Extract Nagios Plugins
Run the following tar command to extract the source code tarball.
[root@tecmint nagios~]# tar -xvf nagios-plugins-2.1.2.tar.gz
After, extracting one new folder will appear in that directory.
[root@tecmint nagios ~]# ls -l
total 2640
drwxr-xr-x. 15 root root    4096 Aug  1 21:58 nagios-plugins-2.1.2
-rw-r--r--.  1 root root 2695301 Aug  1 21:58 nagios-plugins-2.1.2.tar.gz
Step 5: Compile and Install Nagios Plugins
Next, compile and install using following commands
[root@tecmint nagios]# cd nagios-plugins-2.1.2
[root@tecmint nagios-plugins-2.1.2]# ./configure 
[root@tecmint nagios-plugins-2.1.2]# make
[root@tecmint nagios-plugins-2.1.2]# make install
Set the permissions on the plugin directory.
[root@tecmint nagios-plugins-2.1.2]# chown nagios.nagios /usr/local/nagios
[root@tecmint nagios-plugins-2.1.2]# chown -R nagios.nagios /usr/local/nagios/libexec
Step 6: Install Xinetd
Most of the systems, its by default installed. If not, install xinetd package using following yum command.
[root@tecmint nagios-plugins-2.1.2]# yum install xinetd
-------------- On Fedora 22+ Onwards --------------
[root@tecmint nagios-plugins-2.1.2]# dnf install xinetd
Step 7: Install NRPE Plugin
Download latest NRPE Plugin 3.0 packages with wget command.
[root@tecmint nagios-plugins-2.1.2]# cd /root/nagios
[root@tecmint nagios]# wget http://liquidtelecom.dl.sourceforge.net/project/nagios/nrpe-3.x/nrpe-3.0.tar.gz
Unpack the NRPE source code tarball.
[root@tecmint nagios]# tar xzf nrpe-3.0.tar.gz
[root@tecmint nrpe-3.0]# cd nrpe-3.0
Compile and install the NRPE addon.
[root@tecmint nrpe-3.0]# ./configure
[root@tecmint nrpe-3.0]# make all
Next, install the NRPE plugin daemon, and sample daemon config file.
[root@tecmint nrpe-3.0]# make install-plugin
[root@tecmint nrpe-3.0]# make install-daemon
[root@tecmint nrpe-3.0]# make install-daemon-config
Install the NRPE daemon under xinetd as a service.
[root@tecmint nrpe-3.0]# make install-xinetd
OR
[root@tecmint nrpe-3.0]# make install-inetd
Now open /etc/xinetd.d/nrpe file and add the localhost and IP address of the Nagios Monitoring Server.
only_from = 127.0.0.1 localhost <nagios_ip_address>
Next, open /etc/services file add the following entry for the NRPE daemon at the bottom of the file.
nrpe            5666/tcp                 NRPE
Restart the xinetd service.
[root@tecmint]# service xinetd restart
Step 8: Verify NRPE Daemon Locally
Run the following command to verify the NRPE daemon working correctly under xinetd.
[root@tecmint]# netstat -at | grep nrpe
tcp        0      0 *:nrpe                      *:*                         LISTEN
If you get output similar to above, means it working correctly. If not, make sure to check the following things.
  1. Check you’ve added nrpe entry correctly in /etc/services file
  2. The only_from contains an entry for “nagios_ip_address” in the /etc/xinetd.d/nrpe file.
  3. The xinetd is installed and started.
  4. Check for the errors in the system log files for about xinetd or nrpe and fix those problems.
Next, verify the NRPE daemon is functioning properly. Run the “check_nrpe” command that was installed earlier for testing purposes.
[root@tecmint]# /usr/local/nagios/libexec/check_nrpe -H localhost
You will get a following string on the screen, it shows you what version of NRPE is installed:
NRPE v3.0
Step 9: Configure Firewall Rules
Make sure that the Firewall on the local machine will allow the NRPE daemon to be accessed from remote servers. To do this, run the following iptables command.
-------------- On RHEL/CentOS 6/5 and Fedora --------------
[root@tecmint]# iptables -A INPUT -p tcp -m tcp --dport 5666 -j ACCEPT
-------------- On RHEL/CentOS 7 and Fedora 19 Onwards --------------
[root@tecmint]# firewall-cmd --permanent --zone=public --add-port=5666/tcp
Run the following command to Save the new iptables rule so it will survive at system reboots.
-------------- On RHEL/CentOS 6/5 and Fedora --------------
[root@tecmint]# service iptables save
Step 10: Customize NRPE commands
The default NRPE configuration file that got installed has several command definitions that will be used to monitor this machine. The sample configuration file located at.
[root@tecmint]# vi /usr/local/nagios/etc/nrpe.cfg
The following are the default command definitions that are located at the bottom of the configuration file. For the time being, we assume you are using these commands. You can check them by using the following commands.
# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_users
USERS OK - 1 users currently logged in |users=1;5;10;0
# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_load
OK - load average: 3.90, 4.37, 3.94|load1=3.900;15.000;30.000;0; load5=4.370;10.000;25.000;0; load15=3.940;5.000;20.000;0;
# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_hda1
DISK OK - free space: /boot 154 MB (84% inode=99%);| /boot=29MB;154;173;0;193
# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_total_procs
PROCS CRITICAL: 297 processes
# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_zombie_procs
PROCS OK: 0 processes with STATE = Z
You can edit and add new command definitions by editing the NRPE config file. Finally, you’ve successfully installed and configured NRPE agent on the Remote Linux Host. Now it’s time to install a NRPE component and add some services on your Nagios Monitoring Server

On Nagios Monitoring Server

Now login into your Nagios Monitoring Server. Here you will need to do following things:
  1. Install the check_nrpe plugin.
  2. Create a Nagios command definition using the check_nrpe plugin.
  3. Create Nagios host and add service definitions for monitoring the remote Linux host.
Step 1: Install NRPE Plugin
Go to the nagios download directory and download latest NRPE Plugin with wget command.
[root@tecmint]# cd /root/nagios
[root@tecmint]# wget http://liquidtelecom.dl.sourceforge.net/project/nagios/nrpe-3.x/nrpe-3.0.tar.gz
Unpack the NRPE source code tarball.
[root@tecmint]# tar xzf nrpe-3.0.tar.gz
[root@tecmint]# cd nrpe-3.0
Compile and install the NRPE addon.
[root@tecmint]# ./configure
[root@tecmint]# make all
[root@tecmint]# make install-daemon
Step 2: Verify NRPE Daemon Remotely
Make sure that the check_nrpe plugin can communicate with the NRPE daemon on the remote Linux host. Add the IP address in the command below with the IP address of your Remote Linux host.
[root@tecmint]# /usr/local/nagios/libexec/check_nrpe -H <remote_linux_ip_address>
You will get a string back that shows you what version of NRPE is installed on the remote host, like this:
NRPE v3.0
If your receive a plugin time-out error, then check the following things.
  1. Make sure your firewall isn’t blocking the communication between the remote host and the monitoring host.
  2. Make sure that the NRPE daemon is installed correctly under xinetd.
  3. Make sure that the remote Linux host firewall rules blocking the monitoring server from communicating to the NRPE daemon.

Adding Remote Linux Host to Nagios Monitoring Server

To add a remote host you need to create a two new files “hosts.cfg” and “services.cfg” under “/usr/local/nagios/etc/” location.
[root@tecmint]# cd /usr/local/nagios/etc/
[root@tecmint]# touch hosts.cfg
[root@tecmint]# touch services.cfg
Now add these two files to main Nagios configuration file. Open nagios.cfg file with any editor.
[root@tecmint]# vi /usr/local/nagios/etc/nagios.cfg
Now add the two newly created files as shown below.
# You can specify individual object config files as shown below:
cfg_file=/usr/local/nagios/etc/hosts.cfg
cfg_file=/usr/local/nagios/etc/services.cfg
Now open hosts.cfg file and add the default host template name and define remote hosts as shown below. Make sure to replace host_namealias and address with your remote host server details.
[root@tecmint]# vi /usr/local/nagios/etc/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                       tecmint          ; The name we're giving to this server
alias                           CentOS 6                ; A longer name for the server
address                         5.175.142.66            ; IP address of Remote Linux host
}
Next open services.cfg file add the following services to be monitored.
[root@tecmint]# vi /usr/local/nagios/etc/services.cfg
define service{
use                     generic-service
host_name               tecmint
service_description     CPU Load
check_command           check_nrpe!check_load
}
define service{
use                     generic-service
host_name               tecmint
service_description     Total Processes
check_command           check_nrpe!check_total_procs
}
define service{
use                     generic-service
host_name               tecmint
service_description     Current Users
check_command           check_nrpe!check_users
}
define service{
use                     generic-service
host_name               tecmint
service_description     SSH Monitoring
check_command           check_nrpe!check_ssh
}
define service{
use                     generic-service
host_name               tecmint
service_description     FTP Monitoring
check_command           check_nrpe!check_ftp
}
Now NRPE command definition needs to be created in commands.cfg file.
[root@tecmint]# vi /usr/local/nagios/etc/objects/commands.cfg
Add the following NRPE command definition at the bottom of the file.
###############################################################################
# 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$
}
Finally, verify Nagios Configuration files for any errors.
[root@tecmint]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors:   0
Restart Nagios:
[root@tecmint]# service nagios restart
That’s it. Now go to Nagios Monitoring Web interface at “http://Your-server-IP-address/nagios” or “http://FQDN/nagios” and Provide the username “nagiosadmin” and password. Check that the Remote Linux Host was added and is being monitored.
Nagios Remote Host Monitoring
Nagios Remote Host Monitoring