How Do You Install Nagios on RedHat Linux Step-By-Step?

Problem scenario
You have a small AWS server (e.g., t2.micro with 1 GB of RAM) running RedHat Enterprise Linux.  How do you install Nagios on it?  You want thorough directions to install and configure the Nagios monitoring server on RHEL.

As root or a sudoer user, run a script with the following content:

# Written by
​# This script installs Nagios.  There is some interactive portion at the beginning.  
# But it should be easy to install Nagios using the following.
# read in password for nagiosadmin
echo "Ensure you have a security group rule to allow inbound connections over port 80 from the IP address of the desktop that will access Nagios."
echo "********************************"
echo "Next..."
echo "Please enter the email address that will be sent a message when Nagios sends an alert: "
read youremail
echo "********************************"
echo "Next..."
echo "Please enter the password for nagiosadmin.  Remember that this password will sent be over the internet.  It will pass over plaintext if you follow this script.  This script is for educational and/or testing purposes.  It is advisable to use SSL for your Nagios instance (and its authentication).  The nagiosadmin user is an interactive user that logs in via a web browser.
***  Enter any password you want and press enter:"
read -s npass

yum -y update
yum -y install wget build-essential httpd php gcc glibc-common gd make net-snmp openssl-devel xinetd unzip sendmail php-gd 

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagios,nagcmd apache
cd /opt
tar -xzf nagios*.tar.gz
cd nagios-4.3.1

./configure --enable-command-args --with-nagios-user=nagios --with-nagios-group=nagios --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu

make all
make install
make install-commandmode
make install-init
make install-config
make install-webconf
cd /opt
tar -xzf nagios-plugins*.tar.gz
cd nagios-plugins-2.2.1
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make install
service xinetd restart
cd /usr/local/nagios/etc/
cp nagios.cfg nagios.cfg.bak
perl -i -pe 's/.*/cfg_dir=\/usr\/local\/nagios\/etc\/servers/ if $.==51' nagios.cfg
mkdir -p /usr/local/nagios/etc/servers

sed -i -e 's/nagios@localhost/$youremail/g' /usr/local/nagios/etc/objects/contacts.cfg
htpasswd -b -c /usr/local/nagios/etc/htpasswd.users nagiosadmin $npass

systemctl start nagios.service
#systemctl restart httpd.service # we leave this commented out purely as a reference
chkconfig nagios on
systemctl start nagios.service
echo "The error 'Failed to start nagios.service: Unit not found.' may be ignorable."
echo "You should be ready to open a web browser.  Use the external AWS IP address of the server in a URL like this: "
echo "http://x.x.x.x/nagios (where x.x.x.x is the external IP address of the AWS server)"

Leave a comment

Your email address will not be published. Required fields are marked *