Installing Nagios

Nagios itself as well as the standard plugins are written in C and need to be compiled into a native Linux binary. Both Nagios and Nagios plugins use the standard configure, make, make install approach that is common for most Unix applications written in C.

This section will guide you through either using an automated script for performing the installation, which we recommend, or performing the installation manually.

Upgrading from previous versions

If you already have a previous version of Nagios installed, it is always a good idea to upgrade to the latest Nagios and Nagios plugins. It is especially true if upgrading from Nagios 3 or 2 as Nagios 4 includes performance improvements when monitoring large number of hosts and/or services.

When upgrading, it is recommended that you use the manual steps described later in this chapter, and use same usernames, groups, and paths as when the original installation took place. If you have performed the Nagios installation based on steps from the previous revisions of this book, the paths, system user, and group are the same and do not need any changes.

Let’s start with the installation:

  1. It is required to stop all Nagios processes before performing an upgrade. This can usually be done by invoking the following command:
    service nagios stop
    

    The preceding command works on all modern Linux distributions and supports services installed such as SysVinit (in /etc/init.d or /etc/rc.d/init.d) and Upstart services (added in /etc/init and using a different format of the service file definition).

    If the preceding command did not work properly, running the init.d script directly should work:

    service nagios stop
    
  2. It is recommended that you stop Nagios while compiling and installing a new version. You should then proceed with the installation steps described in the next sections. Almost all of Nagios 4 configuration parameters are backward compatible, so your current configuration will work fine after upgrading.
  3. Once the new version of Nagios is installed, it is recommended that you check the Nagios configuration with the new version to ensure that there are no incompatibilities:
    /opt/nagios/bin/nagios -v /etc/nagios/nagios.cfg
    
  4. We can now simply run the following command:
    service nagios start
    

    If the preceding command did not work properly, run the following init.d script, and the upgrade process should be complete:

    /etc/init.d/nagios start
    

Another option is to remove the previous installation completely and install a fresh copy of Nagios, only preserving the configuration files. The downside of this is that you will lose all the historical data of Nagios results.

Performing installation with automated script

To perform a fresh, automated installation of Nagios and Nagios standard plugins, simply run the following as the root user:

curl -sSL https://raw.github.com/learning-nagios/nagiosinstall/
master/install.sh | sh

This will download the automated install script from GitHub and run it.

Please note that this requires the curl command to be available. The installation can also be done using the wget command if curl is not available:

wget -qO- https://raw.github.com/learning-nagios/nagiosinstall/master/install.sh | sh

The script installs prerequisite packages, including Apache web server. Next, the script will create appropriate system accounts and compile Nagios and Nagios plugins from the source code. It will also install Nagios as a system service using the built-in init.d script. Finally, the script will also add a configuration for Apache to allow accessing the Nagios web interface, as http://(ip-address)/nagios

Note

Please note that the username when using the automated script is set to nagiosadmin and the password is nagiosadmin. The Nagios web interface is described in more detail in Chapter 4, Using the Built-in Web interface.

All that is needed is to restart the web server, which varies depending on the Linux distribution, but it should be one of the following commands:

apachectl restart
service apache2 restart
service httpd restart

The script works on all major Linux distributions that use the yum/rpm or apt-get/dpkg package managers. For Linux distributions that do not support these package managers, as well as in this case and in the rare case of errors, the script will exit and an error will be shown rather than the actual output. In this case, it is recommended that you manually follow the steps from the further sections of this chapter and perform the troubleshooting.

After a successful finish, you should see the following message:

Congratulations! Nagios and standard plugins are now installed.

If this is the case, then you are done with the installation and may continue to the next chapter or read more about using Nagios in virtualized environments and containers or learn more about the exact steps the automated script is performing.

When the automated installation is used, the paths to key Nagios directories and files are as follows:

Path Description
/etc/nagios Configuration directory
/etc/nagios/nagios.cfg Main Nagios configuration file
/var/nagios Nagios local state directory
/var/nagios/archives Historical information regarding Nagios; this directory can grow over time and may be put on a separate partition
/var/nagios/status.dat Nagios current state file
/var/nagios/rw/nagios.cmd Pipe for writing commands to Nagios
/opt/nagios/share Web UI files that should be served via web server, such as http://(ip-address)/nagios
/opt/nagios/sbin CGI scripts that should be served via web browser, such as http://(ip-address)/nagios/cgi-bin
/opt/nagios/plugins Path to Nagios plugins used for performing checks

These paths are used in the next chapters in this book and their meanings will be referred to later in this book, but it is worth noting all the key paths.

Note

Please note that the script is not fully setting contexts for Security-Enhanced Linux (SELinux). If you are using SELinux, you may need to set appropriate contexts for all Nagios related files and directories to enable the web interface to work properly or disable the SELinux forcing of security contexts.

On CentOS/RedHat Linux distribution, disabling SELinux enforcement can be done by editing /etc/sysconfig/selinux and set SELINUX to permissive, such as: SELINUX=permissive

After that, a reboot of the machine is required to change the SELinux policy enforcing mode.

Installing Nagios using package managers

Nagios can also be installed using prebuilt packages. Nagios packages are available for most Linux distributions. In many cases, the exact paths for things such as configuration files, local state directory, and web interface-related files may differ. If you choose to install Nagios using packages, keep in mind that some examples in the remaining chapters can require slight modifications.

In this section, we will focus on installing Nagios and the plugins on top of popular Linux distributions using apt-get for Debian and Ubuntu as well as yum for RHEL, CentOS, and Oracle Linux.

Installation with apt-get/dpkg

Both the latest Ubuntu Long-Term Support (LTS) (which currently is 14.04) and Debian 8 provide only Nagios version 3. To install it, simply run the following command:

apt-get -y install nagios3 nagios-plugins

The installation will prompt for the password for the web interface. Similar to the automated installation script, the username will be nagiosadmin. To access the website, you should navigate to  http://(ip-address)/nagios3/ When installing Nagios 3 from the deb packages, the paths to key Nagios directories and files are as follows:

Path

Description

/etc/nagios3

Configuration directory

/etc/nagios3/nagios.cfg

Main Nagios configuration file

/var/cache/nagios3

Nagios local state directory

/var/lib/nagios3/rw/nagios.cmd

Pipe for writing commands to Nagios

/var/cache/nagios3/status.dat

Nagios current state file

/usr/share/nagios3/htdocs

Web UI files that should be served via a web server, such as http://(ip-address)/nagios

/opt/nagios/sbin

CGI scripts that should be served via a web browser, such as http://(ip-address)/nagios/cgi-bin

/usr/lib/nagios/plugins

Path to Nagios plugins used for performing checks

These paths differ from the paths used by the automated installation script, which we strongly recommend, as it makes following the book easier and uses the same paths for all Linux distributions. Since the paths to the preceding key items differ, some examples shown thorough this book may use slightly different paths and need adjustments if you use the Nagios installed from binary packages.

Installation with yum/rpm

Nagios is not provided in The Red Hat Enterprise Linux distribution and all distributions that originate from it, such as CentOS, Fedora, and Oracle Linux. It is, however, provided as part of Extra Packages for Enterprise Linux (EPEL), documented in more detail at the following link: https://fedoraproject.org/wiki/EPEL

The only way to install Nagios from RPM packages on those systems is to use the EPEL. Its installation varies depending on the exact version of the distribution and is described in more details in the EPEL documentation.

For example, we can use the following command to install EPEL on CentOS 7:

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

This will set up EPEL and allow the installation of additional packages via YUM, including the Nagios and Nagios plugins.

The next step is to make sure the packages are up to date and install Nagios along with Nagios plugins:

yum update -y ; yum install -y nagios nagios-plugins-all

The last step is to set the password for the nagiosadmin web user by running the following command:

htpasswd -c /etc/nagios/passwd nagiosadmin

This will prompt for the password for the user. Using nagiosadmin as the username is described in more detail in Chapter 4, Using the Built-in Web interface.

After that, Nagios should be installed. For CentOS 7, Nagios is version 4 and the key Nagios directories and files are as follows:

Path

Description

/etc/nagios

Configuration directory

/etc/nagios/nagios.cfg

Main Nagios configuration file

/var/log/Nagios

Nagios local state directory

/var/spool/nagios/cmd/nagios.cmd

Pipe for writing commands to Nagios

/var/log/nagios/status.dat

Nagios current state file

/usr/share/nagios/html

Web UI files that should be served via web server, such as http://(ip-address)/nagios

/usr/lib64/nagios/cgi-bin

CGI scripts that should be served via web browser, such as http://(ip-address)/nagios/cgi-bin

NOTE: For 32-bit systems, the path will be /usr/lib/nagios/cgi-bin

/usr/lib64/nagios/plugins

Path to the Nagios plugins used for performing checks

NOTE: For 32-bit systems, the path will be /usr/lib/nagios/plugins

These paths differ from the paths used by the automated installation script, which we strongly recommend, as it makes following the book easier and uses the same paths for all Linux distributions. Since the paths to the preceding key items differ, some examples shown thorough the book may use slightly different paths and need adjustments if you use Nagios installed from binary packages.

Related Articles

How to add swap space on Ubuntu 21.04 Operating System

How to add swap space on Ubuntu 21.04 Operating System

The swap space is a unique space on the disk that is used by the system when Physical RAM is full. When a Linux machine runout the RAM it use swap space to move inactive pages from RAM. Swap space can be created into Linux system in two ways, one we can create a...

read more

Lorem ipsum dolor sit amet consectetur

0 Comments

Submit a Comment

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

5 × five =