Nagios Core (formerly known as Nagios) is an open-source monitoring tool that is used to monitor servers and networks, whether it is in a data center or a small business organization.

Nagios Core provides the feature to manage the remote server and its services on a single Dashboard. If your server has any issues, Nagios Core will provide a warning on the Dashboard, allowing you to track the issue before it can cause more serious trouble. Hence, you can reduce downtime.

With Nagios Core, you can monitor Disk Usage, CPU Load, Current Users, Total Processes, etc. 

In the following steps, we will install Nagios Core 4.4.5 on CentOS 7/AlmaLinux: 

Install Required Dependencies 

Step 1: Before installing Nagios Core 4.4.5, we will need to install its required dependencies, including Apache, PHP, and some libraries such as gcc, glibc, glibc-common, and GD using YUM.

# sudo yum install -y httpd httpd-tools php gcc glibc glibc-common gd gd-devel make net-snmp      (CentOS)
# sudo dnf install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp unzip wget tar   (AlmaLinux)

 

Create a User and Group for Nagios

We will create a user Nagios with its password and its group nagapp.

Step 1: Use the command below to add the user and group:

# sudo useradd nagios
# sudo groupadd nagapp

Step 2: Add Nagios user and Apache user in the group nagapp with the below command:

# sudo usermod -G nagapp nagios      (CentOS)
# sudo usermod -G nagapp apache
# sudo usermod -aG nagapp nagios     (AlmaLinux)
# sudo usermod -aG nagapp apache

Step 3: Download Nagios Core 4.4.5 with Nagios Plugin 2.2.1 using this command:

# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.5.tar.gz
# wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

Step 4: Extract both packages with tar.

# tar -xvf nagios-4.4.5.tar.gz
# tar -xvf nagios-plugins-2.2.1.tar.gz

 

Configure Nagios 

Step 1: First, configure Nagios, and go inside the Nagios directory using the cd command.

# cd nagios-4.4.5/

Step 2: Run this command to configure Nagios core 4.4.5:

# ./configure --with-command-group=nagapp

If everything goes fine, it will give the output as shown below

          Creating sample config files in sample-config/ ...
*** Configuration summary for nagios 4.4.5 2019-08-20 ***:
 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagcmd
             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:  /usr/sbin/sendmail
                  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):    

Step 3: Run the make all and make install commands to compile and install all the binaries. This will install the required libraries on your server.

# sudo make all
# sudo make install

Step 4: Let us install init scripts for Nagios with the commands given below:

# sudo make install-init

Step 5: Execute the following command to run Nagios in the command line:

# sudo make install-commandmode

Step 6: At the next step, run this command to install sample Nagios files:

# sudo make install-config

Customize Nagios Configuration

We will add the email account where you want to receive the Nagiosadmin email alerts.

Step 1: Edit the contacts.cfg file with this command:

# sudo vi /usr/local/nagios/etc/objects/contacts.cfg

Step 2: Run this command to install the web interface for Nagios: 

# sudo make install-webconf

Step 3: Create a password for the nagiosadmin. We will use this password while accessing the web interface.

# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Adding a password for the user nagiosadmin

Step 4: Restart the Apache service, so our configuration setting takes effect.

# sudo systemctl start httpd

 

Compile and Install Nagios Plugin 

We have already downloaded the Nagios plugin.

Step 1: Now, go to its directory and install it as per the following commands:

# cd /nagios-plugins-2.2.1
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

Step 2; Now, we will verify the Nagios configuration files. You will see the following output if your setup is fine.

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Output :
Nagios Core 4.4.5
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2019-08-20
License: GPL

Website: https://www.nagios.org
Reading configuration data...
Read main config file okay...
Read object config files okay...
Running pre-flight check on configuration data...

Checking objects...
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 contact groups.
Checked 24 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check 

Step 3: Start and enable the Nagios and Apache services on boot.

# sudo systemctl enable nagios
# sudo systemctl enable httpd

Step 4: Finally, restart the Nagios service to take effect all the settings.

# sudo systemctl enable nagios
# sudo systemctl start nagios

We have completed the Nagios installation on the server.

Now, we can access it using http://IPAddress/nagios

nagios-web.png

Was this answer helpful? 0 Users Found This Useful (0 Votes)