Install Nagios Monitoring Tool on Ubuntu 20.04: Free Software

Posted on

Install Nagios Monitoring Tool on Ubuntu 20.04: Free Software

Install Nagios Monitoring Tool on Ubuntu 20.04: Free Software

In this tutorial, we’ll walk you through how to Install Nagios Monitoring Tool on Ubuntu 20.04. Nagios is a free and open-source software application designed for computer systems, networks, and infrastructure monitoring.

This powerful tool, written in the C language, is primarily designed to run on the Linux operating system. However, it’s also compatible with Unix and Windows operating systems.

Nagios is available in two primary variants:

  • Nagios Core: The open-source, foundational monitoring engine.
  • Nagios XI: A commercial offering with added features and a web-based interface.

Now, let’s dive into the steps required to install Nagios Core monitoring on Ubuntu 20.04, following this guide on the Orcacore website.

To successfully complete this guide, you’ll need to log in to your server as a non-root user with sudo privileges and have a basic firewall set up. Refer to our guide on Initial Server Setup with Ubuntu 20.04 for assistance.

In this guide, you will learn to Install Nagios Monitoring Tool on Ubuntu 20.04.

1. Nagios Monitoring Tool Setup on Ubuntu 20.04

First, update your local package index with the following command:

sudo apt update

Then, install the required packages and dependencies using the command below:

sudo apt install vim wget curl build-essential unzip openssl libssl-dev apache2 php libapache2-mod-php php-gd libgd-dev -y

Download Nagios Core For Ubuntu 20.04

Visit the Nagios Downloads page to obtain the latest release. Use the following commands:

# NAGIOS_VER=$(curl -s https://api.github.com/repos/NagiosEnterprises/nagioscore/releases/latest|grep tag_name | cut -d '"' -f 4)
# wget https://github.com/NagiosEnterprises/nagioscore/releases/download/$NAGIOS_VER/$NAGIOS_VER.tar.gz

Extract the downloaded file using the following command:

sudo tar xvzf $NAGIOS_VER.tar.gz

Compile and Build Nagios Core

Now, compile the extracted file.

Switch to your Nagios directory with the command:

cd $NAGIOS_VER

Start the compilation process by running the command below:

sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled

Upon completion, you’ll see output similar to this:

**Output**
...
Review the options above for accuracy. If they look okay,
type 'make all' to compile the main program and CGIs.

Next, create a user and group. Also, add the www-data user to the “nagios” group.

# sudo make install-groups-users
**Output**
groupadd -r nagios
useradd -g nagios nagios
# sudo usermod -a -G nagios www-data

Compile the main Nagios program and associated packages using this command:

sudo make all

Then, install the main program, CGIs, and HTML files:

sudo make install

Next, install Nagios daemon files and configure them to start on system boot:

sudo make install-daemoninit
**Output**
*** Init script installed ***

After that, add the command mode, which installs and configures the external command file:

sudo make install-commandmode
**Output**
*** External command directory configured ***

Here, install the SAMPLE configuration files. Nagios requires these files to start correctly on Ubuntu 20.04:

sudo make install-config
**Output**
*** Config files installed ***

Configure Apache to serve Nagios web pages. The Nagios developers have simplified Apache setup. Run the following command to set up configuration files and enable specific Apache modules.

Install config files:

sudo make install-webconf
**Output**
*** Nagios/Apache conf file installed ***

Enable Apache rewrite and CGI modules:

sudo a2enmod rewrite cgi

Configure Nagios Apache Authentication on Ubuntu 20.04

To create Nagios web authentication, create a web user. The “htpasswd” command is used for this purpose. By default, Nagios uses the “nagiosadmin” user. Run the command below and input your preferred password:

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
**Output**
New password:
Re-type new password:
Adding password for user nagiosadmin

When finished, set the correct permissions to the /usr/local/nagios/etc/htpasswd.users file with these commands:

# sudo chown www-data:www-data /usr/local/nagios/etc/htpasswd.users
# sudo chmod 640 /usr/local/nagios/etc/htpasswd.users

Install Nagios Monitoring Tool Plugins on Ubuntu 20.04

Before accessing the Nagios web interface, install Nagios Plugins. These plugins help monitor the local host and other services. Find the plugins at Nagios Plugins.

Follow these steps to install the latest plugins. First, switch to your home directory:

cd ~

Then, run the following command to grab the Nagios plugins and extract them on Ubuntu 20.04:

# VER=$(curl -s https://api.github.com/repos/nagios-plugins/nagios-plugins/releases/latest|grep tag_name | cut -d '"' -f 4|sed 's/release-//')

# wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-$VER/nagios-plugins-$VER.tar.gz

# tar xvf nagios-plugins-$VER.tar.gz

Next, navigate into the new plugins folder, then compile and install it:

# cd nagios-plugins-$VER
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# sudo make
# sudo make install

Configure Firewall For Nagios on Ubuntu 20.04

Allow ports on the firewall and start Nagios.

# sudo ufw allow 80
# sudo ufw reload

Start Nagios Monitoring Tool on Ubuntu 20.04

Start Nagios and Apache services on Ubuntu 20.04:

# sudo systemctl restart apache2
# sudo systemctl start nagios.service

2. Access Nagios Core Login Page

Access the Nagios web interface by typing your server’s IP address in your web browser followed by /nagios:

http://your-server-ip/nagios

You will be prompted for a username and password. Use the “nagiosadmin” user you set up earlier. Provide credentials and click sign in.

Nagios login screen

Now you’ll see your Nagios dashboard:

Nagios dashboard

Click the “Hosts” link to see that the localhost is up and being monitored, thanks to the plugins installed.

Conclusion

The Nagios Monitoring Tool is a powerful monitoring solution that detects issues and performance bottlenecks in your network. Its web interface facilitates network monitoring and helps identify issues in network components.

You have now successfully installed and configured the Nagios Monitoring Tool on Ubuntu 20.04.

Hope you enjoy it. You may also be interested in these articles:

Alternative Solutions for System Monitoring on Ubuntu 20.04

While Nagios is a robust and widely-used monitoring solution, other options offer different approaches and feature sets. Here are two alternative ways to achieve system monitoring on Ubuntu 20.04:

1. Using Prometheus and Grafana

Prometheus is a time-series database and monitoring system, while Grafana is a powerful data visualization tool. Together, they provide a comprehensive monitoring solution. This method is especially well-suited for containerized environments and applications that expose metrics in a Prometheus-compatible format.

Explanation:

  • Prometheus: Scrapes metrics from configured targets (e.g., system services, applications) at regular intervals. It stores these metrics as time-series data, allowing you to query and analyze performance trends over time.
  • Grafana: Connects to Prometheus as a data source and allows you to create customizable dashboards to visualize the collected metrics. Grafana provides a wide range of chart types, alerting capabilities, and integration with other services.

Installation and Configuration:

  1. Install Prometheus:

    wget https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-2.48.1.linux-amd64.tar.gz
    tar xvf prometheus-2.48.1.linux-amd64.tar.gz
    cd prometheus-2.48.1.linux-amd64
    sudo mv prometheus /usr/local/bin/
    sudo mv promtool /usr/local/bin/
    sudo mkdir /etc/prometheus
    sudo mkdir /var/lib/prometheus
    sudo mv prometheus.yml /etc/prometheus/
    sudo mv consoles/ console_libraries/ /etc/prometheus/

    Create a Prometheus user and group:

    sudo groupadd prometheus
    sudo useradd -g prometheus --no-create-home --shell /bin/false prometheus
    sudo chown -R prometheus:prometheus /etc/prometheus
    sudo chown -R prometheus:prometheus /var/lib/prometheus

    Create a systemd service file:

    sudo nano /etc/systemd/system/prometheus.service

    Add the following content:

    [Unit]
    Description=Prometheus
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    User=prometheus
    Group=prometheus
    Type=simple
    ExecStart=/usr/local/bin/prometheus 
        --config.file=/etc/prometheus/prometheus.yml 
        --storage.tsdb.path=/var/lib/prometheus/ 
        --web.console.path=/etc/prometheus/consoles 
        --web.console.libraries=/etc/prometheus/console_libraries
    
    [Install]
    WantedBy=multi-user.target

    Enable and start Prometheus:

    sudo systemctl daemon-reload
    sudo systemctl enable prometheus
    sudo systemctl start prometheus
    sudo systemctl status prometheus
  2. Install Grafana:

    sudo apt update
    sudo apt install -y apt-transport-https software-properties-common wget
    wget -q -O - https://apt.grafana.com/gpg.key | sudo apt-key add -
    echo "deb https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
    sudo apt update
    sudo apt install grafana
    sudo systemctl start grafana-server
    sudo systemctl enable grafana-server
    sudo systemctl status grafana-server
  3. Configure Prometheus to scrape system metrics:

    You’ll likely want to use a node exporter to expose system metrics in a Prometheus-compatible format. Install node_exporter:

    wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
    tar xvf node_exporter-1.7.0.linux-amd64.tar.gz
    cd node_exporter-1.7.0.linux-amd64
    sudo mv node_exporter /usr/local/bin/

    Create a node_exporter user and group:

    sudo groupadd node_exporter
    sudo useradd -g node_exporter --no-create-home --shell /bin/false node_exporter
    sudo chown -R node_exporter:node_exporter /usr/local/bin/node_exporter

    Create a systemd service file:

    sudo nano /etc/systemd/system/node_exporter.service

    Add the following content:

    [Unit]
    Description=Node Exporter
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    User=node_exporter
    Group=node_exporter
    Type=simple
    ExecStart=/usr/local/bin/node_exporter
    
    [Install]
    WantedBy=multi-user.target

    Enable and start node_exporter:

    sudo systemctl daemon-reload
    sudo systemctl enable node_exporter
    sudo systemctl start node_exporter
    sudo systemctl status node_exporter

    Edit the Prometheus configuration file /etc/prometheus/prometheus.yml to add node_exporter as a scrape target:

    scrape_configs:
      - job_name: 'node_exporter'
        static_configs:
          - targets: ['localhost:9100']

    Restart Prometheus:

    sudo systemctl restart prometheus
  4. Configure Grafana to use Prometheus as a data source and create dashboards. Access Grafana in your browser (usually on port 3000), add Prometheus as a data source, and then import pre-built dashboards or create your own.

Code Example (Prometheus Configuration – /etc/prometheus/prometheus.yml):

global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds.
  evaluation_interval: 15s # Set the evaluation interval to every 15 seconds.

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'node_exporter'
    static_configs:
      - targets: ['localhost:9100']

2. Using Zabbix

Zabbix is another enterprise-class open-source monitoring solution that offers a wide range of features, including network monitoring, server monitoring, application monitoring, and more.

Explanation:

  • Zabbix Server: The central component that collects, processes, and stores monitoring data.
  • Zabbix Agent: Deployed on the monitored hosts to collect metrics and send them to the Zabbix server.
  • Zabbix Frontend: A web-based interface for configuring the monitoring system, viewing data, and generating reports.

Installation and Configuration:

  1. Install Zabbix Server and Frontend:

    sudo apt update
    sudo apt install zabbix-server-mysql zabbix-frontend-php php-mysql

    Configure the database (MySQL). During the installation, you’ll be prompted to set a password for the MySQL root user.

    sudo mysql -u root -p
    CREATE DATABASE zabbix CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
    CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'your_zabbix_password';
    GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;

    Import the initial schema and data:

    zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -u zabbix -p zabbix

    Edit the Zabbix server configuration file /etc/zabbix/zabbix_server.conf:

    DBHost=localhost
    DBName=zabbix
    DBUser=zabbix
    DBPassword=your_zabbix_password

    Restart the Zabbix server:

    sudo systemctl restart zabbix-server
  2. Install Zabbix Agent:

    sudo apt install zabbix-agent

    Edit the Zabbix agent configuration file /etc/zabbix/zabbix_agentd.conf:

    Server=your_zabbix_server_ip
    ServerActive=your_zabbix_server_ip
    Hostname=your_host_name

    Restart the Zabbix agent:

    sudo systemctl restart zabbix-agent
  3. Configure Zabbix Frontend: Access the Zabbix frontend in your browser (usually on port 80, e.g., http://your-server-ip/zabbix). Follow the on-screen instructions to configure the frontend, including database connection details. The default username is Admin and the default password is zabbix.

  4. Add hosts to Zabbix for monitoring. Use the Zabbix frontend to add the hosts you want to monitor. Zabbix uses templates for monitoring, so you can apply a "Linux Server" template to a newly added host to automatically monitor CPU, memory, disk, network, and other key metrics.

Code Example (Zabbix Agent Configuration – /etc/zabbix/zabbix_agentd.conf):

PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.1.100  # Replace with your Zabbix server IP
ServerActive=192.168.1.100 # Replace with your Zabbix server IP
Hostname=MyUbuntuServer # Replace with your hostname
Include=/etc/zabbix/zabbix_agentd.d/*.conf

These alternative solutions, Prometheus/Grafana and Zabbix, offer different architectural approaches and feature sets compared to Nagios. Choosing the right monitoring tool depends on your specific needs, infrastructure, and expertise. The Nagios Monitoring Tool, Prometheus, and Zabbix all serve the same purpose, but differ in implementation.

Leave a Reply

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