In this tutorial we will learn about how to install Nagios 4 on CentOS 7/RHEL 7 . To install nagios we will use its stable source code, which is avaible at Nagios site.
Nagios is one the most popular, stable and reliable monitoring tool. It is available as free and Open source package called Nagios Core version. On other side you can also get the paid version of Nagios called “Nagios XI“.
Follow the step by step installation of Nagios Core on RHEL 7/ CentOS 7
We are installing Nagios on minimal installed CentOS 7/ RHEL 7.
Nagios Version : Nagios-4.0.8
Step 1: Install wget for downloading the package
Use the below given command to install wget package. If in your server, wget is already installed then you can skip this step
yum install wget
Step 2: Create Nagios user
Create nagios user and nagcmd group for installing Nagios package.
useradd nagios groupadd nagcmd usermod -a -G nagcmd nagios
Step 3: Install Apache,PHP and other dependencies
Nagios is a php based application. But core engine is written on C language. We will run nagios on apache web server.
By using below given command, install all the basic requirements.
yum install httpd php gd gd-devel gcc glibc glibc-common openssl perl perl-devel make
Step 4: Download Nagios package
You can download the Nagios core package from http://nagios.org . At the time of writing this post , the latest stable package was nagios-4.0.8
Step 5: Untar the Downloaded Nagios package
Now extract the downloaded nagios package
tar -xvzf nagios-4.0.8.tar.gz
Step 6 : Compiling Nagios
Now here we will compile the Nagios source code.
Change to extracted out Nagios package and run the compilation command as given below
cd nagios-4.0.8 ./configure --with-command-group=nagcmd make all make install make install-init make install-config make install-commandmode make install-webconf
Step 7: Copy eventhandlers directory and change its ownership
Now copy eventhandlers directory to directory /usr/local/nagios/libexec/
cp -rvf contrib/eventhandlers/ /usr/local/nagios/libexec/
Change ownership of copied eventhandlers directory
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
Step 8: Reset nagiosadmin password
Reset nagiosadmin password by using htpasswd command. We will use the user nagiosadmin and its password at the time of login into Nagios Dashboard
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Step 9 : Start httpd and nagios server
Use below given command to start the httpd and nagios service
systemctl start httpd.service systemctl start nagios.service
Step 10: Open HTTP port for Nagios Dashboard access
On RHEL 7/CentOS7 , firewalld is introduced as alternate for iptables. We recommend to use firewalld instead of iptables.
firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --reload
Step 11: Access the Nagios dashbaord
Access the nagios dashboard by using ip address of your server.
Open web browser and on URL type
(Replace 192.168.56.101 with your server’s ip address)
You will see HTTP authenticaion box.
User Name : nagiosadmin
Password: Which you have set Step 8
After successful login, you will get webpage as given in below screenshot
At left hand sidebar, click on “Services” link . You will get the services section on Nagios Dashboard.
You can see, lots of red color alerts on nagios dashboard with critical status. In “Status Information” observe “No output on stdout”, it means there is no output from nagios plugin script. To solve this, we will install nagios plugins
Install Nagios plugins on Nagios Server
Installing the Nagios plugin is quite simple. Nagios plugin commumity regularly launched the new package which is bundled with new nagios plugin and bug fixes.
At the time of writing this post nagios-plugins-2.0.3 package was latest and stable.
Visit nagios-plugins community site for more info.
Nagios Installed Directory Path : Nagios installed path on server is /usr/local/nagios . Explore this directory you will see many other directories.
Nagios Configuration Directory path: /usr/local/nagios/etc
Download the Nagios plugin package on server
Extract the package
tar -xvzf nagios-plugins-2.0.3.tar.gz
Change to extracted out directory
./configure --with-nagios-user=nagios --with-nagios-group=nagios make && make install
Path of Nagios plugin installed : The nagios plugins are installed at /usr/local/nagios/libexec
After a few minutes, you can see all alerts are checked and have green status. Bydefault nagios update the status on 90 seconds. (See above at nagios dashboard)