In this guide, you will learn how to install Nagios Server on CentOS 9 Stream. Nagios provides enterprise-class Open Source IT monitoring, network monitoring, server and applications monitoring.
Table of Contents
Installing Nagios Server on CentOS 9 Stream
To install Nagios Server, follow through the steps below;
Run System Update
Resynchronize your system packages to their latest versions.
dnf update
Install Required Build Tools
Nagios core packages are available on the default EPEL repositories on CentOS 9 stream. However, the available version on EPEL repos is not up-to-date. For example, as of this writing, the current release on EPEL repos is Nagios v4.4.14 while the current stable release version of Nagios Core is version v4.5.7 as per the releases page.
In this guide, we are going to build Nagios Core from the source code so as to install the most current stable release version. As such there are packages and build tools that you need to install. Run the command below to install them.
dnf install -y \
gcc \
glibc glibc-common \
perl \
httpd \
php php-cli php-common \
wget \
net-snmp \
gd gd-devel \
openssl-devel
Download Nagios Core Source Code
Navigate to the Nagios Core downloads page and grab the latest Nagios core source code. You can simplify this step by just using wget.
VER=4.5.7
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-${VER}.tar.gz
Extract the Nagios Source Code
Once the Nagios source is downloaded, extract it by running the command;
tar xzf nagios-${VER}.tar.gz
Installing Nagios Core on CentOS 9 Stream
Next, navigate to the Nagios source code directory.
cd nagios-${VER}/
Configure Nagios Core on CentOS 9 Stream
Run the configuration script to adapt Nagios to your system and check if all required dependencies and build tools are in place.
./configure
If the configuration is successful, you will be provided with the summary;
...
*** Configuration summary for nagios 4.5.7 2024-10-24 ***:
General Options:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagios
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Install ${includedir}: /usr/local/nagios/include/nagios
Lock file: /run/nagios.lock
Check result directory: /usr/local/nagios/var/spool/checkresults
Init directory: /lib/systemd/system
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
Host OS: linux-gnu
IOBroker Method: epoll
Web Interface Options:
------------------------
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP):
Review the options above for accuracy. If they look okay,
type 'make all' to compile the main program and CGIs.
Compile Nagios Core
Next, proceed to compile Nagios Main program and CGIs.
make all
If the main program and CGIs compiled without any errors, proceed to install Nagios and its configurations.
Create Nagios User and Group
Nagios runs as non-privileged nagios
user. As such, you need to create a Nagios system user and group.
make install-groups-users
Add Apache user to the Nagios group.
usermod -aG nagios apache
Install Nagios Core on CentOS 9 Stream
Install Nagios main program, CGIs, and HTML files.
make install
Install Nagios Service
Install Nagios Systemd initialization scripts.
make install-daemoninit
Install Nagios Commands
Install and configure the external command file as well as the permissions on the directory holding the external commands file.
make install-commandmode
Install Nagios Configuration Files
Install Nagios Sample configuration file.
make install-config
This command installs Nagios sample configuration files in /usr/local/nagios/etc
.
Install Nagios Apache Configuration files
Next, install the Apache HTTP server configuration files for Nagios.
make install-webconf
Setup Nagios Apache Authentication
To setup Nagios Web authentication, you need to create an Apache user for authentication. This can be done using the htpasswd
command.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
The user, nagiosadmin
, is used by default.
If you need to use a different user, you need to replace all the occurences of nagiosadmin
on the /usr/local/nagios/etc/cgi.cfg
file with the user you created.
For example, if you use a user like monadmin
, replace nagiosadmin
as shown below.
sed -i 's/nagiosadmin/monadmin/g' /usr/local/nagios/etc/cgi.cfg
If you also want to use a different authentication user file instead of, /usr/local/nagios/etc/htpasswd.users
, ensure you edit the Nagios Apache configuration file, /etc/httpd/conf.d/nagios.conf
and change the value of AuthUserFile
.
Set the ownership of the Nagios Apache authentication configuration file to web-server user, apache
.
chown apache:apache /usr/local/nagios/etc/htpasswd.users
Adjust the file permissions appropriately such that the owner (apache) have read write access, the group has read access.
chmod 640 /usr/local/nagios/etc/htpasswd.users
Start Apache Web server
Once you are done with configuration, start and enable Apache to run on system boot.
systemctl enable httpd --now
If firewallD is running on your system, be sure to enable external access to Apache.
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
Start Nagios Core service
Start and enable Nagios service to run on system boot.
systemctl enable nagios --now
To check the status
systemctl status nagios
● nagios.service - Nagios Core 4.4.5
Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2019-10-19 01:58:43 EDT; 27s ago
Docs: https://www.nagios.org/documentation
Process: 31542 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
Process: 31540 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
Main PID: 31543 (nagios)
Tasks: 6 (limit: 24012)
Memory: 2.7M
CGroup: /system.slice/nagios.service
├─31543 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
├─31544 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
├─31545 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
├─31546 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
├─31547 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
└─31548 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
You can check Nagios logs at /usr/local/nagios/var/nagios.log
.
Accessing Nagios on CentOS 9 Stream
You can now access your Nagios server from the browser using the address http://<server-IP or HOSTNAME>/nagios
.
You will be prompted to enter username and password created above to login.
Enter the authentication credentials and proceed to Nagios web interface.
Huraay!! Nagios is installed on CentOS 9 Stream. So what is next?
Monitoring Endpoints using Nagios
The next step would now be to start monitoring your end points with nagios. This involves installing Nagios plugins and the NRPE plugins.
Localhost, which is the Nagios server itself, will be monitored by default.
To start monitoring your endpoints, you need Nagios plugins installed, which is not, by default.
If you can check, even the status of the localhost and services are down since no Nagios plugins are installed.
Host checks:
Service Checks:
Next, install Nagios plugins so as to monitor state of the host and services.
Install Nagios Plugins on CentOS 9 Stream
That marks the end of our tutorial on how to install Nagios Server.
You can also check other Nagios Tutorials by following the links below;
Install Nagios Core on Debian 10 Buster
Monitor Linux Hosts using Nagios check_by_ssh Plugin
How to Install and Configure Nagios Core From repo Ubuntu 18.04
How to Install and Configure Nagios Core From the Source Ubuntu 18.04