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:
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
Step 2: Select your Language
Step 3: Set your date & timezone
Step 4: Set your Network & Hostname
Step 5: Select installation Destination
Step 6: Leave software Selection as “Minimal”
Step 7: Click “Begin Installation”
Step 8: Set the root password
Step 9: Wait for the installation to complete
Step 10: Reboot and eject installation media
Step 11: login as root
Step 12: Run yum upgrade
Step 13: Run 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
Step 4: Create the nagcmd group
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
You can find the latest download here:
Step 2: Download Nagios Plug-ins
You can find the latest download here:
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
Step 2: Configure Nagios
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
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
Step 2: Move into nagios-plugins directory
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
Step 3: reboot the server
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
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.