
Your Complete Guide to Installing Nagios on CentOS 8
In today’s complex IT environments, proactive monitoring isn’t just a luxury—it’s a necessity. Ensuring your servers, applications, and network services are running optimally is critical for business continuity. Nagios Core is a powerful, open-source industry standard for IT infrastructure monitoring, providing the essential visibility you need to detect and resolve problems before they impact your users.
This comprehensive guide will walk you through the step-by-step process of installing and configuring a Nagios Core monitoring server on CentOS 8.
A Quick Note on CentOS 8: As CentOS 8 has reached its End-of-Life (EOL), it no longer receives official updates. For production environments, it is highly recommended to migrate to a derivative like Rocky Linux or AlmaLinux. The installation steps provided here are virtually identical for these systems.
Step 1: Prepare Your System with Essential Dependencies
Before we can install Nagios, we need to set up the necessary environment. This involves installing a web server (Apache), a scripting language (PHP), and various compilers and development tools required to build Nagios from the source.
Open your terminal and run the following command to install all required packages in one go:
sudo dnf install -y httpd php php-fpm gcc glibc glibc-common gd gd-devel make net-snmp unzip
Once the installation is complete, it’s a good practice to start and enable the Apache web server and PHP-FPM service to ensure they launch automatically on boot.
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
Step 2: Create a Dedicated Nagios User and Group
For security purposes, Nagios should not run as the root user. We’ll create a dedicated user and group to manage the Nagios process. This isolates its permissions and reduces potential security risks.
First, create the nagios user and group:
sudo useradd nagios
sudo groupadd nagcmd
Next, add both the nagios user and the apache user to the nagcmd group. This is a critical step that allows the web interface to submit commands to the Nagios engine.
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd apache
Step 3: Download and Install Nagios Core
Now we’re ready to download and compile the main Nagios Core application. It’s always best to check the official Nagios Core website for the latest stable version.
Navigate to your home directory or a temporary folder like
/tmp. Usewgetto download the source code archive.cd /tmp wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.7.tar.gzExtract the downloaded archive and change into the new directory.
tar xzf nagios-4.4.7.tar.gz cd nagios-4.4.7Configure the build script. The
--with-command-groupflag is essential for setting the correct permissions../configure --with-command-group=nagcmdCompile and install Nagios. The following commands will compile the source code and install the main program, service scripts, and sample configuration files.
sudo make all sudo make install sudo make install-init sudo make install-config sudo make install-commandmode
Step 4: Configure the Apache Web Interface
Nagios comes with a web interface for easy monitoring and administration. We need to configure Apache to serve this interface.
Run the installation script that creates the necessary Apache configuration file.
sudo make install-webconfCreate a web administrator user account. This account, named
nagiosadmin, will be used to log into the Nagios web UI. You will be prompted to create a password. Choose a strong, secure password.sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadminRestart Apache to apply all the new configurations.
sudo systemctl restart httpd
Step 5: Install the Nagios Plugins
Nagios Core is the monitoring engine, but it relies on plugins to perform the actual checks (e.g., check CPU load, disk space, or HTTP status).
Return to your temporary directory and download the latest Nagios Plugins.
cd /tmp wget https://nagios-plugins.org/download/nagios-plugins-2.4.0.tar.gzExtract the archive and change into the new directory.
tar xzf nagios-plugins-2.4.0.tar.gz cd nagios-plugins-2.4.0Compile and install the plugins.
./configure sudo make sudo make install
Step 6: Final Verification and Service Startup
We’re almost done. The final step is to verify the Nagios configuration files for any errors before starting the service. This is a crucial diagnostic step.
Run the built-in verification command:
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgIf everything is configured correctly, you should see a message confirming zero warnings and zero errors.
Now, you can enable and start the Nagios service.
sudo systemctl enable nagios sudo systemctl start nagios
Security Tip: Configure Your Firewall
For security, your server’s firewall is likely active. You need to allow HTTP traffic so you can access the Nagios web interface from the network.
Run the following commands to add a permanent rule for the HTTP service and reload the firewall:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
Step 7: Access Your Nagios Monitoring Dashboard
Congratulations! Your Nagios server is now up and running.
Open your web browser and navigate to your server’s IP address or domain name, followed by /nagios.
http://your-server-ip/nagios
You will be prompted for a username and password. Enter nagiosadmin as the username and the secure password you created in Step 4. You should now see the Nagios Core dashboard, your central hub for monitoring your infrastructure. From here, you can begin adding hosts and services to monitor.
Source: https://kifarunix.com/install-nagios-server-on-centos-8/


