Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Using Nagios

Introduction

Nagios is an open-source monitoring tool that helps you monitor your network, servers, and applications. It provides alerts and notifications to ensure you are aware of any issues before they become critical. This tutorial will guide you through the process of installing and configuring Nagios on a Linux system.

Installation

Before we start, make sure your system is up-to-date. Run the following commands:

sudo apt update
sudo apt upgrade

Next, install the necessary prerequisites:

sudo apt install -y apache2 libapache2-mod-php7.2 php7.2 wget unzip

Now, download Nagios Core and Nagios Plugins:

wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.6.tar.gz
wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz

Extract the downloaded files:

tar zxvf nagios-4.4.6.tar.gz
tar zxvf nagios-plugins-2.3.3.tar.gz

Next, compile and install Nagios:

cd nagios-4.4.6
sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
sudo make all
sudo make install-groups-users
sudo usermod -a -G nagios www-data
sudo make install
sudo make install-daemoninit
sudo make install-commandmode
sudo make install-config
sudo make install-webconf

Enable Apache modules and restart Apache:

sudo a2enmod rewrite
sudo a2enmod cgi
sudo systemctl restart apache2

Create a Nagios admin user:

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Start and enable the Nagios service:

sudo systemctl start nagios
sudo systemctl enable nagios

Accessing Nagios Web Interface

Once Nagios is installed and running, you can access the Nagios web interface by navigating to http://your_server_ip/nagios in your web browser. Log in using the credentials you created during the installation process.

Configuring Nagios

To monitor hosts and services, you need to configure Nagios configuration files. These files are located in the /usr/local/nagios/etc/objects directory. The main configuration file is nagios.cfg, and it includes other configuration files.

To add a new host, edit the hosts.cfg file:

sudo nano /usr/local/nagios/etc/objects/hosts.cfg

Add the following configuration to define a new host:

<define a new host> <host> use linux-server host_name my-server alias My Server address 192.168.1.100 max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 </host>

Save and close the file. Next, edit the services.cfg file to define the services you want to monitor:

sudo nano /usr/local/nagios/etc/objects/services.cfg

Add the following configuration to define a new service:

<define a new service> <service> use generic-service host_name my-server service_description PING check_command check_ping!100.0,20%!500.0,60% </service>

Save and close the file. Restart Nagios to apply the changes:

sudo systemctl restart nagios

Monitoring with Nagios

Once your hosts and services are configured, you can monitor them through the Nagios web interface. Navigate to http://your_server_ip/nagios and log in. You will see the status of your hosts and services, along with any alerts and notifications.

To further customize your monitoring, you can create custom plugins and scripts. Nagios provides a flexible framework to extend its capabilities according to your needs.

Conclusion

Nagios is a powerful tool for monitoring your IT infrastructure. By following this tutorial, you should have a basic understanding of how to install, configure, and use Nagios. With its extensive customization options, Nagios can be tailored to fit the specific needs of your environment.