Install and Configure Nagios on Rocky Linux 8: Free Monitoring
In this tutorial, we’ll guide you through the process of installing and configuring Nagios Core on Rocky Linux 8. Nagios Core is a free and open-source software application for computer systems, used extensively for monitoring systems, networks, and infrastructure.
This powerful tool offers monitoring and alerting services for switches, applications, and servers, making it a valuable asset within a DevOps environment. It proactively notifies users of issues and also alerts them when problems are resolved.
Written primarily in C, Nagios was designed to run on Linux, but it’s also compatible with Unix and Windows operating systems.
The software application is available in the following two variants:
- Nagios Core: The free and open-source version, offering essential monitoring capabilities.
- Nagios XI: A commercial version with advanced features, a web-based interface, and support.
To successfully complete this guide, ensure you meet the following prerequisites.
1. Requirements for Nagios Core Setup
First, you need to log in to your server as a non-root user with sudo privileges and set up a basic firewall. You can achieve this by following our guide on Initial Server Setup with Rocky Linux 8.
Next, you must have Apache installed on your server. Refer to this guide for assistance: Installing Apache Web Server on Rocky Linux 8.
Also, you must have PHP installed on your server. To do this, you can follow our guide on How To Install PHP 8.1 on Rocky Linux 8.
Finally, you must disable SELinux. Consult this guide: Disabling SELinux on RHEL 8.
Once these prerequisites are met, proceed with the steps below to set up Nagios Core on Rocky Linux 8.
2. Required Packages For Nagios on Rocky Linux 8
Install the necessary packages and dependencies by executing the following command:
sudo dnf install php-cli gcc glibc glibc-common gd gd-devel net-snmp openssl-devel wget make gettext autoconf net-snmp-utils perl-Net-SNMP postfix unzip automake -y
3. Nagios Core Download
Navigate to the /usr/src/
directory:
cd /usr/src/
Visit the Project GitHub repository and download the latest release of the Nagios tar.gz file using the wget
command:
sudo wget https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.4.10/nagios-4.4.10.tar.gz
Extract the downloaded file:
sudo tar zxf nagios-*.tar.gz
Then, switch to your Nagios directory on Rocky Linux 8:
cd nagios-4.4.10
4. Compile and Build Nagios Core on Rocky Linux 8
Run the configure script to check for dependencies:
sudo ./configure
Start the compilation process:
sudo make all
The compilation time will vary based on your system. Upon completion, you’ll see output similar to this:
Output
For more information on obtaining support for Nagios, visit:
...
*************************************************************
Enjoy.
Create a new Nagios user and group:
sudo make install-groups-users
Output
groupadd -r nagios
useradd -g nagios nagios
Add the Apache user to the Nagios group:
sudo usermod -a -G nagios apache
Install the Nagios binary, CGIs, and HTML files:
sudo make install
Output
...
*** Main program, CGIs and HTML files installed ***
...
Create the external command directory and set appropriate permissions:
sudo make install-commandmode
Output
*** External command directory configured ***
Install the sample Nagios configuration files:
sudo make install-config
Output
*** Config files installed ***
Remember, these are *SAMPLE* config files. You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.
Install the Apache web server configuration files:
sudo make install-webconf
Output
*** Nagios/Apache conf file installed ***
Restart Apache:
sudo systemctl restart httpd
Install a systemd unit file to manage the Nagios service and enable it on boot:
sudo make install-daemoninit
Output
*** Init script installed ***
5. Create an Admin User for Nagios on Rocky Linux 8
Create an administrator user named nagiosadmin
to access the web interface:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Enter and confirm the password for the new user.
Output
New password:
Re-type new password:
Adding password for user nagiosadmin
Restart Apache to apply the changes:
sudo systemctl restart httpd
6. Configure Firewall for Nagios on Rocky Linux 8
Allow HTTP and HTTPS traffic through the firewall:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
Reload the firewall to apply the new rules:
sudo firewall-cmd --reload
7. Install Nagios Monitoring Tool Plugins on Rocky Linux 8
Navigate to the /usr/src
directory:
cd /usr/src/
Download the latest version of the Nagios Plugins from the project GitHub repository:
sudo wget -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/releases/download/release-2.4.3/nagios-plugins-2.4.3.tar.gz
Extract the downloaded archive:
sudo tar zxf nagios-plugins.tar.gz
Change to the Nagios plugins directory:
cd nagios-plugins-2.4.3
Compile and install the plugins:
sudo ./configure
sudo make
sudo make install
8. Start Nagios Service on Rocky Linux 8
Start the Nagios service:
sudo systemctl start nagios
Verify that Nagios is running:
sudo systemctl status nagios
9. Access Nagios Monitoring Tool Web Interface
Access the Nagios web interface by entering your server’s IP address followed by /nagios
in your web browser:
http://<server-ip>/nagios
Enter the nagiosadmin
user login credentials and click sign in.
You’ll be redirected to the default Nagios home page.
That’s it! You’ve successfully installed and configured Nagios Core on Rocky Linux 8.
For more information, visit the Nagios Documentation page.
Conclusion
You have now learned how to Install and Configure Nagios on Rocky Linux 8. The core version is a free version of Nagios that you can use to monitor your network and systems.
Alternative Solutions for Monitoring on Rocky Linux 8
While Nagios Core is a robust and widely used monitoring solution, other options exist that might better suit specific needs or preferences. Here are two alternative approaches:
1. Using Zabbix
Zabbix is another open-source monitoring solution that offers a comprehensive set of features, often considered more user-friendly than Nagios in terms of initial setup and configuration. It provides real-time monitoring of thousands of servers, virtual machines, and network devices.
Explanation:
Zabbix uses agents installed on the monitored hosts to collect data, which is then sent to the Zabbix server for processing and visualization. It offers a web-based interface for configuring monitoring parameters, viewing collected data, and setting up alerts.
Key Advantages of Zabbix:
- Easier Initial Configuration: Compared to Nagios, Zabbix provides a more streamlined setup process, particularly for those new to monitoring solutions.
- Agent-Based Architecture: The agent-based approach allows for efficient data collection and reduced overhead on the monitored hosts.
- Built-in Discovery Rules: Zabbix can automatically discover hosts and services within your network, simplifying the configuration process.
- Advanced Visualization: Zabbix offers rich visualization options, including graphs, maps, and dashboards.
Installation and Configuration (Simplified):
-
Install Zabbix Server and Agent:
sudo dnf install zabbix-server-mysql zabbix-agent sudo dnf install mysql-server sudo systemctl start mysqld sudo mysql_secure_installation #Set up mysql root user mysql -u root -p
Create a Zabbix Database
create database zabbix character set utf8 collate utf8_bin; grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'password'; flush privileges; quit
Import initial schema and data. You will be prompted to enter your newly created password.
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
Edit /etc/zabbix/zabbix_server.conf
DBPassword=password
Start Zabbix Service
systemctl restart zabbix-server systemctl enable zabbix-server
- Configure Zabbix Server: Edit the
/etc/zabbix/zabbix_server.conf
file to configure database connection details. - Start Zabbix Services: Enable and start the Zabbix server and agent services.
- Access the Zabbix Web Interface: Open your web browser and navigate to
http://<server-ip>/zabbix
. - Configure Monitoring: Use the web interface to add hosts, configure monitoring parameters, and set up alerts.
2. Prometheus and Grafana
Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. It is particularly well-suited for monitoring dynamic, containerized environments. Grafana is an open-source data visualization and monitoring suite that works seamlessly with Prometheus.
Explanation:
Prometheus collects metrics from monitored targets using a pull-based approach. Targets expose metrics via HTTP endpoints, which Prometheus scrapes at regular intervals. Grafana then connects to Prometheus to visualize the collected data through dashboards and graphs.
Key Advantages of Prometheus and Grafana:
- Designed for Dynamic Environments: Prometheus excels at monitoring applications and infrastructure in rapidly changing environments like Kubernetes clusters.
- Powerful Query Language (PromQL): Prometheus provides a flexible query language (PromQL) for analyzing and aggregating metrics.
- Scalability: Prometheus can scale to handle large-scale monitoring deployments.
- Rich Visualization with Grafana: Grafana provides a user-friendly interface for creating customizable dashboards and visualizing Prometheus metrics.
Installation and Configuration (Simplified):
-
Install Prometheus:
sudo wget https://github.com/prometheus/prometheus/releases/download/v2.47.0/prometheus-2.47.0.linux-amd64.tar.gz sudo tar -xvzf prometheus-2.47.0.linux-amd64.tar.gz cd prometheus-2.47.0.linux-amd64 sudo ./prometheus --config.file=prometheus.yml
-
Install Grafana:
sudo dnf install -y grafana sudo systemctl start grafana-server sudo systemctl enable grafana-server
-
Configure Prometheus: Edit the
prometheus.yml
file to define the targets to be monitored.scrape_configs: - job_name: 'linux' static_configs: - targets: ['localhost:9090']
-
Access Grafana: Open your web browser and navigate to
http://<server-ip>:3000
. -
Configure Grafana Data Source: Add Prometheus as a data source in Grafana, pointing it to the Prometheus server.
-
Create Dashboards: Import or create Grafana dashboards to visualize the metrics collected by Prometheus.
These alternative solutions provide different approaches to system monitoring, each with its strengths and weaknesses. Carefully consider your specific requirements and environment when choosing the best monitoring solution for your needs. While Nagios is a well-established option, Zabbix and Prometheus/Grafana offer compelling alternatives worth exploring.