Nagios is an open-source monitoring software that allows system administrators to monitor the health and performance of servers, applications, and network devices. Nagios provides a comprehensive solution for monitoring the IT infrastructure and can alert administrators of potential problems before they become critical.
In this article, we will go over the steps to install Nagios on CentOS and Red Hat Enterprise Linux (RHEL) 9/8. These steps cover everything from downloading the software to configuring authentication for the Nagios web interface.
By the end of this article, you will have a fully functional Nagios server that can be used to monitor your IT infrastructure. So, let’s get started!
Before we begin, make sure that you have a server running either CentOS or RHEL 9/8, with root access or a user with sudo privileges. Additionally, ensure that your server is up-to-date by running the following command:
sudo yum update -y
Step 1: Install Required Dependencies
Before we install Nagios, we need to install a few dependencies: Apache web server, PHP, and GCC. You can install these by running the following command:
sudo yum groupinstall "development tools"
sudo yum install httpd php php-cli gcc unzip wget glibc glibc-common gd gd-devel net-snmp
Step 2: Create a Nagios User and Group
Nagios requires a user and group to run its processes. To create these, run the following commands:
sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd apache
Step 3: Download Nagios Core
To download Nagios Core, we will use the wget command to download the latest version of Nagios Core from the official website. At the time of writing, the latest version is 4.4.5. Run the following command to download it:
Once the archive has been downloaded, we can extract it using the following command:
tar xzf nagios-4.4.10.tar.gz
Step 4: Compile Nagios Core
To compile Nagios Core, navigate to the extracted directory using the following command:
Next, run the following command to compile Nagios Core:
Step 5: Install Nagios Core
Once the compilation is complete, we can install Nagios Core by running the following commands:
sudo make install
sudo make install-commandmode
sudo make install-init
sudo make install-config
sudo make install-webconf
Step 6: Install Nagios Plugins
Nagios Plugins are required to extend the functionality of Nagios Core. After installing and configuring core service, Download latest nagios-plugins source and install using the following commands.
sudo tar xzf nagios-plugins-2.4.3.tar.gz
Now compile and install nagios plugins
./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
sudo make install
Step 7: Configure Nagios
To configure Nagios, we need to edit the Nagios configuration file. To do this, run the following command:
sudo nano /usr/local/nagios/etc/nagios.cfg
In the configuration file, check for the following line, add them if not available:
Save and close the file.
Step 8: Set up Authentication
By default, Nagios requires authentication to access the web interface. To set up authentication, run the following command to create an admin user:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Enter a strong password to complete the process.
Step 9: Verify and Start Services
First, verify the Nagios configuration file using the following command.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If there is no error found, run the following command to enable and start Nagios service:
sudo systemctl enable nagios
sudo systemctl start nagios
Next, start the Apache web server using the following command:
sudo systemctl start httpd
Step 10: Access the Nagios Web Interface
Finally, you can access the Nagios web interface by navigating to http://your-server-ip-hostname/nagios in your web browser. You will be prompted to enter the username and password you created in step 8.
After successful authentication, you will get the Nagios core dashboard access.
Here you can find the detailed information about Nagios hosts, services, notification etc.
In this article, we have gone over the steps to install Nagios on CentOS and RHEL 9/8. Nagios is a powerful open-source monitoring software that can help you monitor the health and performance of your systems and applications. With the steps outlined in this article, you should be able to get Nagios up and running on your server in no time.