How To Install Nagios on Ubuntu 24.04 LTS and also add Remote Host


Chirag's Technology Tutorial
*********************************************************************************
How To Install Nagios on Ubuntu 24.04 LTS and also add Remote Host
*********************************************************************************
Here's a step-by-step guide to install Nagios Core (latest stable version) on Ubuntu 24.04 LTS, including Apache setup, dependencies, user configuration, and starting the Nagios web interface.
Nagios Server IP : 192.168.224.128
Part - I - Configure Nagios
-----------------------------------------------------
Step 1: Update System
sudo apt update && sudo apt upgrade -y
Step 2: Install Required Dependencies
sudo apt install -y autoconf gcc libperl-dev make apache2 php php-gd libgd-dev \
libapache2-mod-php libssl-dev daemon unzip wget libtool libxml2-dev \
libjansson-dev libdbi-dev libsqlite3-dev
Step 3: Create Nagios User and Group
sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -aG nagcmd nagios
sudo usermod -aG nagcmd www-data
Step 4: Download and Install Nagios Core
Download Latest Nagios (Update URL if needed)
cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.5.9.tar.gz
tar -xzf nagios-4.5.9.tar.gz
cd nagios-4.5.9
Compile and Install:
./configure --with-command-group=nagcmd
make all
sudo make install
sudo make install-commandmode
sudo make install-init
sudo make install-config
sudo make install-webconf
Step 5: Set up Web Access
Create Nagios Admin User:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Enter a password (e.g., admin@123)
Step 6: Install and Configure Nagios Plugins
cd /tmp
wget https://nagios-plugins.org/download/nagios-plugins-2.4.9.tar.gz
tar -xzf nagios-plugins-2.4.9.tar.gz
cd nagios-plugins-2.4.9
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
sudo make install
Step 7: Enable and Start Nagios and Apache
sudo systemctl enable apache2
sudo systemctl enable nagios
sudo systemctl start apache2
sudo systemctl start nagios
Step 8: Allow Firewall (if UFW enabled)
sudo ufw allow Apache
sudo ufw reload
Step 9: Enable CGI Module (Required by Nagios)
sudo a2enmod cgi
systemctl restart apache2
Step 10: Access Nagios Web UI
Open your browser and go to:
http://192.168.224.128/nagios
Login:
Username: nagiosadmin
Password: The one you set (e.g., admin@123)
Optional: Verify Nagios Configuration
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Output:
------
------
Total Warnings: 0
Total Errors: 0
Part - II Configure the Nagios Server (192.168.224.128) to Monitor Remote Hosts
-----------------------------------------------------
Step 1: After adding the NRPE service to a remote host, you should also make some changes to the Nagios server to allow the server to communicate to the remote host. Follow the steps below to configure the Nagios server.
Ensure you're connected to the Nagios server through SSH.
Create a new servers directory on Negios Server (192.168.224.128).
sudo mkdir -p /usr/local/nagios/etc/servers/
Step 2: Create a new /usr/local/nagios/etc/servers/host.cfg configuration file to store remote hosts' information.
sudo nano /usr/local/nagios/etc/servers/host.cfg
Add the following configurations to the file. Replace Vultr with your remote hostname and remote-host-ip with the remote host's public IP address.
define host {
use linux-server
host_name RemoteHost #your host name
alias My Remote Host #Alias Name
address 192.168.224.129 #IP Address of the remote host
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
}
Save and close the file.
In the above configuration:
max_check_attempts: Sets the maximum number of retries before marking the host as down.
check_period: Sets the period to perform host checks.
notification_interval: Sets the interval (in minutes) between consecutive notifications.
notification_period: Sets the period to send notifications in the Nagios dashboard.
Step 3: Open the main Nagios (192.168.224.128) configuration file to enable the remote host configuration.
sudo nano /usr/local/nagios/etc/nagios.cfg
Add the following directive at the end of the file.
cfg_dir=/usr/local/nagios/etc/servers
Save and close the file.
Step 4: Restart the Nagios service to apply the configuration changes.
sudo systemctl restart nagios
Step 5: Test the Nagios configuration for errors.
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Output:
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
Restart Nagios to apply the configuration changes.
sudo systemctl restart nagios
Access the Nagios web monitoring dashboard.
http://192.168.224.128/nagios
🖥 On Remote Host
1. Install NRPE and Plugins
Ubuntu/Debian:
sudo apt update && sudo apt install nagios-nrpe-server nagios-plugins -y
CentOS/RHEL:
sudo yum install epel-release -y
sudo yum install nrpe nagios-plugins-all -y
2. Edit NRPE Configuration
sudo nano /etc/nagios/nrpe.cfg
Set allowed_hosts to include the IP of your Nagios server:
allowed_hosts=127.0.0.1,192.168.224.128 ; Replace with your Nagios server IP
3. Start and Enable NRPE
sudo systemctl restart nagios-nrpe-server
sudo systemctl enable nagios-nrpe-server
🔁 Final Steps on Nagios Server (192.168.224.128)
4. Check Nagios Config and Restart
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
sudo systemctl restart nagios
5. Access Nagios Web Interface
Go to: http://192.168.224.128/nagios
Login and check the remote host and services status.
For any doubts and query, please write on YouTube video comments section.
Note : Flow the Process shown in video.
😉Please, Subscribe and like for more videos:
https://www.youtube.com/@chiragtutorial
💛Don't forget to, 💘Follow, 💝Like, 💖Share 💙&, Comment
Thanks & Regards,
Chitt Ranjan Mahto "Chirag"
_____________________________________________________________________
Note: All scripts used in this demo will be available in our website.
Link will be available in description.
Subscribe to my newsletter
Read articles from Chitt Ranjan Mahto (Chirag) directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
