I found myself needing to install Nagios on Ubuntu Linux. Sadly, most of the guides I was attempting to follow online were somewhat dated and/or lacking. So why not create the walk-through here myself to potentially help others as well?
For the purpose of this guide, I’m assuming you have a blank/clean Ubuntu Linux box. I personally recommend using DigitalOcean for $5/month.
Start by updating the Droplet, and installing the necessary dependencies:
sudo apt-get update sudo apt-get install wget build-essential unzip openssl libssl-dev sudo apt-get install apache2 php libapache2-mod-php php-gd libgd-dev
Next, create the Nagios user. After this command, it will ask for you to create a password.
sudo adduser nagios
Next, we’ll create the Nagios “nagcmd” group, and add our user to it that we created in the previous step. We also want to add the nagios user to the Apache group so we can run and access the front-end Nagios app (when we get to that point).
sudo groupadd nagcmd sudo usermod -a -G nagcmd nagios sudo usermod -a -G nagcmd www-data
As of this writing, Nagios 4.4.3 is the newest version of Nagios Core. Update these values to reflect newer versions.
cd /opt/ wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.3.tar.gz tar xzf nagios-4.4.3.tar.gz
Now we change to the Nagios directory, make, compile, and install.
cd nagios-4.4.3 sudo ./configure --with-command-group=nagcmd sudo make all sudo make install sudo make install-init sudo make install-daemoninit sudo make install-config sudo make install-commandmode sudo make install-exfoliation
Setup event triggers for the web interface.
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/ chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
Now we’ll create the Apache configuration for the Nagios interface.
sudo vi /etc/apache2/conf-available/nagios.conf
Then paste in the following:
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" <Directory "/usr/local/nagios/sbin"> Options ExecCGI AllowOverride None Order allow,deny Allow from all AuthName "Restricted Area" AuthType Basic AuthUserFile /usr/local/nagios/etc/htpasswd.users Require valid-user </Directory> Alias /nagios "/usr/local/nagios/share" <Directory "/usr/local/nagios/share"> Options None AllowOverride None Order allow,deny Allow from all AuthName "Restricted Area" AuthType Basic AuthUserFile /usr/local/nagios/etc/htpasswd.users Require valid-user </Directory>
We then want to create the admin user and set the password for the web interface. Unless you specifically need a different username, stick with nagiosadmin.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Enable a few different Apache configurations, and then restart Apache.
sudo a2enconf nagios sudo a2enmod cgi rewrite sudo service apache2 restart
Install some required Nagios plugins.
cd /opt/ wget http://www.nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz tar xzf nagios-plugins-2.2.1.tar.gz cd nagios-plugins-2.2.1
Make, compile, and install said Nagios plugins.
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl sudo make sudo make install
Once complete, run this command. This is a quick Nagios self-check. It will run through the various files and system checks to ensure that everything is running as it should.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If everything looks good and without error, start Nagios and set it to run automatically after a reboot.
service nagios start sudo systemctl enable nagios
Once completed, be sure to do some cleanup and remove the tarballs that we downloaded earlier.
rm /opt/nagios-4.4.3.tar.gz rm /opt/nagios-plugins-2.2.1.tar.gz
You can then access the Nagios web interface by entering your domain name or IP address, followed by “/nagios/”
http://<your-ip-address-or-domain>/nagios/
After authentication with nagiosadmin and the password we set previously, you should be greeted with this page:
You have made my Life easy with this.. Help. i’ve managed to install Nagios successfully. Please send me information on Open Source Projects. Since i am interested in learning as much on Linux, / Ubuntu
You have made my Life easy with this.. Help. i’ve managed to install Nagios successfully. Please send me information on Open Source Projects. Since i am interested in learning as much on Linux, / Ubuntu
Why not apt install nagios4?