How to Install Nagios on CentOS 8

Select distribution:
Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

Nagios offers a popular and powerful tool for server monitoring. With a built-in dashboard, alert and notification capabilities, and a range of plugins, Nagios can meet most needs.

Learn how to get started with Nagios on CentOS, AlmaLinux, and Rocky Linux in this tutorial. Follow along to install a Nagios instance and start navigating what it has to offer.

Before You Begin

  1. If you have not already done so, create a Linode account and Compute Instance. See our Getting Started with Linode and Creating a Compute Instance guides.

  2. Follow our Setting Up and Securing a Compute Instance guide to update your system. You may also wish to set the timezone, configure your hostname, create a limited user account, and harden SSH access.

Note
This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you’re not familiar with the sudo command, see the Users and Groups guide.

How to Install Nagios

While Nagios is generally available from most system’s package managers, the recommended installation is from source. Installations from package managers tend to have hidden configuration needs, and lack documentation and support.

This tutorial outlines the source installation process.

While the steps in this tutorial focus on CentOS Stream 8, they should also work on AlmaLinux and Rocky Linux.

Preparing the System

In addition to the steps in the Before You Begin section above, Nagios has a few more installation prerequisites.

  1. First, set SELinux to permissive mode. This limits SELinux to issuing warnings rather than rules enforcement.

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

    Learn more about SELinux in our guides Getting Started with SELinux on CentOS 8 and Changing SELinux Modes .

  2. Typically, CentOS and similar RHEL-based systems use Firewalld for managing firewall rules. Use the following commands to open the server’s HTTP and HTTPS ports and then reload Firewalld:

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

    See more on using Firewalld in our guide Configure a Firewall with Firewalld .

  3. Install the prerequisite packages for the Nagios installation:

    sudo dnf install gcc glibc glibc-common make gettext automake autoconf gd gd-devel perl net-snmp net-snmp-utils openssl-devel epel-release wget tar
    sudo dnf --enablerepo=powertools,epel install perl-Net-SNMP

Setting Up the LAMP Stack

Nagios uses a LAMP stack for its base application and to serve its monitoring interface. Learn more about LAMP stacks, as well as how to set them up, in our guide Installing a LAMP Stack on CentOS 8 .

However, Nagios only needs to install two parts of the LAMP stack: the Apache Web Server and PHP. The following steps just set up these necessary parts.

  1. Install the Apache Web Server:

    sudo dnf install httpd
  2. Start and enable the Apache Web Server:

    sudo systemctl start httpd
    sudo systemctl enable httpd
  3. Install PHP:

    sudo dnf install php php-cli

Downloading and Installing Nagios

  1. Download and extract the Nagios Core and Nagios plugins packages. You could go to the Nagios Core releases page and the Nagios Plugins releases page to manually copy the link to the latest packages for each. However, the cURL commands below expedite this, automatically pulling the latest release of each.

    cd /tmp
    curl -s https://api.github.com/repos/NagiosEnterprises/nagioscore/releases/latest \
    | grep "browser_download_url.*nagios.*.tar.gz\"" \
    | tail -n 1 \
    | cut -d : -f 2,3 \
    | tr -d \" \
    | wget -O nagios-core.tar.gz -qi -
    curl -s https://api.github.com/repos/nagios-plugins/nagios-plugins/releases/latest \
    | grep "browser_download_url.*nagios-plugins.*.tar.gz\"" \
    | tail -n 1 \
    | cut -d : -f 2,3 \
    | tr -d \" \
    | wget -O nagios-plugins.tar.gz -qi -
    tar xzvf nagios-core.tar.gz
    tar xzvf nagios-plugins.tar.gz
  2. Change into the Nagios Core directory. You may have to adjust this command depending on the directory the Nagios Core package extracted in the step above.

    cd nagios-4.*/
  3. Compile the Nagios source files:

    sudo ./configure
    sudo make all
  4. Run the script to create the Nagios user and user group and add the apache group to the nagios user:

    sudo make install-groups-users
    sudo usermod -aG nagios apache
  5. Install Nagios from the compiled files:

    sudo make install
  6. Install the Nagios service, command mode, and default configurations. The last command restarts the Apache service for its configuration changes to take effect.

    sudo make install-daemoninit
    sudo make install-commandmode
    sudo make install-config
    sudo make install-webconf
    sudo systemctl restart httpd
  7. Add the nagiosadmin user account via htpasswd. Running this command prompts you to create a password for the new user account. This is the user you use to log into the Nagios interface.

    sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
  8. Start up and enable the Nagios service:

    sudo systemctl start nagios
    sudo systemctl enable nagios
  9. Change into the directory for the Nagios plugins:

    cd /tmp/nagios-plugins-*/
  10. Compile and install the Nagios plugins:

    sudo ./configure
    sudo make
    sudo make install

How to Start Using Nagios

With the new Nagios instance installed and running, access the Nagios interface from a web browser. Navigate to the path /nagios on your system’s public IP address or configured domain.

For example, if your public IP is 192.0.2.0, then you would navigate to http://192.0.2.0/nagios. Alternatively, if your domain name is example.com, you would navigate to example.com/nagios.

Note
Learn more about setting up a domain name for your system through the Linode DNS Manager with our guide DNS Manager - Get Started . While other DNS managers can set up a domain name, Linode’s provides added convenience. Regardless, this guide can serve as a general introduction to the process.

The browser should prompt for a login. Use the nagiosadmin username and the password configured with the htpasswd command above. Once logged in, you should arrive at the Nagios dashboard:

Nagios monitoring dashboard

The interface provides access to a wide range of monitoring tasks. Get an overview of hosts monitored by your Nagios instance on the Hosts page:

Nagios dashboard listing monitored hosts

At present, this only has one host, localhost. More hosts can be added, either by setting up Nagios to monitor publicly-available services or setting up NRPE .

Another useful page to start out with is Services, which shows the services running for all hosts that Nagios is monitoring:

Nagios dashboard listing monitored services

Conclusion

Now you have your own Nagios instance running. Exploring the dashboard’s myriad options can provide a good idea of Nagios’s capabilities. Take a look at the Nagios Core documentation linked below to continue exploring and make the most out of your instance.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.
The Disqus commenting system for Linode Docs requires the acceptance of Functional Cookies, which allow us to analyze site usage so we can measure and improve performance. To view and create comments for this article, please update your Cookie Preferences on this website and refresh this web page. Please note: You must have JavaScript enabled in your browser.