Below we give a brief description of how to install and configure Nagios.
To install Nagios make sure the following are installed and working properly in your machine
* httpd
* php
* gcc
* glibc
* glibc-common
* gd
* gd-devel
* png
* png-devel
* jpeg
* jpeg-devel
* zlib
* zlib-devel
Install Steps
1) Create a new user and group as root
Create a new user nagios.
useradd -m nagios
passwd nagios
Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache
2) Download Nagios and the Nagios Plugins
Download the source code tarballs of both Nagios and the Nagios plugins.
wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.0/nagios-3.2.0.tar.gz/download
wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.14/nagios-plugins-1.4.14.tar.gz/download
3) Compile and Install Nagios
Extract the Nagios source code.
tar xzf nagios-3.2.0.tar.gz
cd nagios-3.2.0
make sure that these libraries are already installed in the system .Otherwise install them using YUM
* gd
* gd-devel
* png
* png-devel
* jpeg
* jpeg-devel
* zlib
* zlib-devel
Run the Nagios configure script, passing the name of the group:
./configure --with-command-group=nagcmd
Compile the Nagios source code.
make all
Install binaries, init script, sample config files and set permissions on the external command directory.
make install
make install-init
make install-config
make install-commandmode
4) Customize Configuration
After installation the default configuration file can be found in the directory /usr/local/nagios/etc/. Also edit your contact information
vi /usr/local/nagios/etc/objects/contacts.cfg
5) Configure the Web Interface
Install the Nagios web config file in the Apache conf.d directory.
make install-webconf
Create a nagiosadmin account for logging into the Nagios web interface.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Restart Apache to make the new settings take effect.
/etc/init.d/httpd restart
6) Compile and Install the Nagios Plugins
Extract the Nagios plugins source code.
tar xzf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
Compile and install the plugins.
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
7) Start Nagios
Add Nagios to the list of system services and have it automatically start when the system boots.
chkconfig --add nagios
chkconfig nagios on
Verify the default Nagios configuration files.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If there are no errors, start Nagios.
service nagios start
8) Modify SELinux Settings
This step is important if the Selinux is not in the Permissive mode it shows error like this
See if SELinux is in Enforcing mode.
getenforce
Put SELinux into Permissive mode.
setenforce 0
To make this change permanent, you’ll have to modify the settings in /etc/selinux/config and reboot.
9) Login to the Web Interface
You should now be able to access the Nagios web interface at the URL below. You’ll be prompted for the username (nagiosadmin) and password(nagios) you specified earlier.
http://localhost/nagios/
10) Add hosts to be monitored
There are object configuration files in which you can define hosts, host groups, contacts, contact groups, services, etc. You can split your object definitions across several config files if you wish, or keep them all in a single config file.
For convinience we created two files hosts.cfg and services.cfg under the directory /usr/local/nagios/etc/objects/ and add the file path to /usr/local/nagios/etc/nagios.cfg as
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
Then create a simple script to add hosts, named add_host_service.sh by adding the following lines.
## script begins here
#!/bin/bash
echo "Enter Host Name"
read name
echo "Enter IP Address of $name"
read ip_add
echo "
define host{
use linux-server
host_name $name
alias $name
address $ip_add
}
" >> /usr/local/nagios/etc/objects/hosts.cfg
echo "
define service {
host_name $name
service_description HTTP
check_command check_http
use generic-service
notification_interval 1
}
define service {
host_name $name
service_description POP
check_command check_pop
use generic-service
notification_interval 1
}
define service {
host_name $name
service_description SMTP
check_command check_smtp!-t 20
use generic-service
notification_interval 1
}
" >> /usr/local/nagios/etc/objects/services.cfg
##script ends here
The above script will monitor three services HTTP, SMTP and POP. To monitor a new service add a new define service entry as shown above.
execute the above script by the command
sh add_host_service.sh
While the execution it will ask for the host name and the IP Address of the host to be added. After execution it will add a new host to nagios. To verify the nagios configuration for errors use the command
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
For the changes to take effect we must restart the nagios as follows.
killall nagios
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
Now you can find the newly added hosts under the link Hosts in Nagios interface.
Happy Monitoring
Mobin
Jr Software Engineer
SparkSupport
&
Jr Software Engineer
SparkSupport