How to Install and Configure Nagios 4 on Ubuntu 22.04
Welcome to our guide on installing and configuring Nagios 4 on Ubuntu 22.04. In this tutorial, we will be installing Nagios Core, an open-source system and network monitoring application. Nagios Core monitors specified hosts and services, alerting you when issues arise and when they are resolved.
Implementing Nagios will help your organization identify and address IT infrastructure problems before they impact critical business processes. By proactively monitoring your IT infrastructure, you can ensure that systems, applications, services, and business processes operate smoothly. When a failure occurs, Nagios promptly alerts the technical staff.
Follow the steps in the upcoming sections to set up a Nagios 4 monitoring server on an Ubuntu 22.04, 20.04, or 18.04 Linux machine.
Step 1: Update System
Run the update commands on your Ubuntu system to ensure you’re on the latest release.
apt update && apt upgrade -y
It is recommended to reboot if no service will be impacted.
[ -f /var/run/reboot-required ] && reboot -f
Step 2: Install the required packages
Once the system is upgraded and rebooted. You’ll need to install the packages required to build Nagios Core on Ubuntu Linux.
apt update
apt install wget unzip vim curl openssl build-essential libgd-dev libssl-dev libapache2-mod-php php-gd php apache2
Step 3: Download Nagios Core
Check the releases page for the latest Nagios available.
NAGIOS_VER=$(curl -s https://api.github.com/repos/NagiosEnterprises/nagioscore/releases/latest|grep tag_name|cut -d '"' -f 4)
curl -SL https://github.com/NagiosEnterprises/nagioscore/releases/download/$NAGIOS_VER/$NAGIOS_VER.tar.gz | tar -xzf -
The command will download and extract the Nagios core archive to your current working directory.
Change to the created Nagios folder.
cd $NAGIOS_VER
Step 4: Install Nagios Core on Ubuntu
After extracting the archive, run the configure script:
./configure
Run the make command with all option to compile the main program and CGIs.
make all
Create User And Group:
make install-groups-users
usermod -a -G nagios www-data
Install Nagios Core 4.x on Ubuntu:
make install
Install the init script in /lib/systemd/system,
make install-daemoninit
Install and configure permissions on the directory for holding the external command file:
make install-commandmode
Install sample config files in /usr/local/nagios/etc.
make install-config
Install the Apache config file for the Nagios web interface:
make install-webconf
a2enmod rewrite cgi
systemctl restart apache2
Install the Exfoliation theme for the Nagios web interface.
make install-exfoliation
If you want to use the classic Nagios theme, run:
<make install-classicui>
Step 5: Create Nagios Web user
A user is required for the access to Nagios web console.
$ htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
The htpasswd has been used to generate the password and write it to the /usr/local/nagios/etc/htpasswd.users file.
Step 6: Install Nagios Plugins
Nagios plugins are used to extend Nagios monitoring features. Let’s ensure they are installed. Check for the latest release of Nagios plugins from the Github releases page.
cd ~/
VER=$( curl -s https://api.github.com/repos/nagios-plugins/nagios-plugins/releases/latest|grep tag_name|cut -d '"' -f 4|sed 's/release-//')
curl -SL https://github.com/nagios-plugins/nagios-plugins/releases/download/release-$VER/nagios-plugins-$VER.tar.gz | tar -xzf -
Change to the plugin source directory:
cd nagios-plugins-$VER
Compile and install Nagios plugins by running the commands below.
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
Step 7: Verify installation and Start Nagios service
Confirm that your Nagios installation was successful on the Ubuntu Linux machine.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
You should get an output similar to below if the installation of Nagios was successful.
Start and enable the Nagios service to start at boot.
systemctl enable --now nagios
Confirm that the Nagios service is running.
$ systemctl status nagios
Step 8: Access Nagios Web Dashboard
if you have a ufw firewall, allow http and https ports for inbound traffic.
for i in http https ssh; do sudo ufw allow $i; done
Now use your browser to access the Nagios dashboard on http:[IP/hostname]/nagios/
Input the credentials for the user created earlier.
You should get to the Nagios Administration dashboard.
We hope this guide has assisted you in installing Nagios 4 on Ubuntu 22.04. Next, explore monitoring your IT environment.
For detailed configuration guides, refer to the official Nagios 4 documentation.