How to install Nagios Core 4 on CentOS 7

Hello,

In the following article I am going to show you how to install Nagios Core 4 on CentOs 7 from source. This is the first of a series on Nagios that I plan to get posted.

What is Nagios

Nagios is a monitoring system that will check on the devices on your network, and notify you in the event of a system failure, or service failure. It is highly customizable (to the point that it can be intimidating to start working with).

What is needed

The first thing I need to do is let you know what you need and where you can get it. In this guide I am using a virtual machine, created in Hyper-V on a Server 2012 R2 cluster. You do not need a fancy enterprise hyper visor to do this you can use a spare computer you have laying around.

Now you need to get the installation media for Centos 7. You can download this from the following link:

http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1503-01.iso

Time to install CentOS

Burn the disk to a blank DVD, or create a bootable USB drive to install CentOS on your machine of choice. (This is about where the video above starts). Now lets boot to the installation media and start installing CentOS 7.

Step 1: Boot to the Media to begin the installation

Begin installing CentOS 7

Begin installing CentOS 7

Step 2: Select your Language

Select the Language you wish to use

Select the Language you wish to use

Step 3: Set your date & timezone

Select Date & Time

Select Date & Time

Select your timezone

Select your timezone

Step 4: Set your Network & Hostname

Select Network & Hostname

Select Network & Hostname

Turn on your network adapter

Turn on your network adapter

Set you IP

Set you IP

Turn on your network adapter /Set your hostname

Set your hostname

Step 5: Select installation Destination

Select Installation Destination

Select Installation Destination

Select the Hard drive you wish to install to

Select the Hard drive you wish to install to

Step 6: Leave software Selection as “Minimal”

Leave software selection as "Minimal Install"

Leave software selection as “Minimal Install”

Step 7: Click “Begin Installation”

Click the begin installation button

Click the begin installation button

Step 8: Set the root password

Click root password to set the root password

Click root password to set the root password

set you root password

set you root password

Step 9: Wait for the installation to complete

Wait for the installation to complete

Wait for the installation to complete

Step 10: Reboot and eject installation media

Reboot  the system

Reboot the system

Begin installing CentOS 7

Eject the installation media

Step 11: login as root

login as root

login as root

Step 12: Run yum upgrade

run the command #yum upgrade

run the command
#yum upgrade

Step 13: Run yum update

run the command #yum update

run the command
#yum update

Now it is time to install the dependencies for Nagios

In this part I have switched over to an SSH session because I would like to have copy paste abilities from my notes. Make sure you are logged in as root.

Step 1: Install the required dependancies

yum -y install httpd php gcc glibc glibc-common gd gd-devel wget perl perl-devel unzip

Step 2: Create the nagios user

/usr/sbin/useradd -m nagios

Step 3: Set the password for the nagios user

passwd nagios

Step 4: Create the nagcmd group

/usr/sbin/groupadd nagcmd

Step 5: Add the nagios and apache user to nagcmd group

/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache

Step 6: Create a downloads directory

mkdir ~/downloads
cd ~/downloads

Time to download nagios

Now we have installed the required dependencies and created the required user/group we can now move on to downloading nagios and extracting it so we can move on to the installation. ensure you are in the downloads directory.

Step 1: Download Nagios Core

wget http://sourceforge.net/projects/nagios/files/nagios-4.1.0rc1.tar.gz

You can find the latest download here:
http://sourceforge.net/projects/nagios/files/

Step 2: Download Nagios Plug-ins

wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz

You can find the latest download here:
http://nagios-plugins.org/download/

Step 3: Extract Nagios

tar xzf nagios-4.1.0rc1.tar.gz

Step 4: Extract Nagios-plugins

tar xzf nagios-plugins-2.0.3.tar.gz

Now to install Nagios Core

Step 1: Move into the nagios directory

cd ~/downloads/nagios-4.1.0rc1

Step 2: Configure Nagios

./configure --with-command-group=nagcmd

Step 3: Run the make commands

make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf

Step 4: Edit the contacts.cfg and change the email to yours

cd /usr/local/nagios/
vi etc/objects/contacts.cfg

Step 5: Create the nagiosadmin user for logging into the nagios web portal

htpasswd -c etc/htpasswd.users nagiosadmin

Step 6: Restart the webservice

systemctl restart httpd.service

The Firewall

Because I have this running behind a hardware firewall I am going to disable the firewall you could just open the needed ports if you like.

Step 1: Disable the firewall

systemctl mask firewalld
systemctl stop firewalld

Now to install the Plugins

Now we need to install the plugins so we can actually have some decent commands to check our devices with.

Step 1: Move back into the downloads directory where we extracted the nagios-plugins

cd ~/downloads/

Step 2: Move into nagios-plugins directory

cd nagios-plugins-2.0.3

Step 3: Configure nagios-plugins

./configure --with-nagios-user=nagios --with-nagios-group=nagios

Step 4: Run the make commands

make
make install

Configure Nagios to start on boot

It is all fine and dandy that we have nagios installed now but we need to ensure that it starts on boot so that we do not need to worry whenever we reboot the nagios server to manually start services.

Step 1: Tell the system to start nagios at startup

chkconfig --add nagios
chkconfig nagios on

Step 2: Tell the system to start httpd at startup

chkconfig httpd on

Now to disable selinux

selinux can cause problems for you and you can either add rules to allow nagios to run correctly or take the route I am going to show you and just disable selinux.

Step 1: edit the selinux config file

cd /
vi etc/selinux/config

Step 2: change SELINUX=enforcing to SELINUX=disabled

SELINUX=disabled

Step 3: reboot the server

reboot

Step 4: verify your nagios config

cd /usr/local/nagios
/usr/local/nagios/bin/nagios -v etc/nagios.cfg

Ensure there are no errors it should look like the following at the end of the output

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

Now to log into nagios

You have now installed nagios and got it running correctly, but that does you no good unless you know how to bring up the nagios web interface.

Step 1: Open your favorite web browser and open the nagios site

http://your-nagios -server-ip/nagios

example
http://172.23.23.15/nagios 

Step 2: Login using the nagiosadmin user you created

user: nagiosadmin
password: the password you set when you created the nagiosadmin user 

Conclusion
Now look around and get familiar with the web interface. In upcoming guides I will show you how to add hosts to monitor and really make nagios core work for you.

3 comments on “How to install Nagios Core 4 on CentOS 7

Leave a Reply

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