How to install Nagios on CentOS 6

Nagios is a powerful monitoring system that monitors your servers and/or services and alerts staff if a problem should arise. The system is plugable which gives administrators the ability to write their own or use hundreds of pre written plugins to monitor their infrastructure.

Installation

Install required packages

yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum -y install nagios nagios-plugins-all

Create blank index.html

If you do not do this you will get a warning from nagios when it checks itself to make sure apache is running.

touch /var/www/html/index.html

Set services to start on boot

chkconfig httpd on
chkconfig nagios on

Change nagiosadmin password

By default the web interface is password protected, the default user is nagiosadmin so we'll change this users password. You can change this username too but it requires you to modify the nagios configuration files to match.

htpasswd -c /etc/nagios/passwd nagiosadmin

Change default contact address

By default alerts will be sent to nagios@localhost. You can change this by editing /etc/nagios/objects/contacts.cfg and changing this address

Start Services

service httpd start
service nagios start

Web Interface

You can now open your browser and goto your server's hostname or ip address prefixed with /nagios. You will be prompted for a username and password. The username is nagiosadmin unless you changed it, and the password is what you set above.

Example: http://192.168.1.1/nagios

Monitoring a remote server

We will now create a configuration file to monitor an additional host. We will monitor ICMP and SSH

Create and edit a file in /etc/nagios/conf.d/server1.domain.cfg

define host {
   use                   linux-server
   host_name       server1.domain.com
   alias                 server1.domain.com
   address           10.0.0.1
   }

define service {
   use                           generic-service
   host_name               server1.domain.com
   service_description  PING
   check_command      check_ping!100.0,20%!500.0,60%
   }

define service {
   use                           generic-service
   host_name               server1.domain.com
   service_description  SSH
   check_command      check_ssh
   }

Next you need to reload nagios

service nagios reload