DEV Community

Kavish Gour
Kavish Gour

Posted on • Updated on

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

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Now, lets open port 80:

firewall-cmd --zone=public --add-port=80/tcp
firewall-cmd --zone=public --add-port=80/tcp --permanent
Enter fullscreen mode Exit fullscreen mode

Install the plugins and nrpe:

yum install nagios-plugins nrpe nagios-plugins-nrpe
systemctl start nrpe
systemctl enable nrpe
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Start and enable nrpe:

systemctl start nrpe
systemctl enable nrpe
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

systemctl start nagios.service
systemctl enable nagios.service
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Latest comments (0)