How Do You Install Nagios on Ubuntu Step-By-Step?

Problem scenario
You have a small AWS server (e.g., t2.nano with 0.5 GB of RAM) running Ubuntu.  How do you install Nagios on it?

Solution
1. As root or a sudoer user, run a script with the following content (sudo bash /tmp/install.sh):

# Written by continualintegration.com
​#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.  You can do this when the script is running."
echo "********************************"
echo "Next..."
echo "Please enter the email address that will be sent a message when Nagios sends an alert and press Enter: "
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

apt-get update
apt-get -y install wget build-essential apache2 php apache2-mod-php7.0 php-gd libgd-dev sendmail unzip

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagios,nagcmd www-data
cd /opt
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.1.tar.gz
tar -xzf nagios*.tar.gz
cd nagios-4.3.1
./configure --with-nagios-group=nagios --with-command-group=nagcmd
make all
make install
make install-commandmode
make install-init
make install-config
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
cd /opt
wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
tar -xzf nagios-plugins*.tar.gz
cd nagios-plugins-2.2.1
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make
make install
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
a2enmod rewrite
a2enmod cgi
htpasswd -b -c /usr/local/nagios/etc/htpasswd.users nagiosadmin $npass
ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/

#service apache2 restart # we leave this commented out purely as a reference
telinit u # this is plan b
systemctl enable /run/systemd/generator.late/nagios.service
service nagios start
echo 'run sudo service apache2 restart'

2. Verify the installation with this command: sudo /usr/local/nagios/bin/nagios --version

3. Open a web browser, go to this address (where x.x.x.x is either the external IP address or the FQDN of the Nagios server):

http://x.x.x.x/nagios

You will be challenged for credentials via a pop-up. For the username, use "nagiosadmin" with no quotes. For the password, enter the password you entered when it was installing.

Leave a comment

Your email address will not be published.