How To Install Nagios Core on Ubuntu & Debian

In this tutorial, we explain all the steps you must follow to know how to install Nagios Core in Ubuntu and Debian.

What is Nagios Core?

Nagios Core is a free open source network monitoring application that every good administrator demands. It is designed to monitor and control network applications, devices, all related services that you may have within a local network.

Step 1: Install LAMP

Before installing Nagios Core from the sources in Ubuntu or Debian, first it will be necessary to install the following LAMP components (Linux, Apache, MySQL, and PHP) in the system, without the MySQL RDBMS database component, executing the following command :

sudo apt install apache2 libapache2-mod-php7.0 php7.0

In the next step, we will install the following system dependencies and the required utilities to compile and install Nagios Core from the sources, executing the following command:

sudo apt install wget unzip zip autoconf gcc libc6 make apache2-utils libgd-dev

Step 2: Install Nagios Core

We currently have version 4.3 of Nagios Core.

As a first step, we will create the nagios system user and group and add the nagios account to the Apache's www-data user, using the following commands:

sudo useradd nagiossudo usermod -a -G nagios www-data

After all the dependencies, packages and system requirements for compiling Nagios from the sources are available in the system, we will go to the Nagios website and obtain the latest version of the stable Nagios Core source file using the following command:

sudo wget

Now, we will extract the Nagios tarball and enter the extracted Nagios directory, with the following commands, we can issue the command ls to list the contents of the Nagios directory:

tar xzf nagios-4.3.4.tar.gz
cd nagios-4.3.4/

Now, we will start to compile Nagios from the sources with the following commands:

Note: We must make sure to configure Nagios with the directory configuration enabled for Apache sites when executing the command.
sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled

In the next step, we will build the Nagios files by executing the following command:

sudo make all

Once this process is finished, we will install the configuration files of Nagios daemon init and the external command mode and, additionally, we must make sure to enable Nagios Daemon in the whole system with the following commands:

sudo make install-init
sudo make install-commandmode
sudo systemctl enable nagios.service

Next, we will execute the following command to install some necessary Nagios sample configuration files for Nagios Core to run correctly:

sudo make install-config

In addition to this, we will install the Nagios configuration file for the Apache web server, which is available in the /etc/apache2/sites-enabled/ directory, by executing the following command:

sudo make install-webconf

Next, we will create a nagiosadmin account and a password for this account, which the Apache server needs to log in to the Nagios web panel using the following command:

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

There we must enter and confirm the password.

Step 3: Configure Apache

To allow the Apache HTTP server to run the Nagios CGI scripts and to access the Nagios administration panel through HTTP, we must first enable the CGI module in Apache and then restart the Apache service, start and activate Nagios daemon in all the operating system with the following commands:

sudo a2enmod cgi
sudo systemctl restart apache2
sudo systemctl start nagios
sudo systemctl enable nagios

Finally, we can log in to the Nagios web interface by directing the browser to the IP address or domain name of the server at the following URL through the HTTP protocol.

We will start a session in Nagios with the user nagiosadmin, and we must assign the configuration of the password configured with the htpasswd script.

We execute any of the following options:


Click on Login, and this will be the environment that we will see:

To see the status of the hosts, we must go to Current Status / Host Groups, where we will see that some errors are shown for the host localhost, this error appears because Nagios does not have installed add-ons to verify the status of the hosts and services.

Step 4: Install Nagios Core Plugins

To compile and install plugins or Nagios plugins from Debian or Ubuntu sources, first, we will install the following dependencies in the system using the following command.

sudo apt install libmcrypt-dev make libssl-dev bc gawk dc build-essential snmp libnet-snmp-perl gettext libldap2-dev smbclient fping libmysqlclient-dev qmail-tools libpqxx3-dev libdbi-dev

Next, we must visit the Nagios Plugins repositories page and download the latest tarball from the source code with the following command:

sudo wget

Now we must extract the tarball from the source code of Nagios Plugins and change the path to the extracted directory of nagios-plugins by executing the following commands:

sudo tar xfz release-2.2.1.tar.gzcd nagios-plugins-release-2.2.1/

Now, we will start the process of compiling and installing Nagios add-ons from the sources, executing the following series of commands in the server console:

sudo ./tools/setup
sudo ./configure
sudo make
sudo make install

Nagios plugins or add-ons compiled and installed can be located in the /usr/local/nagios/libexec/ directory. We must list this directory to see all the add-ons available in the system.

ls /usr/local/nagios/libexec/

Finally, we can restart the Nagios daemon to apply the installed plugins, using the following command:

sudo systemctl restart nagios.service

Next, we can log in again in the Nagios web panel, and we will go to the Current Status / Services path, and we can notice that the Nagios add-ons mark all the services of the hosts.

From the color code, it will be possible to see the status of the current services: the green color is for the OK state, the yellow for Warning and the red for the Critical State.

Step 5: Access through HTTPS

Finally, to access the Nagios administration web interface through the HTTPS protocol, we must execute the following commands to enable the Apache SSL configurations and restart the Apache daemon to reflect the changes:

sudo a2enmod ssl
sudo a2ensite default-ssl.conf
sudo systemctl restart apache2

After allowing the Apache SSL configurations, we proceed to open the file /etc/apache2/sites-enabled/000-default.conf to edit it and add the following block of code after the DocumentRoot declaration:

RewriteEngine onRewriteCond %{HTTPS} offRewriteRule ^(.*) https://%{HTTP_HOST}/$1

We save the changes using the key combination Ctrl + O and exit the editor using the Ctrl + X keys.
Once these changes are made, we execute the following command to restart the service:

sudo systemctl restart apache2.service

In this way, we will access Nagios Core using the secure HTTPS protocol.

Similar Posts

Leave a Reply

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