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> You need sudo access and a running Ubuntu 18.04 server.
Install build dependencies. Two apt install commands are needed because the required packages span different groups:
bashsudo apt update && 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 && sudo make install-configsudo make install-webconf && sudo make install-daemoninit
These install the external command directory, sample configuration files, the Apache integration file, and the systemd service unit.
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:
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 && sudo ./configure && sudo make && sudo make install
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.