How to Install Nagios 4.4.5 on RHEL/CentOS 8/7 and Fedora 30

Nagios is an awesome Open Source monitoring tool, it provides you more comprehensive monitoring environment to always keep an eye on your all machines/networks whether you are in your data center or just your small labs.

With Nagios, you can monitor your remote hosts and their services remotely on a single window. It shows warnings and indicates if something goes wrong in your servers which eventually helps us to detect some problems before they occur. It helps us to reduce downtime and business losses.

Recently, Nagios released its latest versions Nagios Core 4.4.5 and its latest stable release of Nagios plugins 2.2.1 on August 20, 2019.

This article is intended to guide you with easy instructions on how to install the latest Nagios Core 4.4.5 from source (tarball) on RHEL 8/7/6, CentOS 8/7/6 and Fedora 26-30 distributions.

Within 30 minutes you will be monitoring your local machine, no advanced installation procedure only basic installation that will work 100% on most of today’s Linux servers.

Please Note: The installation instructions were shown in here are written based on CentOS 7.5 Linux distribution.

Installing Nagios 4.4.5 and Nagios Plugin 2.2.1

If you follow these instructions correctly, you will end up with the following information.

  1. Nagios and its plugins will be installed under /usr/local/nagios directory.
  2. Nagios will be configured to monitor few services of your local machine (Disk Usage, CPU Load, Current Users, Total Processes, etc.)
  3. Nagios web interface will be available at http://localhost/nagios

Step 1: Install Required Dependencies

We need to install Apache, PHP and some libraries like gcc, glibc, glibc-common and GD libraries and its development libraries before installing Nagios 4.4.5 with the source. And to do so, we can use yum default package installer.

[[email protected]]# yum install -y httpd httpd-tools php gcc glibc glibc-common gd gd-devel make net-snmp

-------------- On Fedora -------------- 
[[email protected]]# dnf install -y httpd httpd-tools php gcc glibc glibc-common gd gd-devel make net-snmp

Step 2: Create Nagios User and Group

Create a new nagios user using useradd command and nagcmd group account and set a password.

[[email protected]]# useradd nagios
[[email protected]]# groupadd nagcmd

Next, add both the nagios user and the apache user to the nagcmd group using usermod command.

[[email protected]]# usermod -G nagcmd nagios
[[email protected]]# usermod -G nagcmd apache

Step 3: Download Nagios Core 4.4.5 and Nagios Plugin 2.2.1

Create a directory for your Nagios installation and all its future downloads.

[[email protected]]# mkdir /root/nagios
[[email protected]]# cd /root/nagios

Now download latest Nagios Core 4.4.5 and Nagios plugins 2.2.1 packages with wget command.

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

Step 4: Extract Nagios Core and its Plugins

We need to extract downloaded packages with tar command as follows.

[[email protected] nagios~]# tar -xvf nagios-4.4.5.tar.gz
[[email protected] nagios~]# tar -xvf nagios-plugins-2.2.1.tar.gz

When you extract these tarballs with tar command, two new folders will appear in that directory.

[[email protected] nagios ~]# ls -l
total 13520
drwxrwxr-x 18 root root     4096 Aug 20 17:43 nagios-4.4.5
-rw-r--r--  1 root root 11101966 Aug 20 17:48 nagios-4.4.5.tar.gz
drwxr-xr-x 15 root root     4096 Apr 19 12:04 nagios-plugins-2.2.1
-rw-r--r--  1 root root  2728818 Apr 19 12:04 nagios-plugins-2.2.1.tar.gz

Configure Nagios Core

Now, first we will configure Nagios Core and to do so we need to go to Nagios directory and run configure file and if everything goes fine, it will show the output in the end as sample output. Please see below.

[[email protected] nagios~]# cd nagios-4.4.5/
[[email protected] nagios-4.4.5 ]# ./configure --with-command-group=nagcmd
Sample output:
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/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):  /usr/bin/traceroute


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

After configuring, we need to compile and install all the binaries with make all and make install command, it will install all the needed libraries in your machine and we can proceed further.

[[email protected] nagios-4.4.5 ]# make all
[[email protected] nagios-4.4.5 ]# make install
Sample output:
*** Compile finished ***

If the main program and CGIs compiled without any errors, you
can continue with testing or installing Nagios as follows (type
'make' without any arguments for a list of all possible options):

  make test
     - This runs the test suite

  make install
     - This installs the main program, CGIs, and HTML files

  make install-init
     - This installs the init script in /lib/systemd/system

  make install-daemoninit
     - This will initialize the init script
       in /lib/systemd/system

  make install-groups-users
     - This adds the users and groups if they do not exist

  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file

  make install-config
     - This installs *SAMPLE* config files in /usr/local/nagios/etc
       You'll have to modify these sample files before you can
       use Nagios.  Read the HTML documentation for more info
       on doing this.  Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!

  make install-webconf
     - This installs the Apache config file for the Nagios
       web interface

  make install-exfoliation
     - This installs the Exfoliation theme for the Nagios
       web interface

  make install-classicui
     - This installs the classic theme for the Nagios
       web interface

The following command will install the init scripts for Nagios.

[[email protected] nagios-4.4.5 ]# make install-init

To make Nagios work from command line we need to install command-mode.

[[email protected] nagios-4.4.5 ]# make install-commandmode

Next, install sample Nagios files, please run following command.

[[email protected] nagios-4.4.5 ]# make install-config
Sample output:
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

*** Config files installed ***

Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

Step 5: Customizing Nagios Configuration

Open the “contacts.cfg” file with your choice of editor and set the email address associated with the nagiosadmin contact definition to receiving email alerts.

# vi /usr/local/nagios/etc/objects/contacts.cfg
Sample Output
###############################################################################
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################

# Just one contact defined by default - the Nagios admin (that's you)
# This contact definition inherits a lot of default values from the 'generic-contact'
# template which is defined elsewhere.

define contact{
       contact_name                    nagiosadmin             ; Short name of user
       use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
       alias                           Nagios Admin            ; Full name of user

       email                           [email protected]     ; *** CHANGE THIS TO YOUR EMAIL ADDRESS ****
       }

Step 6: Install and Configure Web Interface for Nagios

We are done with all configuration in the backend, now we will configure Web Interface For Nagios with the following command. The below command will Configure Web interface for Nagios and a web admin user will be created “nagiosadmin”.

[[email protected] nagios-4.4.5 ]# make install-webconf

In this step, we will be creating a password for “nagiosadmin”. After executing this command, please provide a password twice and keep it remember because this password will be used when you login in the Nagios Web interface.

[[email protected] nagios-4.4.5]# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

Restart Apache to make the new settings take effect.

[[email protected] nagios-4.4.5]# service httpd start               [On RHEL/CentOS 6]
[[email protected] nagios-4.4.5]# systemctl start httpd.service     [On RHEL/CentOS 7/8 and Fedora]

Step 7: Compile and Install Nagios Plugin

We have downloaded Nagios plugins in /root/nagios, Go there and configure and install it as directed below.

[[email protected] nagios-4.4.5]# cd /root/nagios
[[email protected] nagios]# cd nagios-plugins-2.2.1/
[[email protected] nagios-plugins-2.2.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[[email protected] nagios-plugins-2.2.1]# make
[[email protected] nagios-plugins-2.2.1]# make install

Step 8: Verify Nagios Configuration Files

Now we are all done with Nagios configuration and its time to verify it and to do so please insert following command. If everything goes smooth it will show up similar to below output.

[[email protected] nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Sample 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 9: Add Nagios Services to System Startup

To make Nagios work across reboots, we need to add nagios and httpd with chkconfig and systemctl command.

On RHEL/CentOS 6
[[email protected] ]# chkconfig --add nagios
[[email protected] ]# chkconfig --level 35 nagios on
[[email protected] ]# chkconfig --add httpd
[[email protected] ]# chkconfig --level 35 httpd on
On RHEL/CentOS 7/8 and Fedora
[[email protected] ]# systemctl enable nagios
[[email protected] ]# systemctl enable httpd

Restart Nagios to make the new settings take effect.

[[email protected] ]# service nagios start              [On RHEL/CentOS 6]
[[email protected] ]# systemctl start nagios.service    [On RHEL/CentOS 7/8 and Fedora]

Step 10: Login to the Nagios Web Interface

Your Nagios is ready to work, please open it in your browser with “http://Your-server-IP-address/nagios” or “http://FQDN/nagios” and Provide the username “nagiosadmin” and password.

Nagios Web Dashboard
Nagios Dashboard

Nagios Dashboard

Host View
Nagios Host View

Nagios Host View

Nagios Overview
Nagios Overview

Nagios Overview

Services View
Nagios Host Services

Nagios Host Services

Process View
Nagios Process View

Nagios Process View

Congratulations! You’ve successfully installed and configured Nagios and its Plugins. You’ve just started your journey into monitoring.

Upgrade Nagios 3.x to Nagios 4.4.5

If you are already running an older version of Nagios, you can upgrade it anytime. To do so, you just need to download the latest tar archive of it and configure it as shown below.

[[email protected] ]# service nagios stop
[[email protected] ]# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.5.tar.gz
[[email protected] ]# tar -zxvf nagios-4.4.5.tar.gz
[[email protected] ]# cd nagios-4.4.5
[[email protected] ]# ./configure
[[email protected] ]# make all
[[email protected] ]# make install
[[email protected] ]# service nagios start

That’s it for now, in my upcoming articles, I will show you how to add Linux, Windows, Printers, Switches, and Devices to Nagios monitoring Server. If you’re having any trouble while installing, please do contact us via comments. Till then stay tuned and connected to Tecmint and don’t forget to Like and Share us to spread around.

Read Also:

  1. How to Add Linux Host to Nagios Monitoring Server
  2. How to Add Windows Host to Nagios Monitoring Server

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

403 Responses

  1. Raju says:

    Hi,

    I installed the Nagios and everything goes okay but when i open it browser in Google Chrome it show this message

    Not Found
    The requested URL /nagios was not found on this server.
    

    What can i do now?

    • Ravi Saive says:

      @Raju,

      It’s clear that your Nagios installation wasn’t successful, try to follow Nagios installation instructions carefully..

  2. Aldo says:

    someone nows how to monitor a router that is out off my local network?

  3. Arjun says:

    Reusing existing connection to assets.nagios.com:443.
    HTTP request sent, awaiting response… 404 Not Found
    2017-12-24 01:19:38 ERROR 404: Not Found.

  4. shuja says:

    getting below error while running above command

    /usr/local/nagios/etc/nagios.cfg
    /usr/local/nagios/etc/nagios.cfg: line 1144: syntax error near unexpected token `|’
    /usr/local/nagios/etc/nagios.cfg: line 1144: `illegal_macro_output_chars=`~$&|'”‘

  5. Bharath HJ says:

    From command line [using links] I am able to access nagios, but the same fails when I try to hit the URL from a remote host.

    When trying to access nagios from remote host via browser, after entering credentials for nagiosadmin on browser- receiving a blank page [connection reset]. Log shows that it might be failing to load main.php and side.php after user authorization.
    Any suggestions please on what can be the issue?

    Troubleshooting steps tried so far:
    – Able to access a static php from remote host via browser
    – Tried from different browsers [Mozilla, Chrome, IE]
    – Able to telnet from remote host to server [Port 80]
    – Provided all access to files [/usr/local/nagios/etc/htpasswd.users, /usr/local/nagios/share/main.php, side.php]
    – Both server and remote hosts are on the same timezone
    – HTTP is running as user -apache

    Versions installed: nagios-4.3.4, nagios-plugins-2.2.1
    OS: RHEL 6.9
    Packages installed: httpd, httpd-tools, php, gcc, glibc, glibc-common, gd, gd-devel, make, net-snmp

    Logs when accessing on local using command line [links]
    [23/Nov/2017:09:34:34 +0000] “GET /nagios HTTP/1.1” 401 482 “-” “Links (2.13; Linux; GNU C 4.4.7; text)”
    nagiosadmin [23/Nov/2017:09:34:42 +0000] “GET /nagios HTTP/1.1” 301 318 “-” “Links (2.13; Linux; GNU C 4.4.7; text)”
    nagiosadmin [23/Nov/2017:09:34:42 +0000] “GET /nagios/ HTTP/1.1” 200 1079 “-” “Links (2.13; Linux; GNU C 4.4.7; text)”
    nagiosadmin [23/Nov/2017:09:34:42 +0000] “GET /nagios/side.php HTTP/1.1” 200 4735 “http://xx.xx.xx.xx/nagios/” “Links (2.13; Linux; GNU C 4.4.7; text)”
    nagiosadmin [23/Nov/2017:09:34:42 +0000] “GET /nagios/main.php HTTP/1.1” 200 7993 “http://xx.xx.xx.xx/nagios/” “Links (2.13; Linux; GNU C 4.4.7; text)”

    Logs when accessing from remote host.
    [23/Nov/2017:09:59:31 +0000] “GET /nagios HTTP/1.1” 401 482 “-” “Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0”
    nagiosadmin [23/Nov/2017:09:59:39 +0000] “GET /nagios HTTP/1.1” 301 318 “-” “Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0”

    • Ravi Saive says:

      @Bharat,

      Please check the firewall rules, something is blocking accessing from remote host..

      • Bharath HJ says:

        Thanks Ravi,

        I did check firewall rules and they are disabled.
        Though I am still unable to connect to console after entering nagiosadmin credentials.

        Current status on nagios server::
        # /sbin/service iptables status
        iptables: Firewall is not running.
        :
        # sestatus
        SELinux status: disabled
        :
        # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
        Nagios Core 4.3.4
        Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
        Copyright (c) 1999-2009 Ethan Galstad
        Last Modified: 2017-08-24
        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

        Not sure why I am able to access a static php from my remote host hosted using the same httpd.conf on the nagios server, but unable to hit /nagios.

        It does prompt for user credentials but does not load the nagios console.

  6. imtiyaj says:

    Dear Sir,

    Thank you for valuable. Nagios configuration is done properly. Please help to how to add servers and services in Nagios.

    How to create Nagios database ? In new configure Nagios, no database was created in Mysql.

  7. shuja says:

    Hi,

    I installed and configured Nagios but my localhost is showing down. can u tell me how to bring it up or into monitoring

    • Ravi Saive says:

      @Shuja,

      Please verify Nagios configuration for errors using following command, if any errors shown, fix it accordingly.

      # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
      
      • shuja says:

        /usr/local/nagios/etc/nagios.cfg
        /usr/local/nagios/etc/nagios.cfg: line 1144: syntax error near unexpected token `|’
        /usr/local/nagios/etc/nagios.cfg: line 1144: `illegal_macro_output_chars=`~$&|’”‘

  8. imtiyaj says:

    Dear Sir,

    Thank you for information. Please share information about how to add hosts and it’s respective services in Nagios latest version.

  9. Arun Mohan says:

    thanks…its working fine

  10. Umer says:

    All installation steps goes fine.

    When I execute command systemctl enable nagios it shows error.

    Failed to execute operation: Access denied

    please help as soon as possible.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

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