Nagios is a popular open-source monitoring tool used for monitoring the infrastructure and ensuring the availability of services. Here’s a step-by-step guide to installing Nagios on Ubuntu Linux:
Note: These instructions are based on a basic setup, and you may need to adjust them based on your specific requirements.
Prerequisites:
- Ubuntu Server: Make sure you have a clean Ubuntu server installed. You can download the latest version from the official Ubuntu website.
- Update System:
sudo apt update
sudo apt upgrade
Install Required Packages
Before we install Nagios, we need to first install a couple of packages that are crucial for the overrall setup
Install Apache
Apache is used in Nagios installation to provide a web interface for monitoring and managing the Nagios system. The web interface allows users to interact with Nagios, view monitoring status, configure hosts and services, and receive alerts.
sudo apt install apache2
Install PHP
PHP is used for the functioning of the Nagios browser-based interface;
sudo apt install php libapache2-mod-php
Install Additional Dependencies
You can also install additional packages using the following command
sudo apt install build-essential unzip openssl libssl-dev wget
Download and Install Nagios Core:
Now to install Nagios, we need to follow the steps below;
Create a Nagios User and Group
In the context of Nagios, the creation of a dedicated user and group is part of the installation process, and it is done to enhance security and control access to the Nagios files and processes
sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -aG nagcmd nagios
sudo usermod -aG nagcmd www-data
Download Nagios Core
You can now download the Nagios core installation files using the following command;
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-<version>.tar.gz
The above command will download a zipped archive file so we need to run the following command to extract it
tar -zxvf nagios-<version>.tar.gz
Navigate to the Nagios Directory
To go to the Nagios directory, use the following command;
cd nagios-<version>
Configure and Compile Nagios
The configuration and compilation of Nagios can be done by the following command;
./configure --with-httpd-conf=/etc/apache2/sites-enabled
make all
Run the Installation of Nagios
You can run the installation of Nagios using these commands;
sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode
Create Nagios Admin User
Create a Nagios Admin user using the following command;
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Install Nagios Plugins:
Nagios plugins are executable scripts or compiled binaries that extend the functionality of Nagios by enabling it to monitor various services, devices, and performance metrics. These plugins are essential components that allow Nagios to check the status of hosts and services, collect performance data, and generate alerts based on predefined criteria.
To download the Nagios plugins, use the following command;
cd ~
wget https://nagios-plugins.org/download/nagios-plugins-<version>.tar.gz
Extract the zipped file using the following command;
tar -zxvf nagios-plugins-<version>.tar.gz
Navigate to the Nagios Plugins Directory:
To go to the Nagios plugins directory, run the following command;
cd nagios-plugins-<version>
Configure and Compile Nagios Plugins
So, to configure and compile the Nagios plugins, you can run the following command;
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
Install Nagios Plugins
Install the Nagios plugins by running the following command;
sudo make install
Configure Apache for Nagios
We need to set up the Apache server by installing the following modules
sudo a2enmod cgi rewrite
You can now restart the Apache server using this command;
sudo systemctl restart apache2
Access Nagios Web Interface:
- Open a web browser and go to
http://<your-server-IP>/nagios
. - Log in with the username
nagiosadmin
and the password you set during the htpasswd command.
Now, you should have Nagios installed and accessible through the web interface. You can start adding hosts, and services, and configuring alerts based on your monitoring requirements.