Linux

How to Use Nagios to Monitor Linux Systems on Ubuntu

How to Use Nagios to Monitor Linux Systems on Ubuntu

Introduction

Nagios is one of the most popular and powerful open-source tools used for monitoring networked systems, including Linux servers. With its extensive plugin architecture, Nagios can keep track of a wide variety of services, resources, and metrics, such as disk usage, system load, memory utilization, and uptime. It provides real-time alerts for system administrators when thresholds are breached or services go down, ensuring the reliability of IT infrastructure. This guide will show you how to install and configure Nagios to monitor Linux systems on Ubuntu.

Why Use Nagios?
Nagios allows you to:

  • Monitor services like SSH, HTTP, and MySQL.
  • Track resource usage, including CPU load, disk space, and memory.
  • Receive notifications for any system failures or issues through email or SMS.
  • Set up thresholds for resources so that warnings are triggered before critical levels are reached.
  • Expand monitoring capabilities using Nagios plugins, which let you monitor nearly anything on your system.

Prerequisites
Before you begin, make sure you have:

  • A server running Ubuntu (we’ll use Ubuntu 20.04 in this guide).
  • Root access or sudo privileges on the server.
  • Basic command-line knowledge to follow the setup.

Step 1: Update and Install Dependencies
Start by updating your system’s package list and installing the required packages for Nagios.

sudo apt update
sudo apt install apache2 libapache2-mod-php php php-gd libgd-dev build-essential libssl-dev

Nagios requires Apache as its web server and PHP for the web interface, along with several other dependencies.

Step 2: Download and Install Nagios Core
Visit the official Nagios website and download the latest version of Nagios Core. Alternatively, you can use the following commands to download and install it.

cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.6.tar.gz
tar -xzf nagios-4.4.6.tar.gz
cd nagios-4.4.6

Next, run the following commands to compile and install Nagios:

sudo ./configure –with-httpd-conf=/etc/apache2/sites-enabled/
sudo make all
sudo make install-groups-users
sudo usermod -aG nagios www-data
sudo make install
sudo make install-commandmode
sudo make install-init
sudo make install-config
sudo make install-webconf
sudo a2enmod rewrite cgi

Step 3: Configure Nagios Web Interface
You need to set up the Nagios web interface, which will allow you to view the status of monitored services through your browser. Set up a password for the nagiosadmin user, which will be used to log into the Nagios web interface.

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

Now restart the Apache service to apply the changes.

sudo systemctl restart apache2

Step 4: Install Nagios Plugins
Nagios relies on plugins to monitor different services and metrics. You’ll need to download and install the official Nagios plugins.

cd /tmp
wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
tar -xzf nagios-plugins-2.3.3.tar.gz
cd nagios-plugins-2.3.3
sudo ./configure
sudo make
sudo make install

Step 5: Start Nagios
Now that everything is installed, it’s time to start Nagios.

sudo systemctl start nagios

Enable Nagios to start automatically on boot:

sudo systemctl enable nagios

Step 6: Access Nagios Web Interface
To access the Nagios web interface, open your web browser and go to:

http:///nagios

Log in using the nagiosadmin username and the password you created earlier.

Step 7: Add Linux Hosts for Monitoring
By default, Nagios only monitors the host it is installed on. To monitor other Linux systems on your network, you will need to configure additional hosts and services.

Edit the Configuration File
Edit the main configuration file to add the details of the systems you want to monitor:

sudo nano /usr/local/nagios/etc/nagios.cfg

Look for the following line:

cfg_dir=/usr/local/nagios/etc/servers

If it’s commented out, uncomment it to enable this feature. Save and close the file.

Create Configuration Files for Hosts
Next, create a directory for the configuration files of the hosts:

sudo mkdir /usr/local/nagios/etc/servers

Create a new configuration file for each host:

sudo nano /usr/local/nagios/etc/servers/ubuntu-server.cfg

Add the following configuration to define the host:

define host {
use linux-server
host_name ubuntu-server
alias Ubuntu Server
address 192.168.1.10
}
Define Services for the Host
To monitor services on the new host, define them in the same configuration file:

define service {
use generic-service
host_name ubuntu-server
service_description SSH
check_command check_ssh
}

define service {
use generic-service
host_name ubuntu-server
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}

Save and close the file.

Step 8: Restart Nagios
After configuring the hosts and services, restart Nagios to apply the changes.

sudo systemctl restart nagios

Step 9: Set Up Email Notifications
Nagios can send notifications via email when issues are detected. To configure email notifications, edit the contacts.cfg file:

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

Update the email address under the nagiosadmin contact definition:

define contact {
contact_name nagiosadmin
use generic-contact
alias Nagios Admin
email [email protected]
}

Save and close the file. Restart Nagios once more to apply the changes.

For further information, you can visit the official Nagios documentation.

Thank you for visiting our page! If you’re interested in exploring more articles about Linux systems and using FileZilla, feel free to check out the links below.

How to Install and Use FileZilla for FTP on Ubuntu

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button