Install Nagios 4 on CentOS/RHEL6

Install Nagios 4 on CentOS/RHEL6

Install Nagios 4 on CentOS/RHEL6

yum install httpd php php-cli gcc glibc glibc-common gd gd-devel net-snmp on host nagios

Nagios has worked hard to secure it’s seat as one of the world’s best enterprise monitoring systems. Nagios alerts about critical business processes such as certificate expiration, as well as supports multiple platforms including Windows and Linux.

Let’s get started, login, and su to root

Same yum install of httpd, php, gcc, gd and net-snmp prerequisites at the root login step

first let’s install some pre-requisites

yum install httpd php php-cli gcc glibc glibc-common gd gd-devel net-snmp prerequisites for Nagios 4

we also need to install the development tools:

yum -y groupinstall development tools on the Nagios server

modify your hosts file as appropriate

vi /etc/hosts opened as root on the Nagios server

obviously modify this part

/etc/hosts entry mapping the server IP to nagios.domain.local nagios

configure apache to start on startup, and start the service now

chkconfig httpd on and service httpd start returning Starting httpd OK

setup the nagios user account

useradd nagios and passwd nagios, accepted despite BAD PASSWORD warnings

configure group permissions

groupadd nagcmd, then usermod -a -G nagcmd for the nagios and apache users

Compile/Install Nagios:

Before proceeding, please review the document on Building a RPM From Source you will need to have a decent understanding before proceeding. We have saved you alot of time by building the SPEC files, all you have to do is compile the code.

Nagios Spec File

Nagios-Plugins Spec File

Nagios NRPE Spec File

you will also need to bulid the following rpms to be able to install the nagios-plugins, make an RPM from those as well

http://pkgs.repoforge.org/perl-Net-SNMP/perl-Net-SNMP-5.2.0-1.2.rf.src.rpm

http://pkgs.repoforge.org/perl-Crypt-DES/perl-Crypt-DES-2.05-3.2.rf.src.rpm

you may want to setup sudo for the nagios user to compile the packages.

After your packages have all been compiled, not then need to be installed on the server

change to the directory where you built your RPM’s, or download your RPM’s from your build server

cd /home/nagios/rpmbuild/RPMS/x86_64/ to reach the built Nagios RPMs

install the Nagios RPM

sudo rpm -i nagios-4.1.1-1.el6.x86_64.rpm installing the Nagios 4 RPM

install the perl-Crypt DES RPM

sudo rpm -i perl-Crypt-DES-2.05-3.2.el6.x86_64.rpm

change to the noarch directory, and install the perl-Net-SNMP RPM

pwd in rpmbuild/RPMS/noarch, then sudo yum localinstall perl-Net-SNMP-5.2.0-1.2.el6.noarch.rpm

now we are finally able to install our nagios-plugins package

sudo rpm -i nagios-plugins-2.1.1-1.el6.x86_64.rpm installing the plugins package

now if we try to start nagios, we get an error

service nagios start failing: check result path /var/spool/checkresults is not a valid directory

let’s create the directory, and set the necessary permissions

mkdir /var/spool/checkresults and chown nagios:nagios on the new directory

try to start nagios again

service nagios start returning Starting nagios: done

it will likely fail due to the following error:

nagios: Error: failed to access() /usr/bin/nagios: Permission denied

to correct the error chmod 775 /usr/bin/nagios

chkconfig nagios on to start Nagios at boot

now is also a good time to enable startup

chkconfig nagios on, enabling the Nagios service at startup

now we just need to setup apache:

edit the default apache configuration

vi /etc/httpd/conf/httpd.conf to edit the default Apache configuration

update the config to contain a new document root

httpd.conf lines 292-293: old DocumentRoot /var/www/html commented out, new DocumentRoot /usr/share

from here based on the /etc/httpd/conf.d/nagios.conf file, we need to add the nagiosadmin

htpasswd -c /etc/htpasswd.users nagiosadmin creating the Nagios web login

restart apache and nagios one final time

service httpd restart and service nagios restart, both OK after the config check

browse to http://hostname

enter your username/password that you just set

Browser Authentication Required prompt for Nagios Access at http://nagios2 with user nagiosadmin

you should now be on the nagios home page.

You may see the following error:

Nagios Core home page status showing Not running

tail /var/log/messages shows:

Nov 13 23:03:18 nagios2 nagios: Error: Unable to create temp file ‘/var/nagios.tmphqt4d2’ for writing status data: Permission denied
Nov 13 23:03:28 nagios2 nagios: Error: Unable to create temp file ‘/var/nagios.tmpr5AVEL’ for writing status data: Permission denied

chmod 775 /var/ and chgrp nagios /var/, then service nagios restart

now refresh, you should see the following:

Nagios Core 4.1.1 home page showing Daemon running with PID 6534

That’s It!

Hosted Linux Servers at www.zwiegnet.com/go

Related guides: Install Nagios on Linux | Build RPM From Source

1 Comment

Leave a Reply

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