Install Nagios Monitoring Tool on Ubuntu 22.04: Best Network Monitor
This tutorial is designed to guide you through the process of installing the Install Nagios Monitoring Tool on Ubuntu 22.04. Nagios is a powerful and versatile monitoring tool used to oversee network infrastructure and applications. It provides comprehensive system information and allows for real-time network and application monitoring.
Nagios excels at monitoring servers and identifying performance bottlenecks. It maintains server statistics to help pinpoint and resolve performance-related issues. Furthermore, it sends alerts to users when any issues are detected, enabling proactive problem resolution. This article will focus on how to Install Nagios Monitoring Tool on Ubuntu 22.04
To successfully complete this guide, you need to log in to your Ubuntu 22.04 server as a non-root user with sudo privileges and have a basic firewall set up. If you haven’t already, you can follow our guide on Initial Server Setup with Ubuntu 22.04 to configure these prerequisites.
1. Install Required Packages for Nagios
First, update your local package index using the following command:
sudo apt update
Next, install the necessary packages and dependencies with the following command:
sudo apt install vim wget curl build-essential unzip openssl libssl-dev apache2 php libapache2-mod-php php-gd libgd-dev
2. Download the Latest Nagios on Ubuntu 22.04
Visit the Nagios Downloads page to obtain the latest release. Use the following commands to download the Nagios core:
# 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
Once the download is complete, extract the downloaded file using the following command:
sudo tar xvzf $NAGIOS_VER.tar.gz
3. Compile and Build Nagios Monitoring Tool on Ubuntu 22.04
Now you need to compile the extracted file.
Change to the Nagios directory:
cd $NAGIOS_VER
Start the compilation process by running the following command:
sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
Upon completion, you should 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.
Create the nagios
user and group, and 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:
sudo make all
Install the main program, CGIs, and HTML files:
sudo make install
Install Nagios daemon files and configure them to start when the system boots:
sudo make install-daemoninit
Add the command mode to install and configure the external command file:
sudo make install-commandmode
Install the SAMPLE configuration files, as Nagios requires them to start on Ubuntu 22.04:
sudo make install-config
4. Configure Apache to Serve Nagios Web Pages
Now, configure Apache to serve Nagios web pages. Nagios developers have simplified this process. Run the following command to set up the configuration files and enable the necessary Apache modules:
Install config files:
sudo make install-webconf
Enable Apache rewrite and CGI modules:
sudo a2enmod rewrite cgi
5. Configure Nagios Apache Authentication on Ubuntu 22.04
To create Nagios web authentication, you need to create a web user for authentication. The htpasswd
command is used for this. Note that Nagios uses the nagiosadmin
user by default. Run the command below and enter 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
Set the correct permissions for the /usr/local/nagios/etc/htpasswd.users
file:
# sudo chown www-data:www-data /usr/local/nagios/etc/htpasswd.users
# sudo chmod 640 /usr/local/nagios/etc/htpasswd.users
6. Install Nagios Monitoring Tool Plugins on Ubuntu 22.04
Before accessing the Nagios web interface, you need Nagios plugins, which are crucial for monitoring the local host and other services. You can find the plugins at Nagios Plugins.
Follow the steps below to install the latest plugins. First, switch to your home directory:
cd ~
Then, run the following commands to download and extract the Nagios plugins on Ubuntu 22.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
Navigate into the new plugins folder, then compile and install them:
# cd nagios-plugins-$VER
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# sudo make
# sudo make install
7. Configure Firewall For Nagios on Ubuntu 22.04
Allow ports on the firewall and start Nagios:
# sudo ufw allow 80
# sudo ufw reload
8. Start Nagios Monitoring Tool on Ubuntu 22.04
Start the Nagios and Apache services on Ubuntu 22.04:
# sudo systemctl restart apache2
# sudo systemctl start nagios.service
9. Access Nagios Monitoring Tool Web Interface
Access the Nagios web interface by typing your server’s IP address in your web browser followed by /nagios
:
http://<IP Address>/nagios
You will be prompted for a username and password. Use the credentials you set earlier, i.e., nagiosadmin
.
[Image of Nagios login screen]
[Image of Nagios dashboard]
If you click on the "Hosts" link, you should see that the localhost is up and being monitored, thanks to the plugins installed earlier.
Conclusion
The Install Nagios Monitoring Tool on Ubuntu 22.04 is a robust solution for detecting issues and performance bottlenecks within your network. The provided web interface facilitates network monitoring and issue identification across network components.
At this point, you have successfully learned how to Install Nagios Monitoring Tool on Ubuntu 22.04.
Hope you enjoy it. You may also like these articles:
How To Restart Network on Ubuntu
How To List Installed Packages on Ubuntu
Install and Use Iptables on Ubuntu 22.04
Configure Nginx as a Reverse Proxy on Ubuntu 24.04
Install Docker Compose on Ubuntu 24.04
fd command in Linux with Examples
mkvirtualenv Command Not Found on Linux
Tail command in Linux with examples
Install Zsh and Oh My Zsh on Linux
Alternative Solutions for Network Monitoring on Ubuntu 22.04
While Nagios is a powerful tool, other solutions offer different advantages and might be better suited for certain environments. Here are two alternative methods for network monitoring on Ubuntu 22.04:
1. Using Zabbix:
Zabbix is an enterprise-class open-source monitoring solution. It offers a wide range of features, including network monitoring, server monitoring, application monitoring, and cloud monitoring. Zabbix boasts a more modern web interface and can handle a larger scale of monitoring than Nagios out of the box. It also has built-in agents that can be installed on monitored systems for more detailed data collection.
-
Explanation: Zabbix uses agents installed on the target systems to actively collect data and send it back to the Zabbix server. It supports passive checks as well, where the server requests data from the target. It offers a rich set of visualizations, including graphs, maps, and dashboards.
-
Installation and Configuration (Simplified):
First, install the Zabbix server and agent:
sudo apt update sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-agent
Next, create a database for Zabbix:
sudo mysql -u root -p CREATE DATABASE zabbix CHARACTER SET utf8mb4 COLLATE utf8mb4_bin; GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY 'your_zabbix_password'; FLUSH PRIVILEGES; exit
Import the initial schema and data:
zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -u zabbix -p zabbix
Configure the Zabbix server to use the database:
sudo nano /etc/zabbix/zabbix_server.conf
Modify the following parameters:
DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=your_zabbix_password
Restart the Zabbix server and agent:
sudo systemctl restart zabbix-server sudo systemctl restart zabbix-agent
Access the Zabbix web interface at
http://<your_server_ip>/zabbix
and follow the on-screen instructions to complete the setup. The default username is "Admin" and the password is "zabbix". After logging in, you can start adding hosts to monitor. For each host, you’ll need to install the Zabbix agent and configure it to communicate with the server.
2. Using Prometheus and Grafana:
Prometheus is an open-source systems monitoring and alerting toolkit. Grafana is an open-source data visualization and monitoring suite. Together, they provide a powerful and flexible monitoring solution. Prometheus excels at collecting time-series data, while Grafana provides excellent dashboards for visualizing that data.
-
Explanation: Prometheus uses a pull-based model, where it scrapes metrics from target systems. These targets expose metrics in a specific format that Prometheus understands. Grafana then connects to Prometheus as a data source and allows you to create dashboards to visualize the collected metrics. This solution is particularly well-suited for monitoring containerized environments.
-
Installation and Configuration (Simplified):
First, download and install Prometheus and Grafana:
# For Prometheus wget https://github.com/prometheus/prometheus/releases/download/v2.46.0/prometheus-2.46.0.linux-amd64.tar.gz tar xvf prometheus-2.46.0.linux-amd64.tar.gz cd prometheus-2.46.0.linux-amd64 sudo mv prometheus /usr/local/bin/ sudo mv promtool /usr/local/bin/ sudo mkdir /etc/prometheus sudo mkdir /var/lib/prometheus sudo cp prometheus.yml /etc/prometheus/ sudo cp -r consoles/ console_libraries/ /etc/prometheus/ sudo chown -R nobody:nogroup /etc/prometheus/ /var/lib/prometheus/
Create a systemd service file for Prometheus:
sudo nano /etc/systemd/system/prometheus.service
Add the following content:
[Unit] Description=Prometheus Wants=network-online.target After=network-online.target [Service] User=nobody Group=nogroup Type=simple ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/ --web.console.templates=/etc/prometheus/consoles --web.console.libraries=/etc/prometheus/console_libraries [Install] WantedBy=multi-user.target
Enable and start Prometheus:
sudo systemctl enable prometheus sudo systemctl start prometheus
For Grafana:
sudo apt update sudo apt install -y apt-transport-https sudo apt install -y software-properties-common wget wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - echo "deb https://packages.grafana.com/enterprise/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list sudo apt update sudo apt install grafana sudo systemctl enable grafana-server sudo systemctl start grafana-server
Access the Grafana web interface at
http://<your_server_ip>:3000
. The default username and password are "admin". Once logged in, add Prometheus as a data source. Then, import pre-built dashboards or create your own to visualize the metrics collected by Prometheus. You’ll likely need to install exporters (likenode_exporter
for system metrics) on the servers you want to monitor.
These alternative solutions, Zabbix and Prometheus/Grafana, offer compelling alternatives to Nagios for network monitoring on Ubuntu 22.04, each with its own strengths and weaknesses depending on the specific monitoring needs of your environment.