In today’s fast-paced and technology-driven world, businesses rely heavily on their IT infrastructure. To ensure smooth operations and minimize downtime, it is crucial to have a robust monitoring system in place. Nagios, a powerful free and open-source monitoring tool, is widely used to monitor Linux and Windows servers, networks, and infrastructure.
In this article, we will guide you through the process of installing Nagios Core on an Ubuntu 22.04 server. We will cover the prerequisites, installation steps, and configuration process to help you set up Nagios successfully.
Prerequisites
Before we begin the installation process, let’s go over the prerequisites:
- A server running Ubuntu 22.04.
- A root password configured on the server.
To ensure a smooth installation, we need to update the system packages and install the necessary dependencies. Open the terminal and run the following commands:
apt-get update -y apt-get install wget unzip vim curl openssl build-essential libgd-dev libssl-dev libapache2-mod-php php-gd php apache2 -y
Installing Nagios Core from Source
By default, the latest version of Nagios Core might not be available in the Ubuntu 22.04 default repository. Therefore, it is recommended to compile Nagios from the source.
Let’s start by downloading the latest version of Nagios Core from the Git repository. Run the following command in the terminal:
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.7.tar.gz
Once the download is complete, extract the downloaded file using the following command:
tar -xvzf nagios-4.4.7.tar.gz
Next, navigate to the extracted directory and configure Nagios Core by running the following command:
cd nagios-4.4.7 ./configure --with-httpd-conf=/etc/apache2/sites-enabled
Review the configuration summary to ensure all options are accurate. If everything looks good, proceed to compile Nagios by running the following command:
make all
After the compilation process is complete, create the required user and group by executing the following command:
make install-groups-users usermod -a -G nagios www-data
Now, install Nagios Core by running the following command:
make install
To manage the Nagios service, we need to create a systemd service file. Execute the following command:
make install-daemoninit
Set the appropriate permissions on the Nagios installation directory with the following command:
make install-commandmode
Create a sample Nagios configuration file by running the following command:
make install-config
Install the Nagios web interface using the following command:
make install-webconf
Next, enable the required Apache modules by executing the following commands:
a2enmod rewrite cgi
Restart the Apache service to apply the changes:
systemctl restart apache2
To enhance the visual appearance of the Nagios web interface, we can install a theme. Run the following command:
make install-exfoliation
Creating a Nagios Admin User
To access the Nagios web interface, we need to create an admin user. Execute the following command in the terminal:
htpasswd -c /usr/local/nagios /etc/htpasswd.users nagiosadmin
You will be prompted to set a password for the admin user. Enter the desired password and confirm it.
Installing Nagios Plugins
To monitor system services effectively, we need to install Nagios plugins. Let’s download the plugins from the Git repository:
wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-2.4.0/nagios-plugins-2.4.0.tar.gz
Extract the downloaded file using the following command:
tar -xvzf nagios-plugins-2.4.0.tar.gz
Navigate to the extracted directory and configure the plugins:
cd nagios-plugins-2.4.0 ./configure --with-nagios-user=nagios --with-nagios-group=nagios
Compile and install the plugins by running the following commands:
make make install
To verify the sample Nagios configuration files before starting the service, execute the following command:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If there are no errors, you should see a confirmation message indicating that the configuration check was successful.
Starting the Nagios Service
Now that Nagios is installed, let’s start the service and configure it to start automatically on system reboot. Run the following commands:
systemctl start nagios systemctl enable nagios
To check the status of the Nagios service, use the following command:
systemctl status nagios
If Nagios is running correctly, you should see a message indicating that the service is active.
Accessing the Nagios Web Interface
To access the Nagios web interface, open your web browser and enter the URL http://your-server-ip/nagios. You will be redirected to the Nagios login screen.
Enter the admin username and password that you created earlier, and click on the “OK” button. You should now have access to the Nagios default dashboard.
Conclusion
Congratulations! You have successfully installed Nagios Core on your Ubuntu 22.04 server. With Nagios, you can now monitor your Linux and Windows servers, network, and infrastructure with ease. Remember to customize your monitoring setup according to your specific needs.
If you require assistance with Nagios installation or need help with your cloud hosting solutions, don’t hesitate to reach out to Shape.host. Shape.host offers reliable and scalable Cloud VPS services, ensuring your business operates smoothly without any interruptions.