In this tutorial we will show you how to install Nagios on Ubuntu 20.04 LTS. For those of you who didn’t know, Nagios is an open source monitoring tool used to monitor different Linux Machines or different client hosts. It monitors the HTTP, FTP, SSH, SMTP etc along-with the CPU usage, RAM, Disk Usage and different process that are being running.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Nagios on a Ubuntu 20.04 (Focal Fossa) server.
Install Nagios on Ubuntu 20.04 LTS Focal Fossa
Step 1. First make sure that all your system packages are up-to-date by running these following apt commands in the terminal.
sudo apt update sudo apt upgrade sudo apt install build-essential apache2 php openssl perl make php-gd libgd-dev libapache2-mod-php libperl-dev libssl-dev daemon wget apache2-utils unzip
Step 2. Create users and Groups.
Add the user to the Apache web server group:
sudo useradd nagios sudo groupadd nagcmd sudo usermod -a -G nagcmd nagios sudo usermod -a -G nagcmd www-data
Step 3. Installing Nagios on Ubuntu 20.04.
Now, download the Nagios from official page or you can get it by the below command through terminal:
cd /tmp wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.5.tar.gz tar -zxvf /tmp/nagios-4.4.5.tar.gz cd /tmp/nagios-4.4.5/
Then, Compile the Nagios from the source code:
sudo ./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-httpd_conf=/etc/apache2/sites-enabled/ sudo make all sudo make install sudo make install-init sudo make install-config sudo make install-commandmode
Step 4. Configure Nagios.
Nagios places configuration files in the /usr/local/nagios/
etc directory. Now, with the help of your favorite editor edit the file:
sudo nano /usr/local/nagios/etc/objects/contacts.cfg
Change the email address field to receive the notification:
define contact{ contact_name nagiosadmin ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) alias Nagios Admin ; Full name of user email admin@idroot.us ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** }
Step 5. Installing Nagios Web Interface.
Install the Nagios web interface using the below command:
sudo make install-webconf
Then create a user account as “nagiosadmin” for accessing the Nagios web interface. Make sure to save the password you provided on safe place or keep in mind as it will be needed later:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
After it run the below command:
sudo a2enmod cgi
Next, Restart Apache for the changes to take effect:
sudo systemctl restart apache2
Step 6. Installing Nagios Plugin.
Next steps, Download latest nagios-plugins source and install using following commands:
cd /tmp wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz tar -zxvf /tmp/nagios-plugins-2.3.3.tar.gz cd /tmp/nagios-plugins-2.3.3/
Compile and install the plugins:
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios sudo make sudo make install
Step 7. Starting Nagios on Ubuntu 20.04.
Double check the configuration done above by hitting the given command and make sure all configuration pre-checks are okay:
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Output: Nagios Core 4.4.5 Copyright (c) 2009-present Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 2019-08-20 License: GPL Website: https://www.nagios.org Reading configuration data... Read main config file okay... Read object config files okay... Running pre-flight check on configuration data... Checking objects... Checked 8 services. Checked 1 hosts. Checked 1 host groups. Checked 0 service groups. Checked 1 contacts. Checked 1 contact groups. Checked 24 commands. Checked 5 time periods. Checked 0 host escalations. Checked 0 service escalations. Checking for circular paths... Checked 1 hosts Checked 0 service dependencies Checked 0 host dependencies Checked 5 timeperiods Checking global event handlers... Checking obsessive compulsive processor commands... Checking misc settings... Total Warnings: 0 Total Errors: 0
Then, enable Nagios service to start automatically at system startup:
sudo systemctl enable nagios sudo systemctl start nagios
Step 8. Accessing Nagios.
Nagios will be available on HTTP port 80 by default. Open your favorite browser and navigate to http://your-domain.com/nagios
or http://your-server-ip/nagios
and complete the required the steps to finish the installation. When prompted for username and password you will introduce the username “nagiosadmin” and the password that you entered in step 5.
Congratulation’s! You have successfully installed Nagios. Thanks for using this tutorial for installting Nagios monitoring tool in Ubuntu 20.04 LTS (Focal Fossa) systems. For additional help or useful information, we recommend you to check the official Nagios website.