How to install Nagios on CentOs 7/RHEL 7

0
1375

Nagios

Nagios is free and open source application software licensed under GNU GPL Version2. It is very famous monitoring tool used by the almost every system and network administrator in the world. It is my favorite monitoring tool. Nagios can be used to monitor servers, network and infrastructure. It’s not only monitoring also alerts when the systems go wrong and alert the second time when the problem is resolved. It monitors network services like HTTP, FTP, SMTP, SNMP, POP3, IMAP etc. It is a cross-platform application runs under the various operating systems like Linux, nagiosUnix, Macintosh and windows.
In this article, we will be known about the installatiNagioson CentOS 7/RHEL 7.
Before we going to start the installation of Nagios, install the following prerequestices

#yum -y install httpd php gd gd-devel gcc glibc glibc-common net-snmp

Create user nagios and group nagcmd as follows

#useradd nagios
#groupadd nagcmd

Now add users Nagios and apache to nagcmd group

#usermod -G nagcmd nagios
#usermod -G nagcmd apache

NowdownloadthelatestversionNagioscoreandNagiospluginfromtheirofficialsite.
Extract Nagios core and change to directory

#wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.1.tar.gz
#tar -xzvf nagios-4.3.1.tar.gz
#cd nagios-4.3.1

Read also: Zabbix installation on Linux

Compile and install Nagios as follows

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


#make all



Now run the make install command

[root@localhost nagios-4.3.1]# make install
cd ./base && make install
make[1]: Entering directory `/root/nagios-4.3.1/base'
make install-basic
make[2]: Entering directory `/root/nagios-4.3.1/base'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin
/usr/bin/install -c -m 774 -o nagios -g nagios nagios /usr/local/nagios/bin
/usr/bin/install -c -m 774 -o nagios -g nagios nagiostats /usr/local/nagios/bin
make[2]: Leaving directory `/root/nagios-4.3.1/base'
make strip-post-install
make[2]: Entering directory `/root/nagios-4.3.1/base'
/usr/bin/strip /usr/local/nagios/bin/nagios
/usr/bin/strip /usr/local/nagios/bin/nagiostats
make[2]: Leaving directory `/root/nagios-4.3.1/base'
make[1]: Leaving directory `/root/nagios-4.3.1/base'
cd ./cgi && make install
make[1]: Entering directory `/root/nagios-4.3.1/cgi'
make install-basic
make[2]: Entering directory `/root/nagios-4.3.1/cgi'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/sbin
for file in *.cgi; do \
	/usr/bin/install -c -m 775 -o nagios -g nagios $file /usr/local/nagios/sbin; \
done
make[2]: Leaving directory `/root/nagios-4.3.1/cgi'
make strip-post-install
make[2]: Entering directory `/root/nagios-4.3.1/cgi'
for file in *.cgi; do \
	/usr/bin/strip /usr/local/nagios/sbin/$file; \
done
make[2]: Leaving directory `/root/nagios-4.3.1/cgi'
make[1]: Leaving directory `/root/nagios-4.3.1/cgi'
cd ./html && make install
make[1]: Entering directory `/root/nagios-4.3.1/html'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/media
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/stylesheets
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/contexthelp
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/docs
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/docs/images
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/js
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/images
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/images/logos
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/includes
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/ssi
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/angularjs
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/angularjs/angular-1.3.9
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/angularjs/ui-utils-0.2.1
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/bootstrap-3.3.0
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/bootstrap-3.3.0/css
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/d3
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/share/spin
/usr/bin/install -c -m 664 -o nagios -g nagios robots.txt /usr/local/nagios/share
rm -f /usr/local/nagios/share/index.html
rm -f /usr/local/nagios/share/main.html
rm -f /usr/local/nagios/share/side.html
rm -f /usr/local/nagios/share/map.html
rm -f /usr/local/nagios/share/rss-*
rm -rf /usr/local/nagios/share/include/rss
/usr/bin/install -c -m 664 -o nagios -g nagios jsonquery.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios graph-header.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios histogram.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios histogram-form.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios histogram-graph.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios histogram-links.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios infobox.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios map.php /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios map-directive.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios map-form.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios map-links.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios map-popup.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios trends.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios trends-form.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios trends-graph.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios trends-host-yaxis.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios trends-links.html /usr/local/nagios/share
/usr/bin/install -c -m 664 -o nagios -g nagios trends-service-yaxis.html /usr/local/nagios/share
for file in *.php; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share; done
for file in stylesheets/*.css; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/stylesheets; done
for file in contexthelp/*.html; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/contexthelp; done
for file in js/*.js; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/js; done
for file in images/*.gif; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/images; done
for file in images/*.jpg; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/images; done
for file in images/*.png; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/images; done
for file in images/*.ico; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/images; done
for file in images/logos/*.*; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/images/logos; done
for file in includes/*.*; \
do /usr/bin/install -c -m 664 -o nagios -g nagios $file /usr/local/nagios/share/includes; done
/usr/bin/install -c -m 664 -o nagios -g nagios angularjs/angular-1.3.9/angular.min.js  /usr/local/nagios/share/angularjs/angular-1.3.9
/usr/bin/install -c -m 664 -o nagios -g nagios angularjs/angular-1.3.9/angular.min.js.map  /usr/local/nagios/share/angularjs/angular-1.3.9
/usr/bin/install -c -m 664 -o nagios -g nagios angularjs/ui-bootstrap-tpls-0.12.0.min.js  /usr/local/nagios/share/angularjs
/usr/bin/install -c -m 664 -o nagios -g nagios angularjs/ui-utils-0.2.1/ui-utils.js   /usr/local/nagios/share/angularjs/ui-utils-0.2.1
/usr/bin/install -c -m 664 -o nagios -g nagios bootstrap-3.3.0/css/bootstrap.min.css /usr/local/nagios/share/bootstrap-3.3.0/css
/usr/bin/install -c -m 664 -o nagios -g nagios bootstrap-3.3.0/css/bootstrap-theme.min.css /usr/local/nagios/share/bootstrap-3.3.0/css
/usr/bin/install -c -m 664 -o nagios -g nagios d3/d3.min.js /usr/local/nagios/share/d3
/usr/bin/install -c -m 664 -o nagios -g nagios spin/spin.min.js /usr/local/nagios/share/spin
make[1]: Leaving directory `/root/nagios-4.3.1/html'
make install-exfoliation
make[1]: Entering directory `/root/nagios-4.3.1'

*** Exfoliation theme installed ***
NOTE: Use 'make install-classicui' to revert to classic Nagios theme

make[1]: Leaving directory `/root/nagios-4.3.1'
make install-basic
make[1]: Entering directory `/root/nagios-4.3.1'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/archives
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/spool/checkresults
chmod g+s /usr/local/nagios/var/spool/checkresults

*** Main program, CGIs and HTML files installed ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

  make install-init
     - This installs the init script in /etc/rc.d/init.d

  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file

  make install-config
     - This installs sample config files in /usr/local/nagios/etc

make[1]: Leaving directory `/root/nagios-4.3.1'

Now install init scripts, permissions and sample config files by using the following command

#make install-init
#make install-commandmode
#make install-config

Now install nagiosNagiosnterface

# make install-webconf

The default username for Nagios is nagiosadmin, now create a password for nagiosadmin by using the following command

[root@localhost ~]# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: 
Re-type new password: 
Adding password for user nagiosadmin
You have new mail in /var/spool/mail/root
[root@localhost ~]#

Now extract and change to Nagios plugin directory

#wget https://nagios-plugins.org/download/nagios-plugins-2.1.4.tar.gz
#tar -xzvf nagios-plugins-2.1.4.tar.gz
#cd nagios-plugins-2.1.4

Compile and install Nagios plugins

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

#./configure --with-nagios-group=nagcmd

Now run the make command

#make

#make install


Now edit file /usr/local/nagios/etc/objects/contacts.cfg and add email address to receive alerts


To allow access from remote systems, edit the file /etc/httpd/conf.d/nagios.conf and add the IP address from where we accessing Nagios remotely.
Now check configuration for errors and Waring’s by using the following command

Now restart the httpd service

#systemctl restart httpd

Enable and start the nagios service

#systemctl enable nagios
#systemctl start nagios

Configure firewalld and Selinux to allow nagios service

#firewall-cmd --permanent --zone=public --add-service=http
#firewall-cmd --zone=public --permanent --add-service=nagios
#firewall-cmd reload
#setenforce 0

Now access the Nagios web interface by using theURL Address http://ip-address/nagios in your favorite Browser.

It Prompts for username and password. The default username is nagiosadmin and password is created by htpasswd command in earlier steps.

The Nagios core is running with PID 1651, from here we can monitors hosts, services etc.

Read also: Nagios XI  installation on CentOS 7/RHEl 7

In the Next article, we will learn about the monitoring Linux and windows hosts by using Nagios. if you want to join this discussion, feel free to leave a comment!