VOOZH about

URL: https://www.tecmint.com/install-nagios-in-linux/

⇱ How to Install Nagios in RHEL, Rocky, and AlmaLinux


Skip to content

Nagios is an awesome Open Source monitoring tool, that provides a 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.

[ You might also like: 22 Linux Networking Commands for Sysadmin ]

Recently, Nagios released its latest version Nagios Core 4.4.9, and its latest stable release of Nagios plugins 2.3.3 on October 4, 2022.

This article is intended to guide you with easy instructions on how to install and configure the latest version of Nagios Core from source (tarball) on RHEL and RHEL-based distributions such as CentOS Stream, Rocky Linux, AlmaLinux, and Fedora.

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 shown here are written based on the RHEL 9.0 Linux distribution.

[ez-toc]

Installing Nagios Core and Nagios Plugin in Linux

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

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

Step 1: Install Apache and PHP Packages

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

# yum install -y httpd httpd-tools php gcc glibc glibc-common gd gd-devel make net-snmp
👁 Install Apache and PHP
Install Apache and PHP

Step 2: Create Nagios User and Group

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

[root@tecmint]# useradd nagios
[root@tecmint]# groupadd nagcmd

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

[root@tecmint]# usermod -G nagcmd nagios
[root@tecmint]# usermod -G nagcmd apache
👁 Add Nagios User and Group
Add Nagios User and Group

Step 3: Download Nagios Core and Nagios Plugin

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

[root@tecmint]# mkdir /root/nagios
[root@tecmint]# cd /root/nagios

Now download the latest Nagios Core and Nagios Plugins packages with the wget command.

# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.9.tar.gz
# wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
👁 Download Nagios Core and Nagios Plugins
Download Nagios Core and Nagios Plugins

Step 4: Extract Nagios Core and Nagios Plugins

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

# tar -xf nagios-4.4.9.tar.gz
# tar -xf nagios-plugins-2.3.3.tar.gz

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

# ls -l

total 13804
drwxrwxr-x 21 root root 4096 Nov 17 02:22 nagios-4.4.9
-rw-r--r-- 1 root root 11339450 Nov 17 03:08 nagios-4.4.9.tar.gz
drwxr-xr-x 15 root root 4096 Mar 11 2020 nagios-plugins-2.3.3
-rw-r--r-- 1 root root 2782610 Mar 11 2020 nagios-plugins-2.3.3.tar.gz

Step 5: Installing and Configuring Nagios Core

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

# cd nagios-4.4.9/
# ./configure --with-command-group=nagcmd
👁 Configure Nagios Core
Configure Nagios Core
Configuration Summary for Nagios Core
Creating sample config files in sample-config/ ...


*** Configuration summary for nagios 4.4.9 2022-11-16 ***:

 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 the 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): 


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 the make all and make install commands, it will install all the needed libraries in your machine and we can proceed further.

# make all
# make install
Nagios Compilation Summary
*** Main program, CGIs and HTML files installed ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

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

 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

make[1]: Leaving directory '/root/nagios/nagios-4.4.9'

The following command will install the init scripts for Nagios.

# make install-init

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

# make install-commandmode

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

# make install-config
Nagios Configuration Files Installed
/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 6: 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
Nagios Email Alerts
###############################################################################
#
# 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 7: Install and Configure the Web Interface for Nagios

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

# make install-webconf
👁 Configure Nagios Web
Configure Nagios Web

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 into the Nagios Web interface.

# 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.

# systemctl restart httpd

Step 8: Compile and Install Nagios Plugin

go there and configure and install it as directed below.

# cd /root/nagios
# cd nagios-plugins-2.3.3
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install

Step 9: Verify Nagios Configuration Files

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

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Configuration Summary
Nagios Core 4.4.9
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2022-11-16
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 10: Add Nagios Services to System Startup

To make Nagios work across reboots, we need to enable nagios and httpd at the system startup using the systemctl command.

# systemctl enable nagios
# systemctl enable httpd

Next, restart Nagios to make the new settings take effect.

# systemctl restart nagios

Step 11: Allow Nagios Web in Firewall

To access the Nagios web interface, you need to open the Apache ports by running the following commands:

# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload

Step 12: Log in 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.

Upgrading Nagios 3.x to Nagios Core 4.x

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 nagios source tar archive and configure it as shown below.

# systemctl stop nagios
# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.9.tar.gz
# tar -zxvf nagios-4.4.9.tar.gz
# cd nagios-4.4.9
# ./configure
# make all
# make install
# systemctl start nagios
Conclusion

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:

If this article helped, share it with someone on your team.
TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.
☕ Buy Me a Coffee
Ravi Saive
I'm Ravi Saive, an award-winning entrepreneur and founder of several successful 5-figure online businesses, including TecMint.com, GeeksMint.com, UbuntuMint.com, and the premium learning hub Pro.Tecmint.com.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

418 Comments

Leave a Reply
  1. When I run the ‘make all‘ command, the console shows the ‘make: *** No rule to make target ‘all’. Stop.

    How can I solve this problem?

    Reply
  2. Hello,

    Please provide documentation for monitoring the docker container working on a Linux remote host using Nagios.

    Reply
  3. Resolving assets.nagios.com (assets.nagios.com)… failed: Name or service not known.

    Reply
  4. Hi, I am trying to test it on an AWS Ec2 instance, at step 10, it’s not working. I have opened all the security groups also.

    When entering only my Pub IP in the browser, it’s loading to a web-page, but not with /nagios, below error I am seeing,

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

    Thanks

    Reply
  5. There is one step is missing in the above guide. You need to add the port 80 in the firewall otherwise you unable to access it via web console.

    # firewall-cmd --zone=public --add-port=80/tcp --permanent
    # firewall-cmd --reload
    
    Reply
  6. Thank you for this useful article on Nagios…

    Reply
  7. Hi, unable to add Nagios (step 9) after verifying the Nagios configuration files. Got the error Failed to issue method call: No such file or directory.

    Reply
    • The first time is also stuck with the same error then I found that you can use the second screenshot commands in STEP 9.

      I was successfully complete the configuration with below mentioned commands in step 9

      [root@tecmint ]# systemctl enable nagios
      [root@tecmint ]# systemctl enable httpd
      

      Restart Nagios to make the new settings take effect.

      [root@tecmint ]# service nagios start [On RHEL/CentOS 6]
      [root@tecmint ]# systemctl start nagios.service [On RHEL/CentOS 7/8 and Fedora]
      
      Reply
  8. Hi Ravi,

    I am not able to login in to Nagios from my local network, outside of the VM machine. Would you please tell me where I need to allow please send me the code. thanks

    Reply
  9. I can’t access Nagios via the web interface. please help me..

    Reply
    • Try systemctl restart httpd command.

      Reply
  10. When I visit “http://ip-addr“, I can see the page of Apache. But I visit “http://ip-addr/nagios“, I can not see anything.

    I don’t know where is the problem. Please tell me, thanks!

    Reply
    • Try to restart httpd or apache2 service.

      Reply
  11. Did everything as above mentioned but getting the below error at the final Verification Nagios Configuration Files

    Website: https://www.nagios.org
    Reading configuration data…
    Read main config file okay…
    Error: Unexpected token or statement in file ‘/usr/local/nagios/etc/objects/contacts.cfg’ on line 22.
    Error processing object config files!

    Reply
    • @Mohammed,

      Open your /usr/local/nagios/etc/objects/contacts.cfg file and look for line 22, there might be some error..

      Reply
  12. Thank you for this amazing article on setting up Nagios on Linux.

    Reply
  13. Hi Sir,

    Very helpful nagios setup.

    Reply
  14. I followed the step above, yet I get the issue.

    Warning: Monitoring process may not be running! and “You don’t have permission to access /cgi-bin/ on this server.” the Nagios service is running everything seem ok. SElinux is set to permissive.

    I’m on CentOS7, Nagios-4.4.3

    Any idea,

    Reply
    • @Sara,

      Disable SELinux and try..it should work.

      Reply
      • Thanks for reply. Yet, disable SElinux still got the same error. To produce the error, access Nagios via FQDN.com (nagios.mydomain.com) Anyways, access via ipaddress/nagios working fine . I thought it is the apache configuration issue.

        Note: I did VHOST the this server.

        Reply
        • Solved by vim /etc/httpd/conf/httpd.conf then specify the script alias>> ScriptAlias /cgi-bin/ "/usr/local/nagios/sbin/".

          Reply
  15. Got an error while running this command ./configure --with-command-group=nagcmd.

    I also executed this command to resolve :

    # yum install -y gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix
    
    Reply
  16. The way of explanation is terrific. I like it & thanks for supporting us @ 0 cost.

    Reply
  17. Getting Error
    You don’t have permission to access /nagios/ on this server.

    Reply
  18. Kindly share steps to configure notification mails

    Reply
  19. Please help !!!

    When i issue command “systemctl enable nagios“, I got following errors.

    [root@Nagios ~]# systemctl enable nagios
    

    nagios.service is not a native service, redirecting to /sbin/chkconfig.
    Executing /sbin/chkconfig nagios on
    The unit files have no [Install] section. They are not meant to be enabled
    using systemctl.
    Possible reasons for having this kind of units are:
    1) A unit may be statically enabled by being symlinked from another unit’s
    .wants/ or .requires/ directory.
    2) A unit’s purpose may be to act as a helper for some other unit which has
    a requirement dependency on it.
    3) A unit may be started when needed via activation (socket, path, timer,
    D-Bus, udev, scripted systemctl call, …).
    ===========================================
    ==>>

    Can anyone help me?!!! <<==

    Reply
    • @Rinav,

      Do you able to access Nagios web interface? by seeing above error, and think it’s a error.

      Reply
      • I can’t access the web interface either!.

        “This site can’t be reached”

        Reply
        • @Rinav,

          Please verify the Nagios configuration file for possible syntax errors:

          # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
          
          Reply
  20. Hi, I am newbie to Nagios. am newbie to nagios

    How to configure snmpwalk with nagios please tell me.

    Reply
  21. I have added windows machine. I am unable to monitor the client windows machine. I am getting below. Please help me on this.

    connect to address 172.24.120.78 and port 12489: Connection refused

    Reply
    • @Muthukumar,

      Please open the port 12489 on firewall, before accessing the Nagios web interface..

      Reply

Got Something to Say? Join the Discussion... Cancel reply

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Check your email for a magic link to get started.