Contact us

CentOS 5 Nagios Installation

This Nagios installation is based on Nagios installation guide found in CentOS site. These are the steps in that may help. This is just a basic setup please don't expect advance setup. To learn more please read Nagios documentation and for more examples please visit this internal Nagios link. The link is a general example on how to configure some advance feature in Nagios in any system provided that nagios is alread running. Just substitute to your own path.

Create RPM Forge repository

Open a terminal and do the following commands

[mylogin@hostname nagios]# wget http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
[mylogin@hostname folder]# rpm -ivh rpmforge*

Note: you will need to check your Operating Systems Architecture before downloading the rpmforege package. Please check adding yum repository page for additional information.

Check if the repository is enabled. enabled must be equal to 1.

[mylogin@hostname nagios]# vi /etc/yum.repos.d/rpmforge.repo

Tip: Disable all added yum repository if the configuration is done. This will prevent future conflicts with some packages during base upgrade.

Install Nagios (Server Side)

[mylogin@hostname nagios]# yum install nagios nagios-plugins nagios-plugins-nrpe nagios-devel

Install Nagios (Client Side)

[mylogin@hostname nagios]# yum install nagios nagios-plugins nagios-plugins-nrpe nagios-devel nagios-nrpe

Nagios Configuration

Before starting any configuration make it a habit to backup all configuration files. This will save us a lot of time in troubleshooting. Having a backup will also allow us to restore the most recent configuration to the system. We can also make the backup configuration as a future reference in case we need something :)

[mylogin@hostname nagios]# cd /etc
[mylogin@hostname nagios]# cp -frp nagios nagios.backup-<date>
[mylogin@hostname nagios]# vi /etc/nagios/nagios.cfg

Be sure to add the following lines after cfg_file=/etc/nagios/objects/localhost.cfg

cfg_file=/etc/nagios/objects/contactgroups.cfg
cfg_file=/etc/nagios/objects/hostgroups.cfg
cfg_file=/etc/nagios/objects/hosts.cfg
cfg_file=/etc/nagios/objects/services.cfg
cfg_file=/etc/nagios/objects/escalations.cfg

Create Nagios configuration files

[mylogin@hostname nagios]# cd /etc/nagios/objects/
[mylogin@hostname nagios]# touch contactgroups.cfg hostgroups.cfg hosts.cfg services.cfg escalations.cfg
[mylogin@hostname nagios]# chown nagios:nagios contactgroups.cfg hostgroups.cfg hosts.cfg services.cfg escalations.cfg
[mylogin@hostname nagios]# mv localhost.cfg localhost.cfg_orig

Separating the configuration files of Nagios will allow easy administration because the configuration files of Nagios are group according to its functions.

Edit Nagios configuration file

[mylogin@hostname nagios]#vi /etc/nagios/nagios.cfg

comment cfg_file=/etc/nagios/objects/localhost.cfg with '#'

These are the contents of the configuration files:

contacts.cfg

[mylogin@hostname nagios]# vi /etc/nagios/objects/contacts.cfg

# Content of Nagios contacts.cfg

define contact{
contact_name              nagiosadmin
use                             generic-contact 
alias                            Nagios Admin    
email                           admin-email-address
}

define contact{
contact_name                      pals
alias                                    pals
use                                     generic-contact
service_notification_period    24x7
host_notification_period        24x7
service_notification_options   c,r
host_notification_options       d,r
email                                  pals@domain.com
}

define contact{
contact_name                       benjunne
alias                                    benjunne
use                                     generic-contact
service_notification_period    workhours
host_notification_period        workhours
service_notification_options   c,r
host_notification_options       d,r
email                                   benjunne@domain.com
}

contactgroups.cfg

[mylogin@hostname nagios]# vi /etc/nagios/objects/contactgroups.cfg

# Content of contactgroups.cfg

# 'network-group' contact group definitions
define contactgroup{
contactgroup_name       network-group
alias                             network-group
members                      pals,benjunne
}

# 'systems-database-group' contact group definitions
define contactgroup{
contactgroup_name       systems-database-group
alias                             systems-database-group
members                      marlou,debbie
}

# 'technical-group' contact group definitions
define contactgroup{
contactgroup_name       technical-group
alias                             technical-group
members                     dennis,arnel,steve
}

hosts.cfg

[mylogin@hostname nagios]# vi /etc/nagios/objects/hosts.cfg

# Contents of hosts.cfg

define host{
use                      linux-server                                                                         
host_name               localhost
alias                        localhost
address                   127.0.0.1
}

# Production Server
define host{
use                       linux-server
host_name            production-server
alias                     Production Server
address                IP-ADDRESS
check_command   check-host-alive
max_check_attempts  20
notification_interval     240
notification_period      24x7
notification_options    d,u,r
}

# Test Server
define host{
use                        linux-server
host_name             test-server
alias                      Test Server
address                 IP-ADDRESS
check_command    check-host-alive
max_check_attempts  20
notification_interval    240
notification_period      24x7
notification_options     d,u,r
}

hostgroups.cfg

[mylogin@hostname nagios]#vi /etc/nagios/objects/hostgroups.cfg

# Content of hostgroups.cfg still needs additional configuration

define hostgroup{
hostgroup_name   linux-servers          
alias                     Linux Servers                  
members              localhost                
}

services.cfg

[mylogin@hostname nagios]# vi /etc/nagios/objects/services.cfg

# Content of services.cfg
define service{
use                                  local-service
host_name                       localhost
service_description           PING
check_command               check_ping!100.0,20%!500.0,60%
}

define service{
use                                  local-service
host_name                       localhost
service_description           Root Partition
check_command              check_local_disk!20%!10%!/
}

define service{
use                                  local-service
host_name                       localhost
service_description           Current Users
check_command               check_local_users!20!50
}


define service{
use                                  local-service
host_name                       localhost
service_description           Total Processes
check_command               check_local_procs!250!400!RSZDT
}

define service{
use                                  local-service
host_name                       localhost
service_description           Current Load
check_command              check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}


define service{
use                                  local-service
host_name                       localhost
service_description           Swap Usage
check_command              check_local_swap!20!10
}

define service{
use                                  local-service
host_name                       localhost
service_description           SSH
check_command               check_ssh
notifications_enabled         0
}


define service{
use                                  local-service
host_name                       localhost
service_description           HTTP
check_command              check_http
notifications_enabled         0
}

# START PRODUCTION SERVER

define service{
use                                   generic-service
host_name                         production-server
service_description             HTTP
check_command                 check_http!-t 5 -p 8000
notifications_enabled           1
}

define service{
use                                    generic-service
host_name                         production-server
service_description             SSH
check_command                 check_ssh!-t 5 -r "OpenSSH_3.6.1p2" ; version match check
}

escalations.cfg

[mylogin@hostname nagios]# vi /etc/nagios/objects/escalations.cfg

# Content of escalations.cfg
define serviceescalation{
host_name               production-server
service_description     HTTP
first_notification          1
last_notification          0
notification_interval   30
contact_groups          systems-database-group
}

Start Nagios

[mylogin@hostname nagios]# service nagios start
[mylogin@hostname nagios]# service nagios restart
[mylogin@hostname nagios]# service nrpe restart
[mylogin@hostname nagios]# chkconfig nagios on
[mylogin@hostname nagios]# chkconfig nrpe on

Troubleshooting Nagios

Below is a syntax that may help in trobleshooting nagios configuration error. It will produce a verbose output of the error message.

[mylogin@hostname nagios]# nagios -v /etc/nagios/nagios.cfg

Create Nagios user access.

This will ask you for your password. Please remember it. The command will also allow you to reset your password incase you forget.

[mylogin@hostname nagios]# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin

Accessing Nagios

Open your favorite browser and point to Nagios Server

http://<your-nagios-server-domain-or-ip-address>/nagios/

This will propt a password. Please encode the user name nagiosadmin and the password that you entered.

Bookmark and Share RSS News Feed