In this tutorial, we will show you how to install Nagios on CentOS 8. For those of you who didn’t know, Nagios is open-source software that can be used for network and infrastructure monitoring. Nagios will monitor servers, switches, applications, and services. It alerts the System Administrator when something went wrong and also alerts back when the issues have been rectified. Resources that can be monitored include CPU, memory, and disk space loads, log files, temperature, or hardware errors. It can monitor various parameters and problems for services like HTTP, SMTP, and DNS, and with the help of plugins, it can be highly extended. Nagios core was originally designed to run under Linux, although it should work under most other units as well.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of Nagios on a CentOS 8 server.
Prerequisites
- A server running one of the following operating systems: CentOS 8.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Nagios on CentOS 8
Step 1. First of all, make sure that all packages are up to date.
sudo dnf update
Step 2. Install required packages and dependencies.
Run the command below to install them:
dnf install gcc glibc glibc-common perl httpd php php-cli wget net-snmp gd gd-devel
Next, create Nagios user and group:
useradd nagios passwd nagios
Now create a groud for nagios setup “nagcmd” and add Nagios user to this group. Also, add a Nagios user in the apache group:
groupadd nagcmd usermod -a -G nagcmd nagios usermod -a -G nagcmd apache
Step 3. Installing Nagios on CentOS 8.
First, navigate to the Nagios Core downloads page and grab the latest Nagios core source code:
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.6.tar.gz tar xzf nagios-4.4.6.tar.gz cd nagios-4.4.6/
Perform the below steps to compile the Nagios from the source code:
./configure make all make install make install-groups-users make install-daemoninit make install-commandmode make install-config make install-webconf
We need to set up the password for the user nagiosadmin. This username will be used to access the web interface so it is important to remember the password that you will input here. Set the password running the following command and enter the password twice:
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Step 4. Installing Nagios on CentOS 8.
Before you download and install the Nagios plugins, you need to install the required packages for compiling and building the plugin package:
dnf install gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils
Then, download and extract the latest version of the Nagios Plugins:
wget --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.2.1.tar.gz tar zxf nagios-plugins.tar.gz
Move into the extracted directory, compile, build and install the Nagios Plugins:
cd nagios-plugins-release-2.2.1/ ./tools/setup ./configure make make install
Now you need to restart the apache service. Also, start and enable the Nagios service:
systemctl restart httpd.service systemctl start nagios.service systemctl start nagios.service systemctl start nagios.service
Step 5. Configure firewall for Nagios.
If you have a firewall running, you need to open port 80 in the firewall:
firewall-cmd --permanent --zone=public --add-port=80/tcp firewall-cmd --reload
Step 6. Accessing Nagios Web Interface.
Finally, you can now access the Nagios web console. Open your web browser and point it to the Nagios Core web directory, for example:
http://192.168.1.77/nagios OR http://idroot.us/nagios
When prompted for a username and password you will introduce the username “nagiosadmin” and the password that you entered in step 3. In case you forget this password you can modify it by rerunning the htpasswd command in step 3.
Congratulations! You have successfully installed Nagios. Thanks for using this tutorial for installing the Nagios monitoring tool in CentOS 8 systems. For additional help or useful information, we recommend you to check the official Nagios website.