Nagios Server
##How to install Nagios server on Centos Machine
##What is Nagios Server?
Nagios® Server Monitoring software is open source software that provides host, service and network monitoring capabilities. Nagios Server Monitoring software monitors disk space usage, CPU usage, memory usage, VPN tunnels, router and switches, databases, and network services. Nagios server monitoring software and other performance management products are used to manage server performance.
-
Installation Process
##What will u end up?
- If you follow these instructions, here’s what you will end up with:
- Nagios and the plugin will be installed in path: /usr/local/nagios
- Nagios will be configured to monitor a few aspects of your local system (CPU load, disk usage, etc.)
- The Nagios web interface will be accessible at http://localhost/nagios/
## Prerequisites
- During portions of the installation you’ll need to have root access to your machine.
- You also need to give it a static IP address.
- Make sure you’ve installed the following packages on your Fedora installation before continuing.
- Apache
- PHP
- GCC compiler
- GD development libraries
1. We can use yum to install these packages by running as Root
[root@monitoring ~]# yum -y install httpd php gcc gclib glibc-common gd gd-devel
2. Create Account for Nagios Server
[root@monitoring ~]# useradd -m nagios
[root@monitoring ~]# passwd nagios
[root@monitoring ~]# usermod -a -G nagcmd nagios
[root@monitoring ~]# usermod -a -G nagcmd apache
3. Create a directory for storing the Nagios and plugin from downloads
[root@monitoring ~]# mkdir downloads/
[root@monitoring ~]# cd downloads/
Download the source code tarballs of both Nagios and the Nagios plugins (visit http://www.nagios.org/download for links to the latest versions). Now I am using these version : nagios-3.2.0 and nagios plugins 1.4.15
4. We need to extract them
[root@monitoring downloads]# tar xvf nagios-3.2.0.tar.gz
[root@monitoring downloads]# cd nagios-3.2.0
5. Start compiling it
[root@monitoring nagios-3.2.0]# ./configure –with-command-group=nagcmd
[root@monitoring nagios-3.2.0]# make install
[root@monitoring nagios-3.2.0]# make install-init
[root@monitoring nagios-3.2.0]# make install-config
[root@monitoring nagios-3.2.0]# make install-commandmode
[root@monitoring nagios-3.2.0]# make install-webconf
6. Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account.
[root@monitoring conf.d]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
7. Restard apache service to make the new setting take effect
[root@monitoring conf.d]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
8. Extract and compile nagios plugin
[root@monitoring downloads]# tar xvf nagios-plugins-1.4.15.tar.gz
[root@monitoring downloads]# cd nagios-plugins-1.4.15
[root@monitoring downloads]# cd nagios-plugins-1.4.15
[root@monitoring nagios-plugins-1.4.15]# ./configure –with-nagios-user=nagios –with-nagios-group=nagios
[root@monitoring nagios-plugins-1.4.15]# make
[root@monitoring nagios-plugins-1.4.15]# make install
9. Add Nagios to the list of system service and have it automatically start when the system boots.
[root@monitoring ~]# chkconfig –add nagios
[root@monitoring ~]# chkconfig nagios on
10. Test service whether it is working or not
[root@monitoring ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Checking global event handlers…
Checking obsessive compulsive processor commands…
Checking misc settings…
Total Warnings: 0
Total Errors: 0
11. Fedora ships with SELinux (Security Enhanced Linux) installed and in Enforcing mode by default. This can result in “Internal Server Error” messages when you attempt to access the Nagios CGIs.
[root@monitoring ~]# vi /etc/selinux/config
# permissive – SELinux prints warnings instead of enforcing.
# disabled – SELinux is fully disabled.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
# targeted – Only targeted network daemons are protected.
# strict – Full SELinux protection.
SELINUXTYPE=targeted
Noted: After changes it you must reboot to make it effect.
12. Instead of disabling SELinux or setting it to permissive mode, you can use the following command to run the CGIs under SELinux enforcing/targeted mode:
[root@monitoring ~]# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
[root@monitoring ~]# chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
13. Start access to nagios server: http://server-ip/nagios
14. How to monitor Linux/Unix machine (NRPE addon)
- Intrudution:
We will show you about how you can monitor “private” services and attributes of Linux server, such as:
– CPU Load
– Memory usage
– Disk usage
– Logged in users
– Running processes ………
- Moreover, we can monitor services that are provided by Linux Servers (HTTP,FTP, SSH, SMTP, etc…..)
- There are several different ways to monitor attributes or remote Linux/Unix servers. One is by
using shared SSH keys and the check_by_ssh plugin to execute plugins on remote servers. This
method will not be covered here, but can result in high load on your monitoring server if you
are monitoring hundreds or thousands of services. The overhead of setting up/destroying SSH connections is the cause of this.
- Another common method of monitoring remote Linux/Unix hosts is to use the NRPE addon.
NRPE allows you to execute plugins on remote Linux/Unix hosts. This is useful if you need to
monitor local resources/attributes like disk usage, CPU load, memory usage, etc. on a remote
host.
15. Installation NRPE on Remote Server:
-
We need create Nagios user account on remote server to monitored
[root@ssh ~]# useradd nagios
[root@ssh ~]# passwd nagios
[root@ssh ~]#
-
Download and install Nagios plugins on this link: www.nagios.org/download/download.php
[root@ssh ~]# mkdir -p /opt/Nagios
[root@ssh ~]# cd /opt/Nagios/
-
We have to extract Files:
[root@ssh Nagios]# tar xvf nagios-plugins-1.4.15.tar.gz
[root@ssh Nagios]# ll
total 2368
drwxrwxrwx 16 test root 4096 Mar 25 07:34 nagios-plugins-1.4.15
-rw-r–r– 1 root root 2095419 Sep 7 2010 nagios-plugins-1.4.15.tar.gz
drwxrwxr-x 6 nagios nagios 4096 Mar 25 07:38 nrpe-2.8
-rw-r–r– 1 root root 293332 Mar 31 2012 nrpe-2.8.tar.gz
[root@ssh Nagios]# cd nagios-plugins-1.4.15
[root@ssh nagios-plugins-1.4.15]#
-
Compile and Congigure Nagios Plugins : We need the openssl-devel, GCC compiler and GD development libraries package installed to compile plugin with ssl support:
[root@ssh nagios-plugins-1.4.15]# yum install openssl-devel gcc glibc glibc-common gd gd-devel
[root@ssh nagios-plugins-1.4.15]#
-
Start to install plugin:
[root@ssh nagios-plugins-1.4.15]# ./configure –with-nagios-user=nagios –with-nagios-group=nagios
[root@ssh nagios-plugins-1.4.15]# make
[root@ssh nagios-plugins-1.4.15]# make install
[root@ssh nagios-plugins-1.4.15]#
-
The permission on the plugin directory and the plugins will need to be changed to nagios user:
[root@ssh nagios-plugins-1.4.15]# chown nagios:nagios /usr/local/nagios/
[root@ssh nagios-plugins-1.4.15]# chown -R nagios:nagios /usr/local/nagios/libexec/
[root@ssh nagios-plugins-1.4.15]
-
Anyway, we need install xinted as well:
[root@ssh nagios-plugins-1.4.15]# yum install xinetd
[root@ssh nagios-plugins-1.4.15]#
- Download nad install NRPE Daemon
- As we already downloaded in this location and start extract:
[root@ssh Nagios]# tar xvf nrpe-2.8.tar.gz
[root@ssh Nagios]# ll
total 2368
drwxrwxrwx 16 test root 4096 Mar 25 07:34 nagios-plugins-1.4.15
-rw-r–r– 1 root root 2095419 Sep 7 2010 nagios-plugins-1.4.15.tar.gz
drwxrwxr-x 6 nagios nagios 4096 Mar 25 07:38 nrpe-2.8
-rw-r–r– 1 root root 293332 Mar 31 2012 nrpe-2.8.tar.gz
[root@ssh Nagios]#
-
Compile and configure NRPE file
[root@ssh Nagios]# cd nrpe-2.8
[root@ssh nrpe-2.8]# ./configure
[root@ssh nrpe-2.8]# make
[root@ssh nrpe-2.8]# make all
[root@ssh nrpe-2.8]# make install-plugin
[root@ssh nrpe-2.8]# make install-daemon
[root@ssh nrpe-2.8]# make install-daemon-config
[root@ssh nrpe-2.8]# make install-xinetd
[root@ssh nrpe-2.8]#
-
Configure NRPE Configuration file:
- We have to add Nagios Monitoring server ip address as below on remote server:
[root@ssh nrpe-2.8]# vim /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg –inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1 192.168.1.173
}
-
Moreover, we need edit service file entry, add entry for nrpe daemon:
[root@ssh nrpe-2.8]# vim /etc/services
chargen 19/tcp ttytst source
chargen 19/udp ttytst source
ftp-data 20/tcp
ftp-data 20/udp
#Service NRPE ###
nrpe 5666/tcp
# 21 is registered to ftp, but also used by fsp
ftp 21/tcp
-
Make xinetd starts at boot and restart it:
[root@ssh nrpe-2.8]# chkconfig xinetd on
[root@ssh nrpe-2.8]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[root@ssh nrpe-2.8]#
-
Test NRPE Daemon Installation: We can check daemon is running and listening on port 5666: Output should be as below:
[root@ssh nrpe-2.8]# netstat -at |grep nrpe
getnameinfo failed
getnameinfo failed
tcp 0 0 *:nrpe *:* LISTEN
[root@ssh nrpe-2.8]#
-
Check NRPE daemon is functioning: Output should be NRPE version
[root@ssh nrpe-2.8]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.8
[root@ssh nrpe-2.8]#
- Open Port 5666 on Firewall
- Make sure to open 5666 on the firewall of the remote server so that the Nagios monitoring server can access the NRPE daemon:
16.Set up Nagios Monitoring Host Server
-
Download and install NRPE Plugin
- We can download link from here: http://www.nagios.org/download
- We can save file to directory on: /download
[root@monitoring downloads]# ll
total 5688
drwxrwxr-x 14 nagios nagios 4096 Aug 28 20:52 nagios-3.2.0
-rw-r–r– 1 root root 3170967 Sep 7 2010 nagios-3.2.0.tar.gz
drwxrwxrwx 16 test root 4096 Aug 28 21:01 nagios-plugins-1.4.15
-rw-r–r– 1 root root 2095419 Sep 7 2010 nagios-plugins-1.4.15.tar.gz
-rw-r–r– 1 root root 293332 Mar 31 16:53 nrpe-2.8.tar.gz
[root@monitoring downloads]#
- After we extract file:
[root@monitoring downloads]# tar xvf nrpe-2.8.tar.gz
[root@monitoring downloads]# cd nrpe-2.8
[root@monitoring nrpe-2.8]#
- Compile and configure NRPE: We need install package: openssl-devel to compile with ssl support:
[root@monitoring nrpe-2.8]# yum install openssl-devel
[root@monitoring nrpe-2.8]# ./configure
[root@monitoring nrpe-2.8]# make all
[root@monitoring nrpe-2.8]# make install-plugin
[root@monitoring nrpe-2.8]#
- Test connection to NRPE daemon on Remote Server: To make sure that the NRPE on our Nagios server can communicate with the NRPE daemon on the remote server we want to monitor. Please follow as below:
[root@monitoring nrpe-2.8]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.172
NRPE v2.8
[root@monitoring nrpe-2.8]#
- Moreover, we cannot communicate with remote server, check your firewall:
[root@monitoring nrpe-2.8]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.172
Connection refused or timed out
[root@monitoring nrpe-2.8]#
- Create NRPE Command Definition:
- The command definition, we need to be created in order for the check_nrpe plugin to be used by nagios Server: You can follow as below:
[root@monitoring nrpe-2.8]# vim /usr/local/nagios/etc/objects/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$
}
-
Start to create new Linux object template:
- To be able to add the remote linux machine to Nagios we need to create object file template and add some object definitions:
- Create new linux-ssh object template file:
[root@monitoring ~]# vim /usr/local/nagios/etc/objects/linux-ssh.cfg
define host{
name linux-ssh ; Name of this template
use linux-ssh ; Inherit default values
check_period 24×7
check_interval 5
retry_interval 1
max_check_attempts 8
check_command check-host-alive
notification_period 24×7
notification_interval 30
contact_groups admins
register 0 ; DONT REGISTER THIS – ITS A TEMPLATE
}
define host{
#use linux-box-remote ; Inherit default values from a template
use linux-ssh ; Inherit default values from a template
host_name Centos ; The name we’re giving to this server
alias Centos ; A longer name for the server
address 192.168.1.172 ; IP address of the server
}
define service{
use generic-service
host_name Centos
service_description CPU Load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name Centos
service_description Current Users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name Centos
service_description Disk /
check_command check_nrpe!check_disk_root
}
define service{
use generic-service
host_name Centos
service_description Disk /home
check_command check_nrpe!check_home
}
define service{
use generic-service
host_name Centos
service_description /
check_command check_nrpe!check_root
define service {
use generic-service
host_name Centos
service_description Check_Procs
check_command check_nrpe!check_zombie_procs
}
define service {
use generic-service
host_name Centos
service_description Check_Total_Procs
check_command check_nrpe!check_total_procs
}
define service{
use generic-service ; Name of service template to use
host_name Centos
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use generic-service ; Name of service template to use
host_name Centos
service_description SSH
check_command check_ssh
notifications_enabled 0
}
define service{
use generic-service ; Name of service template to use
host_name Centos
service_description HTTP
check_command check_http
notifications_enabled 0
}
define service{
use generic-service ; Name of service template to use
host_name Centos
service_description Swap Partition
check_command check_nrpe!check_swap
notifications_enabled 0
}
-
Make sure you active the linux-ssh.cfg template:
[root@monitoring ~]# vim /usr/local/nagios/etc/nagios.cfg
# Definitions for monitoring the local (Linux) host
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/linux-ssh.cfg
-
To check whether the Nagios configuration is working or not:
[root@monitoring ~]# /usr/local/nagios/bin/nagios -v
/usr/local/nagios/etc/nagios.cfg
Checking obsessive compulsive processor commands…
Checking misc settings…
Total Warnings: 0
Total Errors: 0
Things look okay – No serious problems were detected during the pre-flight
Check
-
Restart Nagios Service:
[root@monitoring ~]# service nagios restart
Running configuration check…done.
Stopping nagios: done.
Starting nagios: done.
[root@monitoring ~]#
-
Sometime you will get some error on Nagios like on Disk space as below:
-
Below is step to solve this problem: Go to check on remote server and check your system hard disk architecture.
[root@ssh ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
39G 1.6G 35G 5% /
/dev/hda1 99M 19M 76M 20% /boot
tmpfs 125M 0 125M 0% /dev/shm
[root@ssh ~]#
-
After that, we can go to check and change hard disk name: from “hba1” to “hda1” as below:
[root@ssh ~]# vim /usr/local/nagios/etc/nrpe.cfg
#command[check_disk_root]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hba1
command[check_disk_root]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hda1
- If you follow these instructions, here’s what you will end up with: