How to Install Nagios Core on CentOS 7

In this tutorial, We are going to perform How to download and Install Nagios Core on CentOS 7 or any Cloud Instance like Amazon EC2, Azure VM, Google Compute Engine,etc. with preinstalled CentOS 7 Step by Step.

Introduction

Nagios Core is free and open source monitoring tools which is used to monitor the System resources, applications ,Services, Databases and network devices such asRouters,switches,..etc.

Using Nagios Core we can monitor below resources and Network Ports.

Resources:

  • CPU utilization
  • Memory utilization
  • Disk utilization
  • Logged in users
  • Running processes
  • System Uptime
  • Service states
  • Swap utilization

Network Ports:

  • HTTP
  • FTP
  • SSH
  • SMTP
  • Ping
  • Bandwidth Latency
  • Mysql
  • IMAP
  • POP3
  • Tomcat
  • PHP wrapper
  • MySQL

Prerequisites

  • CentOS 7 Server
  • Preinstalled http
  • 1 CPU and 2 GB RAM
  • Firewall Ports 80,443,5666

Before installing Nagios, update the System and Install the below per-requisite packages .

$ sudo yum update
$ sudo yum install -y gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix

Install unzip packages if not installed

$ sudo yum install unzip

Disable SELinux

# sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config

OR

Set in permissive mode.

$ setenforce 0

Step 1: Create Nagios User and Group

Enter below command to create Nagios user and group and add www-data user to nagios group.

$ sudo useradd nagios
$ sudo groupadd nagios
$ sudo make install-groups-users
$ sudo usermod -a -G nagios www-data

Step 2: Download and Install Nagios Core on CentOS 7

Here We are downloading Nagios Core 4.4.5 setup, To download latest version visit Officical Nagios Site

Navigate to /tmp directory

$ cd /tmp

Download and Extract the Nagios Core Setup

$ sudo wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.5.tar.gz
$ tar xzf nagioscore.tar.gz
$ cd /tmp/nagioscore-nagios-4.4.5/

Compile the Nagios Core and Install

$ sudo ./configure --with-nagios-group=nagios --with-command-group=nagios --with-httpd_conf=/etc/apache2/sites-enabled/
$ sudo make all
$ sudo make install
$ sudo make install-daemoninit
$ make install-commandmode

Step 3: Install and Configure Apache Files

Install and configure apache files using below commands,

$ sudo make install-webconf

Restart an Apache to take effect

$ sudo systemctl start httpd.service

Step 4: Create User Account to Access Nagios Web Interface

We have to create user in apache and set password. Enter below command for same.

$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Output:

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

Step 5: Download and Install Nagios Plugins

Navigate to /tmp directory, Download the nagios core plugin and extract it as shown below

$ cd /tmp
$ sudo wget --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.2.1.tar.gz
$ tar zxf nagios-plugins.tar.gz

Compile and install nagios core plugins,

$ cd /tmp/nagios-plugins-release-2.2.1/
$ sudo ./tools/setup
$ sudo ./configure
$ sudo make
$ sudo make install

Step 6: Verify Nagios Configuration, Start Nagios and Enable

Verify the Nagios core configuration using below command,

$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Output:

$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

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

To start Nagios Service

$ sudo systemctl start nagios

To enable nagios service at system startup

$ sudo systemctl enable nagios

Step 7: Configure Firewall

Allow http port to access Nagios web interface, if you are configuring Nagios on Cloud Instance allow 80 port in inbound rules.

$ sudo firewall-cmd --zone=public --add-port=80/tcp
$ sudo firewall-cmd --zone=public --add-port=80/tcp --permanent

Reload the firewall settings to take effect

$ sudo firewall-cmd --reload

Step 8: Accessing Nagios Web Interface

To access nagios web interface, Open your favorite browser and type your server name or IP followed by nagios/

http://Server_IP/nagios

OR

http://Domain_Name/nagios

Once you hit above URL, Enter the credentials of “nagiosadmin” user and you will be redirected to nagios default page.

To Monitor the services. go to Current status -> Services at left pane as shown below

nagios core web interface

Related Articles:

How to download and Install Nagios on Ubuntu 18.04/16.04 LTS

How to Install Netdata On Ubuntu

How to Install ELK Stack on Ubuntu

How to Install Splunk on Ubuntu 18.04/16.04 LTS

How to Install Splunk Enterprise on CentOS 7

Reference:

https://support.nagios.com/kb/article/nagios-core-installing-nagios-core-from-source-96.html

FOSS TechNix

FOSS TechNix (Free,Open Source Software's and Technology Nix*) founded in 2019 is a community platform where you can find How-to Guides, articles for DevOps Tools,Linux and Databases.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link