CentOS: Install Nagios – The Simple Way

Nagios is the most popular open-source infrastructure monitoring tools. Nagios offers monitoring and alerting for servers, switches, applications, and services. It alerts users when things go wrong and alerts them again when the problem has been resolved.

I have created a script to install Nagios and Nagious plugin in RHEL/CentOS:

#!/bin/bash
# Install nagios and nagios plugin in RHEL/CentOS/Fedora
 
# Disable SElinux
sed -i.bak 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
setenforce 0
 
# Nagios requirement
yum install gd gd-devel httpd php gcc glibc glibc-common make openssl openssl-devel -y
 
# Installation directory
installdir=/root/nagios
 
[ ! -d $installdir ] && mkdir -p $installdir
rm -Rf $installdir/*
cd $installdir
 
nagios_latest_url='http://sourceforge.net/projects/nagios/files/latest/download'
nagios_plugin_latest_url='http://sourceforge.net/projects/nagiosplug/files/latest/download'
wget $nagios_latest_url
wget $nagios_plugin_latest_url
 
# Nagios
nagios_package=`ls -1 | grep nagios | grep -v plugin`
tar -xzf $nagios_package
cd nagios
 
clear
echo "Installing Nagios.."
useradd nagios
./configure
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
 
clear
echo "Create .htpasswd for nagios"
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
 
cd $installdir
 
# Nagios Plugin
nagios_plugin_package=`ls -1 | grep nagios-plugin`
tar -xzf $nagios_plugin_package
cd nagios-plugin*
 
clear
echo "Installing Nagios Plugin.."
./configure
make
make install
 
clear
echo "Starting Nagios.."
chkconfig nagios on
service nagios start
 
echo "Staring Apache.."
service httpd restart
chkconfig httpd on
 
# Configure IPtables
iptables -I INPUT -m tcp -p tcp --dport 80 -j ACCEPT
service iptables save
 
ip_add=`hostname -I | tr -d ' '`
echo "Installation done.."
echo "Connect using browser http://$ip_add/nagios/"
echo "username: nagiosadmin"
echo "password: (nagios password)"

You can download the script directly here:

$ wget http://blog.secaserver.com/files/nagios-installer.sh

Changethe  script permission and run script:

$ chmod +x nagios-installer.sh
$ ./nagios-installer.sh

Once completed, you can directly open Nagios page using http://<your_ip_address>/nagios and login with username nagiosadmin with same password you enter during the installation. You should see the Nagios page similar to screenshot below:

nagios

 

 

Installation done!