How to Install Nagios on Ubuntu 18.04

Install Nagios on Ubuntu 18.04

In this tutorial we are going to learn how to install Nagios on Ubuntu 18.04. We will also install and configure its prerequisites. Nagios is the most widely used open source monitoring tools which help us to monitor the services and application that run’s on Windows, Linux, Routers and other network devices. The server administrator who uses Nagios gains access to a wide variety of features such as SSH-enabled remote monitoring, network and host traffic monitoring, and a versatile plugin ecosystem.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 18.04 Bionic Beaver minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Nagios on Ubuntu 18.04

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y
apt-get upgrade -y

Step 2. Installing Required Dependencies.

You’all need to install some basic prerequisite packages for Nagios:

sudo apt install build-essential libgd-dev openssl libssl-dev unzip apache2

Step 3. Creating Nagios User and Group.

Create a nagios user and nagcmd group for allowing the external commands to be executed through the web interface, add the nagios and apache user to be a part of nagcmd group:

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www-data

Step 4. Installing Nagios on Ubuntu 18.04.

After installing required dependencies and adding user accounts. Go the the Nagios Core download page, and download the latest stable release of Nagios 4:

cd /tmp

Extract nagios tarball archive you downloaded and use the script inside to install:

tar -zxvf nagios-4.4.1.tar.gz
cd /tmp/nagios-4.4.1/

Compile and Install Nagios:

./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-httpd_conf=/etc/apache2/sites-enabled/
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

Step 4. Configure Nagios.

Edit the contacts.cfg file and to do so open this file using any text editor:

nano /usr/local/nagios/etc/objects/contacts.cfg

Replace email with your own email then save the file and exit from the text editor:

# This contact definition inherits a lot of default values from the 'generic-contact'
# template which is defined elsewhere.
define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user

        email                       ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

We need to setup apache authentication for user nagiosadmin. Do not change this username. else you would required more changes in configuration:

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

Run the following command to enable Apache modules:

sudo a2enmod rewrite
sudo a2enmod cgi

Step 5. Download and Installing Nagios Plugins.

After installing and configuring Nagios core service, Download latest nagios-plugins source and install using following commands:

tar -zxvf /tmp/nagios-plugins-2.2.1.tar.gz
cd /tmp/nagios-plugins-2.2.1/

Compile and install the plugins:

./configure --with-nagios-user=nagios --with-nagios-group=nagios
make install

Verify the sample Nagios configuration files:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Now, start Nagios service and enable Nagios to start automatically at system startup:

systemctl enable nagios
systemctl start nagios

Step 6. Accessing Nagios Web Installation.

Now you can access the Nagios web install wizard in your browser by entering the domain name or http://your_ip/nagios/ to continue your installation. You’ll be prompted for the username (nagiosadmin) and password you specified earlier.

Congratulation’s! You have successfully install and configured Nagios on your Ubuntu 18.04 server. Thanks for using this tutorial installing Nagios on Ubuntu 18.04 LTS (Bionic Beaver) system.