loading...

How to install and configure Nagios Core on CentOS 7 (without compiling)

kavishgour profile image Kavish Gour Updated on ・2 min read

Nagios Core is an open source tool for IT insfrastructure monitoring. Nagios relies on plugins to monitor everything - databases, operating systems, applications, network equipment, protocols, and more!

Installation

Update your repo and install nagios:

yum update -y ; yum install nagios -y

Nagios depends on the Apache web server for its web interface. The previous commands will install apache. Start and enable the service:

systemctl enable httpd.service
systemctl start httpd.service

Now, lets open port 80:

firewall-cmd --zone=public --add-port=80/tcp
firewall-cmd --zone=public --add-port=80/tcp --permanent

Install the plugins and nrpe:

yum install nagios-plugins nrpe nagios-plugins-nrpe
systemctl start nrpe
systemctl enable nrpe

Note: NRPE, allows you to remotely execute Nagios plugins on other Linux/Unix machines and receive the output through nagios.

We also need some basic plugins, that nagios needs by default:

for i in users uptime ssh ping procs load http swap disk; do yum install nagios-plugins-$i -y; done

Start and enable nrpe:

systemctl start nrpe
systemctl enable nrpe

The check_http plugin won't work unless we create an 'index.html' in /var/www/html. Lets'create one:

echo "<h1> Apache is UP and RUNNING. </h1>" > /var/www/html/index.html

Click here for more details about the plugins.

Now, for apache to allow access to the web interface, we've to give the 'nagiosadmin' user a password. The user is created by default. You can change it if you want. To achieve this, let's run 'htpasswd' and input your password:

htpasswd  /etc/nagios/passwd nagiosadmin

All is set. Let's start and enable the nagios service:

systemctl start nagios.service
systemctl enable nagios.service

Go to 'http://localhost/nagios' or 'http://{ip-address}/nagios', enter your credentials, and that's it.

Note: In the services tab, several plugins will print status critical. Give nagios a minute or two to read its configuration and use its required plugins.

You can also use the 'nagiostats' utility on the command line:

[root@centos \~]# nagiostats | grep '^Services Ok'
Services Ok/Warn/Unk/Crit:              8 / 0 / 0 / 0

Just for fun: I wrote a python script to automate the installation.

Posted on by:

kavishgour profile

Kavish Gour

@kavishgour

OpenBSD/Linux and Cybersecurity enthusiast || Member of secbsd.org || Pythonista

Discussion

pic
Editor guide