ag@linux:~$

history 24 of 36

Install Nagios Core 3 and Plugins on CentOS 6: Quick Steps

A short command list for building Nagios Core 3.4.4 and the Nagios plugins from source on CentOS 6, then logging in to the web interface.

Written

From my Linux study notes, 2016. Some commands and versions here are old, so please reuse them carefully. Anything marked "added later", and the notes at the end, explain what has changed since.

This is my short list of commands for installing Nagios Core and the Nagios plugins from source on CentOS 6. For a longer walkthrough that also creates the Nagios user and groups, sets the alert email address and checks the configuration, see my other post, “Install Nagios on CentOS: Users, Web Login, Alerts and Checks”.

Before you start

  • Run these commands as root (or put sudo in front of them).
  • Use a test server first.
  • The Nagios install steps expect a nagios user and group to exist. This post does not create them, and without them the install steps fail. Create them first (this is the same as in my other Nagios post):
Terminal window
useradd -m nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache

Installation of Nagios Core

  1. Install the packages needed to build Nagios and run its web interface (Apache, PHP, the C compiler and the GD graphics library):

    Terminal window
    yum install gd gd-devel httpd php gcc glibc glibc-common
  2. Make a folder to keep the downloads in:

    Terminal window
    mkdir /root/nagios
  3. Go into it:

    Terminal window
    cd /root/nagios
  4. Download Nagios Core and the Nagios plugins:

    Terminal window
    wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.4.tar.gz
    wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
  5. Extract Nagios:

    Terminal window
    tar xvzf nagios-3.4.4.tar.gz

    x extracts, v lists the files as they are extracted, z handles the gzip compression and f names the archive file.

  6. Go into the extracted folder:

    Terminal window
    cd nagios

    If cd nagios fails, run ls to see the exact folder name the archive created and cd into that instead.

  7. Run the configure script, which checks your system and prepares the build:

    Terminal window
    ./configure

    If you created the nagcmd group above, use ./configure --with-command-group=nagcmd instead so the web interface can send commands to Nagios.

  8. Compile and install. In the original post these were written on one line separated by commas; they are separate commands, run one after another:

    Terminal window
    make all
    make install
    make install-init
    make install-commandmode
    make install-config
    make install-webconf
    • make install installs the program under /usr/local/nagios/.
    • make install-init installs the start-up script.
    • make install-commandmode sets permissions on the folder used for external commands.
    • make install-config installs the sample configuration files.
    • make install-webconf adds the Apache configuration for the web interface.
  9. Create the web login user nagiosadmin. You will be asked to type a password twice:

    Terminal window
    htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

    The -c option creates the file. Only use it the first time; running it again with -c overwrites the file and removes existing users.

  10. Set Nagios to start at boot and start it now:

    Terminal window
    chkconfig nagios on
    service nagios start

Installation of Nagios plugins

The plugins are the small programs Nagios runs to do the actual checks (ping, disk space, HTTP and so on).

Terminal window
cd ..
tar xvzf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure
make
make install

Correction: the download in step 4 is version 1.4.16, but these commands extract 1.4.15. Use the same version you downloaded:

Terminal window
cd ..
tar xvzf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

Then start Apache and set it to start at boot:

Terminal window
service httpd start
chkconfig httpd on

Log in

Now log in at http://your-ip/nagios with user nagiosadmin and the password you set in step 9.

To check it worked: the page should ask for a username and password, then show the Nagios home page. The “Services” page should list checks for localhost. If the page does not load from another computer, check that the firewall allows port 80.

Notes for today

  • CentOS 6 reached end of life on 30 November 2020 and gets no security updates. Rocky Linux and AlmaLinux are the common free replacements.

  • Nagios Core 3 is old. Nagios Core 4 replaced it. The SourceForge links above may no longer work; get the current Nagios Core and plugin releases from the official site, https://www.nagios.org/, and check the documentation for your version, as the build steps have changed.

  • Services: on systems with systemd, service x start / chkconfig x on become:

    Terminal window
    sudo systemctl start httpd
    sudo systemctl enable httpd
  • Packages: yum became dnf on newer Red Hat-family systems (yum still works as an alias).

  • Firewall: on Rocky Linux and AlmaLinux, allow web traffic with:

    Terminal window
    sudo firewall-cmd --permanent --add-service=http
    sudo firewall-cmd --reload
  • Security: the web login uses HTTP basic authentication. Over plain http:// the password is sent unencrypted, so put the Nagios web interface behind HTTPS, or restrict it to your own network, on any server reachable from the internet.