Introduction
Nagios is a powerful open-source network monitoring tool that helps system administrators to monitor infrastructure. It can monitor servers, switches, services, and applications to ensure they are running smoothly. In this tutorial, we will discuss how to install and configure Nagios on CentOS Linux to monitor network devices and services proactively.
Prerequisites
Before starting, make sure that you have a CentOS Linux instance installed and running with root access. Additionally, you will need the following tools:
Apache and PHP
Nagios Core
NRPE plugin
Nagios Plugins
Nagios Graph
If you don't have these tools installed, you can follow the below steps to install them.
Installation of Apache and PHP
Initially, we need to install Apache and PHP. Use the following command to install it.
sudo yum install httpd php -y
After installation, start the Apache service and enable it to start automatically at boot time.
sudo systemctl start httpd.service
sudo systemctl enable httpd.service
Installation of Nagios Core
After installing Apache and PHP, we will install Nagios Core. Follow the below command to install it.
sudo yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils epel-release
sudo yum install -y nagios nagios-plugins-all
Once the installation is complete, start the Nagios service and enable it to start automatically at boot time.
sudo systemctl start nagios.service
sudo systemctl enable nagios.service
Installation of NRPE Plugin
NRPE is a Nagios plugin that helps to monitor remote Linux servers. To install the NRPE plugin on CentOS, use the below command.
sudo yum install -y nrpe nagios-plugins-all
After installation, start the NRPE service and enable it to start automatically at boot time.
sudo systemctl start nrpe.service
sudo systemctl enable nrpe.service
Installation of Nagios Plugins
Nagios Plugins are essential components that help Nagios Core to monitor various services and applications. We can install the Nagios Plugins by using the below command.
sudo yum install nagios-plugins-all -y
Installation of Nagios Graph
Nagios Graph is a web-based application that generates graphical representations of Nagios performance data. It requires the installation of GraphViz, a graph visualization software. Use the following commands to install Nagios Graph and Graphviz.
sudo yum install nagiosgraph
sudo yum install graphviz
Configuration of Nagios
Nagios Core is now installed on our CentOS system. However, before configuring Nagios Core, we need to add a new user and password to access the Nagios web interface. To do this, run the below command.
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Add following permissions to the /usr/local/nagios/etc/nagios.cfg file.
sudo vi /usr/local/nagios/etc/nagios.cfg
Uncomment the following lines in the nagios.cfg file.
#cfg_dir=/usr/local/nagios/etc/servers
cfg_dir=/usr/local/nagios/etc/objects
To check if the configuration file is ok, run the following command.
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If everything is alright, restart the Nagios service.
sudo systemctl restart nagios.service
Configuration of NRPE Plugin
After installing the NRPE plugin, we need to configure the NRPE configuration file on the remote Linux server. Open the /etc/nagios/nrpe.cfg file and make the following changes.
allowed_hosts=127.0.0.1, nagios-server-ip
command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
Note: Replace nagios-server-ip
with the Nagios server IP address.
After modifying the NRPE configuration file, restart the NRPE service on the remote Linux server.
sudo systemctl restart nrpe.service
Accessing Nagios Web Interface
At this point, Nagios Core has been successfully installed and configured on CentOS Linux. To access the Nagios web interface, open a browser and type your server IP address followed by /nagios. For example, http://server-IP-address/nagios
You will be asked to provide the Nagios login credentials configured earlier.
After logging in, you will see the Nagios Core home page. Here, you can view monitoring information for all monitored hosts and services.
Conclusion
In this tutorial, we have covered how to install and configure Nagios on CentOS Linux. We also covered how to install and configure Apache and PHP, NRPE Plugin, Nagios Plugins, and Nagios Graph. With Nagios Core, you can monitor infrastructure proactively and take action before any issue impacts your business.
还没有评论,来说两句吧...