Nagios Monitoring Server Setup
Nagios Core
Server Configuration
Nagios Core Installation
# Dependancies
yum install -y gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix
yum install openssl-devel
#Download Nagios core
## Check github https://github.com/NagiosEnterprises/nagioscore/releases
## Check SourceForge.net as well
wget -o nagiosCore.tar.gz https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.5.2/nagios-4.5.2.tar.gz
# Extract and compile
tar xzf nagiosCore.tar.gz
cd nagios-4.5.2 #
./configure --with-command-group=nagcmd
# Run these commands sequentually
make all
make install-groups-users
## Binaries
make install
make install-init
make install-config // Sample files to get started with clients
make install-daemoninit
systemctl enable httpd.service
make install-commandmode
make install-config
#Apache Config Files
make install-webconf
#Firewall Config
firewall-cmd --zone=public --add-port=80/tcp
firewall-cmd --zone=public --add-port=80/tcp --permanent
# Create user account (admin)
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# Start and Test
## Apache Webserver Start -> Runs the webapp
systemctl start httpd.service
## Nagios Service
systemctl start nagios.service
Nagios Plugins
The plugins are open sourced scripts written to monitor certain services. There are over thousands of plugins that can be found in the Nagios Exchange Website, and we can also define our own plugins as well if we need to.
#Dependencies
yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils epel-release
yum --enablerepo=powertools,epel install perl-Net-SNMP
# Download and Compile
cd tmp
wget --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/releases/download/release-2.4.9/nagios-plugins-2.4.9.tar.gz
tar zxf nagios-plugins.tar.g
cd /tmp/nagios-plugins.tar.g/
./tools/setup
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
# Configuration verification
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# Start Server
## Apache Webserver Start -> Runs the webapp
systemctl enable httpd.service
systemctl start httpd.service
## Nagios Service
systemctl enable nagios.service
systemctl start nagios.service
NRPE
NRPE installation and client remote configurations will be discussed later. NRPE should be installed prior to host configurations. Therefore, read the official documentations until the content are added.
Refer Official Documentations: NRPE Installation Docs
# Remote Host Setup
## Refer Github and download newest nagios plugins
wget http://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
tar xzf nagios-plugins-2.2.1.tar.gz
cd nagios-plugins-2.2.1
./configure
make
make install
## This is unnecessary since we are gonna use groups-user install
useradd nagios
groupadd nagios
usermod -a -G nagios nagios
# Only for some systems
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec
# NRPE Daemon Install
wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-
3.2.1/nrpe-3.2.1.tar.gz
tar xzf nrpe-3.2.1.tar.gz
cd nrpe-nrpe-3.2.1
./configure
makeall
make install-groups-users
make install
make install-config
systemctl enable nrpe.service;systemctl start nrpe.service
# Check id NRPE is working correctly
/usr/local/nagios/libexec/check_nrpe -H localhost
# add Monitoring Host Ip to allow it to communicate with the host
## This is the place to configure InDirect Commands as well. Check the config file
vi /usr/local/nagios/etc/nrpe.cfg
System Checks
Direct Checks
In-Direct Checks
The following method is employed to check public resources or services which might be unreachable for the Monitoring Host(ie. Server). In the following example provided in the documentation the monitoring host requests statistics from the remote host indirectly on the webserver which is unreachable for the monitoring host directly.
Service Check Configurations
Go to “/usr/local/nagios/etc/objects/“, in here you have to create a cfg file to define hosts and services. This can be done either in one or multiple files. Refer to the following example hosts.cfg file.
use linux-server
host_name fedora-client
alias fedora-client
address 10.0.1.20
check_command check_ping!100.0,20%!500.0,60%
check_interval 1
}
define service {
use generic-service
host_name fedora-client
service_description Ping
check_command check_ping!100.0,20%!500.0,60%
check_interval 1
}
define service {
use generic-service
host_name fedora-client
service_description hda1
check_command check_nrpe!check_hda1
check_interval 1
}
define service {
use generic-service
host_name fedora-client
service_description Processes
check_command check_nrpe!check_total_procs
check_interval 1
}
define service {
use generic-service
host_name fedora-client
service_description Zombie_procs
check_command check_nrpe!check_zombie_procs
check_interval 1
}
define service {
use generic-service
host_name fedora-client
service_description CPU
check_command check_nrpe!check_load
check_interval 1
}
define service {
use generic-service
host_name fedora-client
service_description Disk Space
check_command check_nrpe!check_root
check_interval 1
}
In the following file we have used predefined plugin commands found in commands.cfg file of the client to check various system statistics and services. There are multiple such service, check the documentations of individual plugins to get a full understanding. Additionally, any command definitions should be added to commands.cfg of the server (/usr/local/nagios/etc/objects).
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
Once the services and hosts are defined, we have to add the file into the nagios.cfg file of the server.
Enable Service Checks in client(hosts)
Make sure that the service commands are configured in the host as follows. More commands can be added. We will be editing /usr/local/nagios/etc
Comments
Post a Comment