We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

23
813.156,35

Cart

Quantity 116,00

Learn how to – Install Nagios Server on Rocky Linux 9 / AlmaLinux 9

Learn how to – Install Nagios Server on Rocky Linux 9 / AlmaLinux 9.

Monitoring plays an important role in any environment as it helps improve and maintain the performance and health of servers/applications. This is due to the fact that many organizations depend on applications to run their businesses. There are many monitoring solutions that one can use, they include New Relic, Zenoss, Elastic Stack, Dynatrace, Prometheus, N-able RMM, Zabbix, PRTG Network Monitor, Nagios, Datadog Infrastructure Monitoring e.t.c

Nagios is an open-source monitoring solution designed to run on Linux. It can be used to monitor Windows, Linux, and Unix operating systems. Nagios previously known as NetSaint was developed by Ethan Galstad and first released in 1999. This project was then refined by several contributors as an open-source project. The Nagios Enterprise is a company based around the Nagios Core technology and offers several products such as Log Server, XI, Fusion, and Network Analyzer.

This software is designed to run periodic checks on the vital parameters of a network, application, or server. These parameters include microprocessor load, the number of running processes, log files, disk and memory usage e.t.c. It can also be used to monitor services that include Simple Mail Transfer Protocol (SMTP), Hypertext Transfer Protocol (HTTP), Post Office Protocol 3 (POP3), and many other services.

Nagios works with the server-agent architecture where the server is installed on the host system and plugins installed on the remote system to be monitored. Signals are sent from the server to the plugins via a process scheduler. The plugins have the responsibility to collect the data and send it back to the scheduler. The process scheduler then sends the notifications to the admin and updates the Nagios GUI.

The below diagram can be used to demonstrate how Nagios works.

This tuitorial demonstrates how to install Nagios Server on Rocky Linux 9 / AlmaLinux 9.

#1. Install Required Packages

Before we begin, ensure the system and all the available packages are updated to their latest available versions;

sudo dnf update -y

Set SELinux in permissive mode:

sudo sed -i 's/SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config
sudo setenforce 0

Install the required packages such as Apache and other build tools

sudo dnf -y install unzip tar httpd httpd-tools php gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel

Once the instalation is complete, start and enable Apache and PHP-FPM:

sudo systemctl enable --now httpd php-fpm

#2. Download Nagios Core Source Code

To download the latest source code for Nagios Core, navigate to the Nagios Downloads page. Alternatively, you can obtain the latest release version and export it with the command:

VER=4.4.7

Once exported, download the version with the command:

wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-$VER.tar.gz

Extract the archive:

tar xzf nagios-$VER.tar.gz

#3. Install Nagios Core on Rocky Linux 9 / AlmaLinux 9

We will begin by configuiring the core to adapt to the system and check if all the required packages have been installed.

cd nagios-$VER/
./configure

Once successful, you will see the below summary:

Now compile the Nagios Core

make all

Add a Nagios User and group to system.

sudo make install-groups-users

Add the Apache user to the Nagios group created.

sudo usermod -aG nagios apache

Now install the Nagios Core by executing the command:

sudo make install

Install the init scripts for Nagios.

sudo make install-init

Install the external command file and permissions;

sudo make install-commandmode

Install the Nagios configuration files:

sudo make install-config

Finally, install the Apache configuration files for Nagios:

sudo make install-webconf

#4. Install Nagios Plugins on Rocky Linux 9 / AlmaLinux 9

The Plugins are used to collct montoring information form the server. To collect the monitoring data form the localhost, you can install the Nagios Plugins as shown. First downlaod the latest socuce code from the Nagios Plugins page

wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz

Extract the archive:

tar -xvf nagios-plugins-*.tar.gz

Navigate into the directory;

cd nagios-plugins-*/

Create the required directory with proper permissions:

mkdir -p /usr/local/nagios/var/spool/checkresults
sudo chown -R nagios:nagios /usr/local/nagios/var/spool/checkresults

Configure and install the the Nagios plugins

./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
sudo make install

#5. Create the Nagios Web User

Inorder to access the Nagios web dashboard, we are required to create a user account. This user account will be used for authentication.

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

The default name for the user is nagiosadmin. You can use another username by replacing all the instances of nagiosadmin in the /usr/local/nagios/etc/cgi.cfg file by the preferred username.

Allow apache to access the configurations file by setting the correct ownership and permissions.

sudo chown apache:apache /usr/local/nagios/etc/htpasswd.users
sudo chmod 640 /usr/local/nagios/etc/htpasswd.users

For the changes made to apply, restart Apache:

sudo systemctl restart httpd

Allow the HTTP service through the firewall:

sudo firewall-cmd --add-port=80/tcp --permanent
sudo firewall-cmd --reload

Start and enable the Nagios service.

sudo systemctl enable nagios --now

Reboot the system:

sudo reboot now

Once the system reboots, verify if the service is running:

$ systemctl status nagios
● nagios.service - Nagios Core 4.4.7
     Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; vendor preset: disabled)
     Active: active (running) since Thu 2022-08-25 09:38:32 CEST; 27s ago
       Docs: https://www.nagios.org/documentation
    Process: 873 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
    Process: 880 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
   Main PID: 882 (nagios)
      Tasks: 6 (limit: 48184)
     Memory: 5.1M
        CPU: 22ms
     CGroup: /system.slice/nagios.service
             ├─882 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
             ├─883 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─884 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─885 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─886 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             └─892 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

#6. Access the Nagios Web Interface

Now you can access the Nagios web UI using the URL http://IP_Address/nagios/. You will be required to login using the nagiosadmin user as shown.

On sucessful login, you wil see the below dashboard.

View the host availability;

Check the collected data under services:

You have successfully install the Nagios Server on Rocky Linux 9 / AlmaLinux 9. The next steps involves configuring end points to be monitored.

#7. Configure Rocky Linux 9 / AlmaLinux 9 Nagios Agent

For an agent to be monitored. you need to have the below installed:

  • Nagios plugins for data collection
  • NRPE Agent to execute the plugins

There are two ways to install Nagios Plugins on Rocky Linux 9 / AlmaLinux 9. These are; using source code or installing from the EPEL repo.

In this guide, we will use the easiest way, that is, using the EPEL repo. Enable the EPEL repo on Rocky Linux 9 / AlmaLinux 9.

sudo dnf install epel-release

Once enabled, find the availabe Nagios plugins:

$ dnf list nagios-plugins-*
Available Packages
nagios-plugins-all.x86_64                          2.4.0-5.el9              epel
nagios-plugins-apt.x86_64                          2.4.0-5.el9              epel
nagios-plugins-breeze.x86_64                       2.4.0-5.el9              epel
nagios-plugins-by_ssh.x86_64                       2.4.0-5.el9              epel
nagios-plugins-cluster.x86_64                      2.4.0-5.el9              epel
nagios-plugins-dhcp.x86_64                         2.4.0-5.el9              epel
nagios-plugins-dig.x86_64                          2.4.0-5.el9              epel
nagios-plugins-disk.x86_64                         2.4.0-5.el9              epel
nagios-plugins-disk_smb.x86_64                     2.4.0-5.el9              epel
nagios-plugins-dns.x86_64                          2.4.0-5.el9              epel
nagios-plugins-dummy.x86_64                        2.4.0-5.el9              epel
nagios-plugins-file_age.x86_64                     2.4.0-5.el9              epel
nagios-plugins-flexlm.x86_64                       2.4.0-5.el9              epel
......

Now install the preferred Nagios plugins. For example the plugins to check the processes, disk space, swap space, dns, users, uptime, httpand load, use the command:

sudo dnf install nagios-plugins-{load,http,users,procs,disk,swap,nrpe,uptime,dns}

Once installed, the packages will be stored under the path /usr/lib64/nagios/plugins/:

$ ls -1 /usr/lib64/nagios/plugins/
check_disk
check_dns
check_http
check_load
check_nrpe
check_procs
check_swap
check_uptime
check_users
eventhandlers
negate
urlize
utils.sh

Also the Nagios NRPE Agent can be installed from the source code and from the EPEL. Installing it from the EPEL repo is easier and can be accomplished with the command:

sudo dnf install nrpe

Once installed, verify with the command:

$ nrpe -V
NRPE - Nagios Remote Plugin Executor
Version: 4.1.0

Start and enable the service:

sudo systemctl enable nrpe --now

Verify if the service is running:

$ systemctl status nrpe
 nrpe.service - Nagios Remote Plugin Executor
     Loaded: loaded (/usr/lib/systemd/system/nrpe.service; enabled; vendor preset: disabled)
     Active: active (running) since Thu 2022-08-25 11:26:52 CEST; 5s ago
       Docs: http://www.nagios.org/documentation
   Main PID: 2159 (nrpe)
      Tasks: 1 (limit: 23441)
     Memory: 1.3M
        CPU: 8ms
     CGroup: /system.slice/nrpe.service
             └─2159 /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -f

Allow the service through the firewall:

sudo firewall-cmd --add-port=5666/tcp --permanent
sudo firewall-cmd --reload

Now on the Nagios server, add the remote host by creating a new object at /usr/local/nagios/etc/objects. For example:

sudo vim /usr/local/nagios/etc/objects/nodes.cfg

Add the below lines replacing appropriately:

# REMOTE HOST DEFINITION
define host {
    use                     linux-server
    host_name               node1.learnhowto-demo.com
    alias                   node1
    address                 192.168.205.13
}
# REMOTE HOST GROUP DEFINITION
define hostgroup {
    hostgroup_name         linux-servers
    alias                  Linux Servers
    members                node1.learnhowto-demo.com 
}
define service {

    use                     local-service           ; Name of service template to use
    host_name               node1.learnhowto-demo.com
    service_description     PING
    check_command           check_ping!100.0,20%!500.0,60%
}

define service {

    use                     local-service           ; Name of service template to use
    host_name               node1.learnhowto-demo.com
    service_description     Root Partition
    check_command           check_local_disk!20%!10%!/
}

define service {

    use                     local-service           ; Name of service template to use
    host_name             node1.learnhowto-demo.com
    service_description     Current Users
    check_command           check_local_users!20!50
}
define service {

    use                     local-service           ; Name of service template to use
    host_name               node1.learnhowto-demo.com
    service_description     Total Processes
    check_command           check_local_procs!250!400!RSZDT
}

define service {

    use                     local-service           ; Name of service template to use
    host_name               node1.learnhowto-demo.com
    service_description     Current Load
    check_command           check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
define service {

    use                     local-service           ; Name of service template to use
    host_name               node1.learnhowto-demo.com
    service_description     Swap Usage
    check_command           check_local_swap!20%!10%
}

define service {

    use                     local-service           ; Name of service template to use
    host_name               node1.learnhowto-demo.com
    service_description     SSH
    check_command           check_ssh
    notifications_enabled   0
}
define service {

    use                     local-service           ; Name of service template to use
    host_name               node1.learnhowto-demo.com
    service_description     HTTP
    check_command           check_http
    notifications_enabled   0
}

In the above file, use local-service defines the template to be used by the added hosts. The templates are define int the default templates directory. You can also create custorm templates to be used.

Allow the Nagios server to use the config by making the below changes to the conf:

sudo vim /usr/local/nagios/etc/nagios.cfg

Add the below lines:

.....
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/nodes.cfg

Comment out the localhost.cfg to allow the remote host added to be used. Save the file and restart Nagios.

sudo systemctl restart nagios

Now from the Nagios web UI, you can perform monitoring on the added host(s). The host takes sometime to become available.

The services will also be availabe as shown.

Closing Thoughts

That marks the end of this guide on how to install Nagios Server on Rocky Linux 9 / AlmaLinux 9. We have also gone through how to configure a remote endpoint to be monitored. I hope this was significant to you.

See more:

Install and Configure Nagios 4 on Debian

Install and Configure Nagios 4 on Ubuntu

Install Graphite & Graphite-Web on CentOS 8 | RHEL 8

23
813.156,35

Cart

Quantity 116,00