Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Install and Configure Nagios in CentOS 6.4 / RHEL 6.4  (Read 5698 times)

0 Members and 1 Guest are viewing this topic.

dustin

  • Guest
Install and Configure Nagios in CentOS 6.4 / RHEL 6.4
« on: October 24, 2013, 11:20:02 pm »
Nagios is a monitoring tool under GPL licence. This tool lets you monitor servers, network hardware (switches, routers, ...) and applications.

Install the prerequisites.
[root@server ~]# yum install -y gd gd-devel httpd php gcc glibc glibc-common

By default nagios is not found in CentOS official repository, so add the EPEL repository to install nagios.

[root@server ~]# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
[root@server ~]# rpm -ivh epel-release-6-8.noarch.rpm

Now install nagios

[root@server ~]# yum install -y nagios*

Note: It is worked for me either the SELINUX and Firewall are disabled or enabled. All you need to do is allow the apache port through iptables.

Configure Nagios
Add the admin mail address in the nagios contact file to receive alerts from nagios server.

[root@server ~]# vi /etc/nagios/objects/contacts.cfg

### Line 35 - Edit the mail id ###
email                           root@localhost  ;

Edit the following lines in nagios config file

[root@server ~]# vi /etc/httpd/conf.d/nagios.conf

## Comment Lines 15 & 16 ##
#   Order allow,deny
#   Allow from all

## Uncomment and Change lines 17,18 & 19 as shown below ##
Order deny,allow
Deny from all
Allow from 127.0.0.1 (provide ip range)

Set nagiosadmin password

[root@server ~]# htpasswd /etc/nagios/passwd nagiosadmin
New password:
Re-type new password:
Updating password for user nagiosadmin

Start nagios and httpd services and let them to start automatically on every boot.

[root@server ~]# /etc/init.d/nagios start
Starting nagios: done.
[root@server ~]# /etc/init.d/httpd start
[root@server ~]# chkconfig nagios on
[root@server ~]# chkconfig httpd on

To allow nagios server through firewall, add the following two lines in iptables config file. This will let you to access the nagios webconsole from all clients.

[root@server ~]# vi /etc/sysconfig/iptables
 -A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
 -A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT

Restart iptables

[root@server ~]# service iptables restart

Open nagios administrator console and enter the nagiosadmin password as created before.

Click on the “Hosts” section in the left pane of the console. You will see the no of hosts to be monitored by Nagios server.

----
Adding clients to Nagios server
----

Add the EPEL repository to install “nagios-plugins” and “nrpe” packages in client systems.

[root@client ~]# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
[root@client ~]# rpm -ivh epel-release-6-8.noarch.rpm

Install “nrpe” and “nagios-plugins” packages in client systems to be monitored.

[root@client ~]# yum install -y nrpe nagios-plugins-all openssl

Configure Clients

[root@client ~]# vi /etc/nagios/nrpe.cfg
 ## Line 81 - Add the Nagios server IP ##
allowed_hosts=127.0.0.1 x.x.x.x(server Ip)

Start nrpe service

[root@client ~]# /etc/init.d/nrpe start
[root@client ~]# chkconfig nrpe on

To add the clients to be monitored through nagios server, open the “nagios.cfg” file in nagios server and uncomment the following lines.

[root@server ~]# vi /etc/nagios/nagios.cfg
## Line 52 - Uncomment ##
cfg_dir=/etc/nagios/servers

Create a directory called “servers” under “/etc/nagios/”.

[root@server ~]# mkdir /etc/nagios/servers

Create config file to the client to be monitored.

[root@server ~]# vi /etc/nagios/servers/clients.cfg
define host{

use                             linux-server

host_name                       client

alias                           client

address                         x.x.x.x(client ip)

max_check_attempts              5

check_period                    24x7

notification_interval           30

notification_period             24x7

}

Restart nagios service.

[root@server ~]# /etc/init.d/nagios restart