Home > Cpanel/Linux Internals > Setting up NAGIOS

Setting up NAGIOS

October 6th, 2009

Nagios is a free Web-based monitoring software for Linux. It keeps a tab on your system and network services and sends alerts through e-mail, instant-message and SMS in case of over-use of resources or errors.
You can track about 50 different services, including HTTP, SMTP, NNTP, POP3, PING, processor load and disk usage. The software is a little difficult to configure, but it’s worth the labor.

Installing Nagios:

You need a Linux machine with C Compiler to install Nagios. To use the Web interface, you need a Web server (preferably Apache) and gd library 1.6.3 or higher. To start the installation, download and untar the following two files from the following links:

http://switch.dl.sourceforge.net/sourceforge/nagios/nagios-1.0.tar.gz
http://switch.dl.sourceforge.net/sourceforge/nagiosplug/nagiosplug-1.3-beta1.tar.gz

#tar -zxvf nagios-1.0.tar.gz
#tar -zxvf nagiosplug-1.3.tar.gz

This will create two new directories—nagios-1.0 and nagiosplug-1.3—containing the core installation components and the installer for executable binary commands, respectively. You’ll need to make a separate directory to install Nagios.

The Nagios configuration file also searches for a default Nagios user. So, add one as follows.

#adduser nagios

Set the password by running ‘passwd’ command

Now go to nagios-1.0 and nagiosplug-1.3 directories and issue the following commands in each.

#./configure
#make all
#make install

This will install the Nagios core and the command files. At this moment Nagios doesn’t have any script files from where it can take information about hosts and services. You must, therefore, create the configuration files. The easiest way is to install the sample config files by running the following command from your nagios-1.0 directory.

#make install-config

This will install all the configuration files by the name filename.cfg-sample just edit the file and rename the file to filname.cfg.

The main directories you will find under the nagios directory are :

/bin - Nagios core program
/etc - Main resource and CGI configuration files
/sbin - Various CGI scripts used by Nagios
/share - HTML files ( for web interface and online documentation )
/var - for logging

Adding Hotsts and Host groups :

To add hosts open the file hosts.cfg file

root@svr80 [~]# vi /home/nagios/public_html/etc/hosts.cfg

And add the following to it

define host{
host_name svr76
alias 67.15.94.77
address 67.15.94.77
max_check_attempts 3
event_handler_enabled 0
notification_interval 0
notification_period 24×7
notification_options n
active_checks_enabled 1
passive_checks_enabled 0
check_period 24×7
obsess_over_host 0
check_freshness 0
contact_groups linux-admins
}

You can add multiple hosts in this file.

To add a host to a group, open the hostgroups.cfg file and add the following entries.

root@svr80 [~]# vi /home/nagios/public_html/etc/hostgroups.cfg

define hostgroup{
hostgroup_name Reseller-Servers
alias all Reseller servers
members svr22,svr20,svr18,svr17,svr15,svr14,svr10,svr9,svr7,server5,server-4,svr82,svr80,svr23,svr25,svr26,svr28,svr29,svr31,svr33,svr34,svr37,svr39,svr42,svr45,svr47,svr49,svr51,svr54,svr57,svr59,svr64,svr66,svr69,svr72,svr75,svr78,svr85
}

On our nagios we have two hostgroups one is General-servers and the other is Reseller-Servers.

Adding Services :

You can add the services you want to monitor in services.cfg file

root@svr80 [~]# vi /home/nagios/public_html/etc/services.cfg

define service{
hostgroup_name Reseller-Servers,General - Servers
service_description APACHE
check_command check_http
max_check_attempts 3
normal_check_interval 5
retry_check_interval 2
check_period 24×7
notification_interval 10
notification_period 24×7
notification_options w,u,c
contact_groups linux-admins

}

Here hostgroup_name is the name of the host(s) on which the service will run, service_description is the description of the service and check_command contains the comands located in the /home/nagios/libexec directory.

Alert staff

Next, give the contact information of people who will recive all the alerts. Go to contacts.cfg, and by default you will find an entry for the user nagios as follows.

root@svr80 [~]# vi /home/nagios/public_html/etc/contacts.cfg

define contact {
contact_name nagios
alias Nagios Admin
host_notification_period 24×7
service_notification_period 24×7
host_notification_options d,u,r
service_notification_options w,u,c,r
host_notification_commands host-notify-by-email,host-notify-by-epager
service_notification_commands notify-by-email
email nagios-admin@localhost
}

Configuring web interface.

To configure the web interface just add the following lines to the apache configuration file i.e. httpd.conf file.

<VirtualHost 66.98.220.64>
ServerAlias nagios.4bigravi.com
ServerAdmin webmaster@rsanetworks.net
DocumentRoot /home/nagios/public_html
BytesLog domlogs/monitor.rsanetworks.net-bytes_log
<IfModule mod_php4.c>
php_admin_value open_basedir “/home/nagios/:/usr/lib/php:/usr/local/lib/php:/tmp”
</IfModule>
<IfModule mod_php5.c>
php_admin_value open_basedir “/home/nagios/:/usr/lib/php:/usr/local/lib/php:/tmp”
</IfModule>
ServerName monitor.rsanetworks.net
User nagios
Group nagios
CustomLog domlogs/nagios.ravikumar.in combined
ScriptAlias /cgi-bin/ /home/nagios/public_html/sbin/
</VirtualHost>

Start monitoring

You are now ready to start Nagios. Just restart the Web server and run the following command from /usr/local/nagios/bin directory.

#./nagios /home/nagios/public_html/etc/nagios.cfg

Open Web browser and type the following address.

“http://yourmachine/nagios”

where yourmachine is the name or the IP address of your Nagios server.

Everything on the Web interface is self-evident. Just click on the various menu items on the left to view different kinds of information about the hosts being monitored.

Cpanel/Linux Internals

  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.