How to Install Nagios on Ubuntu Server

Introduction

Nagios is an open-source network monitoring and alert system which can keep supervision on your entire IT infrastructure to ensure your systems, applications, and services are running smoothly. It can alert users when there is an issue or potential problems with their infrastructure.

In this tutorial, we will learn how to install Nagios on Ubuntu Server Latest.

Prerequisites

To install Nagios on Ubuntu Server, ensure that the following requirements are installed on your machine:

Step 1: Update Ubuntu Server

Before we start installing Nagios, it is always a good practice to update the Ubuntu Server. Run the below command:

sudo apt-get update
sudo apt-get upgrade

Step 2: Install Required Packages

For Nagios installation, some prerequisites packages are required. Use the below command to install those packages:

sudo apt-get install build-essential libgd2-xpm-dev openssl libssl-dev unzip apache2 php libapache2-mod-php php-gd libgd-dev libapache2-mod-php libperl-dev libssl-dev daemon wget apache2-utils

Step 3: Download Nagios Core

Download Nagios Core from its official website https://www.nagios.org/downloads/nagios-core/. Use the below command to download the latest version:

cd /tmp
curl -L -O https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.6.tar.gz

Extract the downloaded tarball using the below command:

tar xzf nagios-4.4.6.tar.gz

Step 4: Compile Nagios Core From Source

Now start the compilation of Nagios Core from the /tmp/nagios directory.

cd nagios-4.4.6/
./configure --with-httpd-conf=/etc/apache2/sites-enabled
sudo make all

Step 5: Create Nagios User and Group

The below command creates a nagios user and group as per the Nagios requirement:

sudo make install-groups-users
sudo usermod -a -G nagios www-data

Step 6: Install Nagios Core

To install Nagios on Ubuntu Server, execute the below command:

sudo make install

Step 7: Install Nagios Service and Configuration Files

Now, start the installation of Nagios service files using below command:

sudo make install-daemoninit
sudo make install-config
sudo make install-commandmode
sudo make install-webconf

Step 8: Create Apache Configuration for Nagios

To create an Apache configuration for Nagios, execute the below command:

sudo a2enconf nagios
sudo a2enmod cgi

Step 9: Configure Nagios Web Interface

To configure the Nagios web interface, edit /usr/local/nagios/etc/cgi.cfg file and uncomment below lines:

# HTML CGI settings
main_config_file=/usr/local/nagios/etc/nagios.cfg
physical_html_path=/usr/local/nagios/share
url_html_path=/nagios

Also, edit /usr/local/nagios/etc/nagios.cfg file and uncomment the following lines

# Object Config files
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_dir=/usr/local/nagios/etc/servers

Step 10: Set Nagios Admin Password

To set up a Nagios admin password, use the below command:

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

Step 11: Restart the Apache Service

To restart Apache services, execute the below command:

sudo systemctl restart apache2

Step 12: Verify Nagios Installation

After the installation, verify Nagios installation by accessing the Nagios web interface URL. Use [Server-IP-Address]/nagios URL.

Conclusion

In this tutorial, we have learned how to install Nagios on Ubuntu Server Latest. Nagios serves as an important tool for network monitoring and alerts us when problems arise in our infrastructure.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!