How to Install Nagios on Ubuntu 20.04

Published on

3 min read

Install and Configure Nagios on Ubuntu

Nagios is a popular open-source monitoring system.

Nagios keeps an inventory of your entire IT infrastructure and ensures your networks, servers, applications, services, and processes are up and running. In case of failure or suboptimal performance, Nagios will send notification alerts via various methods.

This article explains how to install Nagios on Ubuntu 20.04.

Installing Nagios on Ubuntu 20.04

Nagios 4 is available in the Ubuntu software repository. Installation is pretty straightforward, just run the following commands as a user with sudo privileges :

sudo apt updatesudo apt install nagios4 nagios-plugins-contrib nagios-nrpe-plugin

The command above will install a bunch of packages, including Nagios Core, Nagios Plugins, and Apache.

The Apache configuration file that ships with Nagios depend on the mod_authz_groupfile and mod_auth_digest modules, which are not enabled by default. mod_authz_groupfile module is used to allow or deny access to authenticated by group membership, and mod_authz_groupfile enables the MD5 digest authentication.

Run the commands below to enable both modules:

sudo a2enmod authz_groupfile auth_digest

The default the Apache configuration allows access to Nagios only from localhost and private IPs. We’ll change the configuration so that only authenticated users can view the interface and issue commands.

Open the configuration file with your text editor:

sudo nano /etc/apache2/conf-enabled/nagios4-cgi.conf

Comment the lines starting with Require ip, “<Files “cmd.cgi”>”, “” and Require all granted and uncomment the line containing Require valid-user, as shown below:

/etc/apache2/conf-enabled/nagios4-cgi.conf
# Require ip	::1/128 fc00::/7 fe80::/10 10.0.0.0/8 127.0.0.0/8 169.254.0.0/16 172.16.0.0/12 192.168.0.0/16
# <Files "cmd.cgi">
	AuthDigestDomain "Nagios4"
	AuthDigestProvider file
	AuthUserFile	"/etc/nagios4/htdigest.users"
	AuthGroupFile	"/etc/group"
	AuthName	"Nagios4"
	AuthType	Digest
	# Require all	granted
	Require	valid-user
# </Files>

The file also includes instructions for configuring different access levels.

Once done restart Apache:

sudo systemctl restart apache2

You can verify that both Apache and Nagios are working properly by checking their status:

sudo systemctl status apache2sudo systemctl status nagios4

Creating User Account

By default, Nagios is configured to grant administrative privileges to a user named “nagiosadmin”. With this user, you can log in to the Nagios web interface and manage your inventory. Use the following htdigest command to create the user:

sudo htdigest -c /etc/nagios4/htdigest.users Nagios4 nagiosadmin

You will be prompted to enter and confirm the user’s password.

New password: 
Re-type new password: 
Adding password for user nagiosadmin

Restart the Apache service for changes to take effect:

sudo systemctl restart apache2

Configuring Firewall

Ubuntu ships with a firewall configuration tool called UFW. If the firewall is enabled on your system, make sure to open the HTTP and HTTPS ports:

sudo ufw allow Apache

Accessing the Nagios Web Interface

To access the Nagios web interface open your favorite browser and type your server’s domain name or public IP address followed by /nagios:

http(s)://your_domain_or_ip_address/nagios4

Enter the nagiosadmin user login credentials, and you will be redirected to the default Nagios home page.

Conclusion

We’ve shown you how installed Nagios on Ubuntu servers.

For more information about how to configure and use Nagios, check their Documentation .

If you hit a problem or have feedback, leave a comment below.