Install and Configure Nagios - CentOS




Nagios is an open source computer system monitoring, network monitoring and infrastructure monitoring software application. Nagios offers monitoring and alerting services for servers, switches, applications, and services. It alerts the users when things go wrong and alerts them a second time when the problem has been resolved.


Here i am installing and configuring Nagios in CentOS 6.4, 64 bit. Depending upon the versions, make changes in the installation steps. Here in this case both the client and servers are CentOS 6.4, 64 bit.


Server Side Configuration


Server IP: 192.168.1.100
Server Hostname: server.arun.com

Install Nagios


[root@nagios-server ~]# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@nagios-server ~]# yum install nagios nagios-plugins

You can find nagios configuration files in /etc/nagios and plugins under /usr/lib64/nagios/plugins/ after the installation.

Configure Nagios


Create 'nagiosadmin' user

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

Now you can access nagios via browser using the following url. You can use 'nagiosadmin' and it's password to login to nagios webpanel.
http://<IP>/nagios


You can find nagios configuration files in /etc/nagios and plugins under /usr/lib64/nagios/plugins/


Change Notification Mail Address

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

.
.
define contact{
        contact_name             nagiosadmin       ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user

        email                           nagios@localhost        ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }
.
.

Add or Edit Commands for Monitoring

**Commands must be defined before use. We can use a command once it is defined in the commands.cfg file. You cannot use any other commands which is not defined here. Here is the commands which is defined in my server.

[root@nagios-server ~]# egrep -v '^#|^$' /etc/nagios/objects/commands.cfg

define command{
 command_name notify-host-by-email
 command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
 }
define command{
 command_name notify-service-by-email
 command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
 }
define command{
        command_name    check-host-alive
        command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
        }
define command{
        command_name    check_local_disk
        command_line    $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
        }
define command{
        command_name    check_local_load
        command_line    $USER1$/check_load -w $ARG1$ -c $ARG2$
        }
define command{
        command_name    check_local_procs
        command_line    $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
        }
define command{
        command_name    check_local_users
        command_line    $USER1$/check_users -w $ARG1$ -c $ARG2$
        }
define command{
 command_name check_local_swap
 command_line $USER1$/check_swap -w $ARG1$ -c $ARG2$
 }
define command{
 command_name check_local_mrtgtraf
 command_line $USER1$/check_mrtgtraf -F $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -e $ARG5$
 }
define command{
        command_name    check_ftp
        command_line    $USER1$/check_ftp -H $HOSTADDRESS$ $ARG1$
        }
define command{
        command_name    check_hpjd
        command_line    $USER1$/check_hpjd -H $HOSTADDRESS$ $ARG1$
        }
define command{
        command_name    check_snmp
        command_line    $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$
        }
define command{
        command_name    check_http
        command_line    $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
        }
define command{
 command_name check_ssh
 command_line $USER1$/check_ssh $ARG1$ $HOSTADDRESS$
 }
define command{
 command_name check_dhcp
 command_line $USER1$/check_dhcp $ARG1$
 }
define command{
        command_name    check_ping
        command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5
        }
define command{
        command_name    check_pop
        command_line    $USER1$/check_pop -H $HOSTADDRESS$ $ARG1$
        }
define command{
        command_name    check_imap
        command_line    $USER1$/check_imap -H $HOSTADDRESS$ $ARG1$
        }
define command{
        command_name    check_smtp
        command_line    $USER1$/check_smtp -H $HOSTADDRESS$ $ARG1$
        }
define command{
 command_name check_tcp
 command_line $USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$
 }
define command{
 command_name check_udp
 command_line $USER1$/check_udp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$
 }
define command{
 command_name check_nt
 command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
 }
define command{
 command_name check_mysql
 command_line $USER1$/check_mysql -H $HOSTADDRESS$
}
define command{
  command_name            check_nrpe
  command_line            $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
define command{
 command_name process-host-perfdata
 command_line /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /var/log/nagios/host-perfdata.out
 }
define command{
 command_name process-service-perfdata
 command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /var/log/nagios/service-perfdata.out
 }


Add New Client's for Monitoring

I am adding all the client's configuration in a new directory, ie, /etc/nagios/servers . I have to add the new directory in the nagios configuration.

[root@nagios-server ~]# echo "cfg_dir=/etc/nagios/servers" >> /etc/nagios/nagios.cfg
Once you have done the above step, all the files with extension .cfg in  /etc/nagios/servers will be loaded with nagios.


Client IP: 192.168.1.101
Client Hostname: client.arun.com

For easy to understand, i am creating the configuration file for 'client.arun.com' as 'client.arun.com.cfg'. Here is a sample configuration template for adding new clients to the nagios server. The following configuration file will monitor FTP, HTTP, POP3, IMAP, SMTP, MYSQL, SSH, PING, Current Load, Current Users, Root Partition, Total Processes, Zombie Processes. You can add new services in this and remove unwanted services.

[root@nagios-server ~]# cat /etc/nagios/servers/client.arun.com.cfg

# First of all client server is to be defined using host defintion.
define host{
  use    linux-server
  host_name  client.arun.com
  alias    client.sudosu.in
  address   192.168.1.101
  max_check_attempts 5
  check_period  24x7
  notification_interval 30
  notification_period 24x7
}

#Once all the host is defined. Then proceed with the monitored services.
define service{
  use    generic-service
  host_name  client.arun.com
  service_description PING
  check_command check_ping!100.0,20%!500.0,60%
}

define service{
  use    generic-service
  host_name  client.arun.com
  service_description HTTP
  check_command check_http
}

define service{
  use    generic-service
  host_name  client.arun.com
  service_description FTP
  check_command check_ftp
}

define service{
  use    generic-service
  host_name  client.arun.com
  service_description SSH
  check_command check_ssh
}

define service{
  use    generic-service
  host_name  client.arun.com
  service_description SMTP
  check_command check_smtp
}

define service{
  use    generic-service
  host_name  client.arun.com
  service_description POP3
  check_command check_pop
}

define service{
  use    generic-service
  host_name  client.arun.com
  service_description IMAP
  check_command check_imap
}

define service{
  use    generic-service
  host_name  client.arun.com
  service_description MYSQL
  check_command check_mysql
}

#nrpe and nagios plugins need not to be installed in the client side for the above services.
#====================================================================
#nrpe and nagios plugins need to install in the client side for the following services.

define service{
      use    generic-service
     host_name  client.arun.com
     service_description Current Users
      check_command check_nrpe!check_users
}
define service{
      use    generic-service
      host_name  client.arun.com
      service_description Current Load
      check_command check_nrpe!check_load
}
define service{
      use    generic-service
      host_name   client.arun.com
      service_description Root Partition
      check_command check_nrpe!check_xvda
}
define service{
      use    generic-service
      host_name  client.arun.com
      service_description Zombie Processes
      check_command check_nrpe!check_zombie_procs
}
define service{
      use    generic-service
      host_name  client.arun.com
      service_description Total Processes
      check_command check_nrpe!check_total_procs
}


Once you have made all the above changes, restart nagios and httpd service.

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


Client Side Configuration

Install nrpe and Nagios Plugins


**You do not want to do anything in the client server if you want to monitor ssh, smtp, pop3, imap, http, ping, mysql services. ie, do not want to install nrpe and nagios-plugins. You can check the status of these service outside the client server without any additional services. One of the example is 'telnet', it help you to check whether a service is listening in the server or not.

**If you want to monitor process, load, disk usage, swap memory, ie, for all the information which is returned inside the client server. you have to configure the client as follows.


[root@nagios-client ~]# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@nagios-client ~]# yum install nrpe nagios-plugins

You can find nrpe configuration files in /etc/nagios and plugins under /usr/lib64/nagios/plugins/ after the installation.

Here is my sample nrpe.cfg file.

[root@nagios-client ~]# egrep -v '^#|^$' /etc/nagios/nrpe.cfg

log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts= 192.168.1.0/24

dont_blame_nrpe=0
allow_bash_command_substitution=0
debug=0
command_timeout=60
connection_timeout=300
command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_xvda]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/xvda1
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200

Once you have made all the above changes, restart nrpe service.
[root@nagios-client ~]# /etc/init.d/nrpe restart

This entry was posted by Arun Ghosh. Bookmark the permalink.