Nagios comes with the inbuilt web interface to monitor devices, but you need to rely on configuration files for adding devices to Nagios monitoring.
Install below packages for Nagios.
yum -y install httpd php gcc glibc glibc-common wget perl gd gd-devel unzip
Create a user and group account for the Nagios installation.
useradd nagios groupadd nagcmd
Add both nagios and apache user to nagcmd group. This allows us to execute external commands through the Nagios web interface.
usermod -a -G nagcmd nagios usermod -a -G nagcmd apache
You can use below commands to download Nagios core (v4.4.3) and Nagios plugins(v2.2.1). Else, you can visit the official website to download the latest version of Nagios core and plugins.
cd /tmp wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.3.tar.gz wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
Install Nagios Core
Extract the Nagios core package.
tar -zxvf /tmp/nagios-4.4.3.tar.gz cd /tmp/nagios-4.4.3
Run the series of command to compile and install Nagios core.
./configure --with-nagios-group=nagios --with-command-group=nagcmd make all make install make install-init make install-config make install-commandmode
Install Nagios Web Interface
Execute the below command in the terminal to install Nagios web interface.
You need to protect the Nagios web interface by creating a user account (nagiosadmin).
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Remember the password that you set to this user – you will need it later.
Restart Apache service.
systemctl restart httpd systemctl enable httpd
Sample configuration can be found
/usr/local/nagios/etc directory. These sample files would be enough for getting started with Nagios.
But, you would need to make one change before you proceed.
/usr/local/nagios/etc/objects/contacts.cfg config file and change the email address of nagiosadmin contact definition to the address you would like to use for receiving alerts.
Change the Email address field with your email id to receive the notification.
Install Nagios Plugins
Extract the download Nagios Plugins.
cd /tmp tar -zxvf nagios-plugins-2.2.1.tar.gz cd nagios-plugins-2.2.1
Use below commands to compile and install the Nagios plugins.
./configure --with-nagios-user=nagios --with-nagios-group=nagios make make install
Start Nagios Server
Check for any errors in the Nagios configuration file.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If you don’t see any errors, then you are good to start the Nagios service.
systemctl start nagios
Start Nagios on system startup.
systemctl enable nagios
See if SELinux is in Enforcing mode.
We recommend it to disable it.
You need to modify the settings in /etc/selinux/config to make it permanent. Then reboot the machine.
Make sure you allow the web server to be accessible outside the network.
firewall-cmd --permanent --add-service=http firewall-cmd --reload
Access Nagios Web Interface
You can access the Nagios web interface using the following URL.
Enter the username and password:
You would get the Nagios console.
Click Hosts in the left pane to get a list of systems being monitored by Nagios. We haven’t added any host to Nagios, So it simply monitors the localhost itself.
Click Service in the left pane to get the status of any services that are being monitored with Nagios.
You have successfully setup Nagios monitoring tool on CentOS 7. At this moment, Nagios monitors only the services of Nagios server. In our upcoming article, we will configure Nagios to monitor Remote Linux System.