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 in case of over-use of resources or errors.
It also informs when the process improves. 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. We used Red Hat Linux 8.0 and Apache 2.0.40 for it. 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. By default the configuration file looks for a Nagios directory in /usr/local. So, create one as follows.
#mkdir /usr/local/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
Go to /usr/local/nagios/etc directory and you’ll find all the sample configuration files. Rename them by removing the —sample at the end of each as follows.
#mv filename.cfg-sample filename.cfg.
Adding hosts
Nagios is now ready to start monitoring hosts, so you now must add them. To do that, open the hosts.cfg file from /usr/local/nagios/etc directory and add the following to it.
define host{
host_name PCQLabs
alias Labs Server
address 192.168.1.102
check_command check-host-alive
max_check_attempts 10
notification_interval 480
notification_period 24x7
notification_options d,u,r
}
|
Here, host_name is the computer name, alias is the description and address is the ip address of the machine that will be monitored. All the information that’s filled up is from our test setup, so you must replace it with similar information from your setup.
You can add as many hosts as you want and group them according to the way you want to manage them. To add a host to a group, open the hostgroups.cfg file and add the following entries.
define hostgroup{
hostgroup_
name Labsgroup
alias PCQuest
contact_groups linuxadmins
members PCQlabs,member2
}
Here hostgroup_name is the name of the group, alias is the description, members are hosts which are members of this group and contact_groups is the the group of Admins who will receive the alerts.
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.
define contact{
contact_name nagios
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_
options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-by-email,notify-by- epager
host_notification_commands host-notify-by-email email root@localhost.localdomain
}
Besides this, you can modify or create additional users and create and assign different groups to them. To add this contact to a contact group, for instance, go to contactgroups.cfg and add these lines to it.
define contactgroup{
contactgroup_
name pcq-admins
alias PCQuest
Administrators members
nagios, root
}
Configure Web interface
To do this, first create an alias for the CGIs. By default, the Nagios configuration script searches for it in http://yourmachine/nagios/ cgi-bin/ directory. So, just add the following lines in your httpd.conf file.
ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/
AllowOverride AuthConfig
Options ExecCGI
Allow from all
Order allow,deny
Next create an alias for the html files by adding the following lines.
Alias /nagios/ /usr/local/nagios/share/
Options None
AllowOverride AuthConfig
Order allow,deny
Allow from all
Your Web server is also ready now. Next, we’ll set up the alerting mechanism. Open the services.cfg, and you’ll find something like this
define service{
host_name DLSB
service_description PING is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 5 retry_check_interval 1 contact_groups pcq-admins
notification_interval 120
notification_period 24x7
notification_options w,u,c,r check_command check_ping!
100.0,20%! 500. 0,60%
}
Here host_name is the name of the host on which the service will run, service_description is the description of the service and check_command contains the comands located in the /usr/local/nagios/libexec directory.
These commands are used with different switches seperated by a ! mark. You can know more about these commands by running them with -h in the command prompt.
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 ../etc/nagios.cfg
Open your favorite Web browser and type the following address.
“http://yourmachine/nagios/index.html”
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.
Anindya Roy