How To

Install Nagios Core on Ubuntu 18.04: Build from Source Guide

Nagios is one of the most widely used open-source infrastructure monitoring systems in the world. It tracks servers, networks, applications, services, and processes, and sends alerts by email or other channels when something fails or performs below threshold.

Ubuntu 18.04 includes Nagios v3 in its default repositories. This guide covers how to install Nagios on Ubuntu 18.04 from source code, specifically Nagios Core 4.4.2. Building from source gives you the latest release, current security patches, and compatibility with the latest Nagios Plugins.

<strong>Prerequisite:</strong>&nbsp;You need sudo access and a running Ubuntu 18.04 server.

Install Nagios on Ubuntu: Compile Nagios Core from Source

Install build dependencies. Two apt install commands are needed because the required packages span different groups:

bashsudo apt update &amp;&amp; sudo apt upgradesudo apt install autoconf gcc libc6 make wget unzip apache2 php libapache2-mod-php7.2 libgd-devsudo apt install libmcrypt-dev libssl-dev bc gawk dc build-essential libnet-snmp-perl gettext

Download and extract the source. The /usr/src/ directory is the conventional location for source code on Linux systems:

bashcd /usr/src/sudo wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.2.tar.gzsudo tar zxf nagios-*.tar.gzcd nagioscore-nagios-*/

Configure and compile. The --with-httpd-conf flag tells the build system where to place the Nagios Apache configuration file:

bashsudo ./configure --with-httpd-conf=/etc/apache2/sites-enabledsudo make all

make all compiles the main Nagios binary and the CGI programs that drive the web interface. After a successful build, run the installation targets:

bashsudo make install-groups-userssudo usermod -a -G nagios www-datasudo make install

make install-groups-users creates the nagios system user and group. Adding www-data to the nagios group allows Apache to write to the Nagios external command pipe. make install places the binaries, CGIs, and HTML files in /usr/local/nagios/.

Run the remaining installation steps in order:

bashsudo make install-commandmode  &amp;&amp; sudo make install-configsudo make install-webconf &amp;&amp; sudo make install-daemoninit

These install the external command directory, sample configuration files, the Apache integration file, and the systemd service unit.

Configure Apache, Create the Admin Account, and Install Nagios Plugins

Enable Apache modules. Nagios uses CGI scripts to render the web interface and .htaccess rules for routing:

bashsudo a2enmod rewritesudo a2enmod cgi

Create the web admin account. The Nagios web interface is protected by HTTP Basic Authentication. Use htpasswd to create the nagiosadmin user:

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

You will be prompted to set and confirm a password. Then restart Apache and open the firewall:

bashsudo systemctl restart apache2sudo ufw allow Apache

Install Nagios Plugins. Nagios Core does not monitor anything by itself. The plugins are the actual check scripts. Out of the box they cover:

  • Host availability: ICMP ping checks to confirm reachability
  • HTTP/HTTPS: response codes, response time, and SSL certificate expiry dates
  • Disk space: warning and critical thresholds for filesystem usage
  • CPU and load: system resource utilization checks
  • TCP/UDP port checks: verify any service on any host is listening

Download and compile the plugins separately:

bashcd /usr/src/sudo wget -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.2.1.tar.gzsudo tar zxf nagios-plugins.tar.gzcd nagios-plugins-release-2.2.1/sudo ./tools/setup &amp;&amp; sudo ./configure &amp;&amp; sudo make &amp;&amp; sudo make install

Start Nagios and Access the Web Interface

Start the Nagios service and check its status:

bashsudo systemctl start nagiossudo systemctl status nagios

The output should show Active: active (running). The service starts automatically at boot because make install-daemoninit registered and enabled the systemd unit during installation.

Open http://your_domain_or_ip/nagios in a browser. Enter the nagiosadmin credentials you created with htpasswd. You land on the Nagios home dashboard showing host and service check results, status maps, and event logs.

To add monitoring targets, edit the configuration files in /usr/local/nagios/etc/ and validate them before restarting:

bashsudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgsudo systemctl restart nagios

Always validate your config before restarting. Nagios will refuse to start if the configuration file contains errors.

Nagios Core 4.4.2 is now installed on Ubuntu 18.04. Start adding hosts, services, and contacts to your configuration files and reload Nagios after each change. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

Install phpMyAdmin on Ubuntu 18.04 with Apache: Setup Guide

phpMyAdmin is a free, open-source PHP application that provides a browser-based interface for managing MySQL and…

35 minutes ago

Install Zabbix on Ubuntu 18.04: Server Setup with MySQL Backend

Zabbix is a mature open-source infrastructure monitoring platform that collects metrics from network devices, servers, virtual…

40 minutes ago

Install Gradle on Ubuntu 18.04: Set Up OpenJDK and Environment

Gradle is a powerful open-source build automation tool used primarily for Java, Kotlin, Groovy, and Android…

45 minutes ago

Install TeamViewer on Ubuntu 18.04: Download the .deb and Set Up

TeamViewer is a proprietary cross-platform remote access application for remote control, desktop sharing, file transfer, and online meetings. It is one of the most widely used remote support tools in the world, available for Windows, macOS, Linux, iOS, and Android. TeamViewer is not included in the Ubuntu repositories because it is proprietary software. This guide covers how to install TeamViewer on Ubuntu 18.04 using the official .deb package. The same steps apply to Ubuntu 16.04, Debian, Linux Mint, and Elementary OS. <strong>Prerequisite:</strong>&nbsp;You&nbsp;need&nbsp;sudo&nbsp;access. Install TeamViewer on Ubuntu: Download the .deb Package Download the official TeamViewer .deb package. The _amd64.deb suffix indicates this package is for 64-bit x86-64 systems. For ARM-based machines, download the appropriate package from the TeamViewer Linux downloads page: bashwget https://download.teamviewer.com/download/linux/teamviewer_amd64.deb Install the package using apt. The ./ prefix tells apt this is a local file path, not a package name from the repositories:…

50 minutes ago

Install Laravel on Ubuntu 18.04 with Composer: Setup Guide

Laravel is an open-source PHP web application framework built around an expressive, developer-friendly syntax. It is…

19 hours ago

Install Kodi on Ubuntu 18.04: Add the Official PPA and Set Up

Kodi (formerly XBMC, short for Xbox Media Center) is a free, open-source, cross-platform media player and…

19 hours ago