Followers

Nagios Installation

Install Nagios on Ubuntu 20.04

Last Updated: Tue, Oct 5, 2021 
Linux GuidesServer AppsUbuntu

Introduction

Nagios is an open-source tool for monitoring network applications, services, and other essential network devices. It detects faults through active monitoring and sends notification alerts when suspicious activity is detected. Similarly, it sends notifications when devices or services are back to their functional state.

It works on a Server/Agent architecture where the server that hosts Nagios (core) uses plugins to communicate with remote hosts through agents like the Nagios Remote Plugin Executor. The final reports generated from the logs are visually represented through the user interface.

This article explains how to install Nagios on Ubuntu 20.04 server.

Prerequisites

1. Install and Configure Nagios Core

  1. Update the system packages.

    $ sudo apt update
    
  2. Install all the required packages.

    $ sudo apt install wget unzip curl openssl build-essential libgd-dev libssl-dev libapache2-mod-php php-gd php apache2 -y
    
  3. Download Nagios Core Setup files. To download the latest version, visit the official releases site.

    $ wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.6.tar.gz
    
  4. Extract the downloaded files.

    $ sudo tar -zxvf nagios-4.4.6.tar.gz
    
  5. Navigate to the setup directory.

    $ cd nagios-4.4.6
    
  6. Run the Nagios Core configure script.

    $ sudo ./configure
    
  7. Compile the main program and CGIs.

    $ sudo make all
    
  8. Make and install group and user.

    $ sudo make install-groups-users
    
  9. Add www-data directories user to the nagios group.

    $ sudo usermod -a -G nagios www-data
    
  10. Install Nagios.

    $ sudo make install
    
  11. Initialize all the installation configuration scripts.

    $ sudo make install-init
    
  12. Install and configure permissions on the configs' directory.

    $ sudo make install-commandmode
    
  13. Install sample config files.

    $ sudo make install-config
    
  14. Install apache files.

    $ sudo make install-webconf
    
  15. Enable apache rewrite mode.

    $ sudo a2enmod rewrite
    
  16. Enable CGI config.

    $ sudo a2enmod cgi
    
  17. Restart the Apache service.

    $ sudo systemctl restart apache2
    
  18. Create a user and set the password when prompted.

    $ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users admin
    

2. Install Nagios Plugins

  1. Download the Nagios Core plugin. To download the latest plugins, visit the plugins download page.

    $ cd ~/
    
    $ wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
    
  2. Extract the downloaded plugin.

    $ sudo tar -zxvf nagios-plugins-2.3.3.tar.gz
    
  3. Navigate to the plugins' directory.

    $ cd nagios-plugins-2.3.3/
    
  4. Run the plugin configure script.

    $ sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
    
  5. Compile Nagios Core plugins.

    $ sudo make
    
  6. Install the plugins.

    $ sudo make install
    

3. Verify Nagios Configuration

  1. Verify the Nagios Core configuration.

    $ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    
  2. Start the Nagios service.

    $ sudo systemctl start nagios
    
  3. Enable Nagios service to run at system startup.

    $ sudo systemctl enable nagios
    

4. Access Nagios Web Interface

Open your web browser and access Nagios web interface via the URL http://ServerIP/nagios. For example:

http://192.0.2.10/nagios

You have successfully installed Nagios Core on your server. To log in, use admin as your username and the password you set during the user account creation step as your password. You can now access the dashboard and begin configuring Nagios.

5. Add Remote Hosts

Now that your Nagios server is configured, it's time to configure a remote host to monitor.

To get started, connect as root over SSH to the host you want to monitor.

Install Prerequisites

To monitor hosts, we need to add them to Nagios. By default, Nagios only monitors localhost (the server it's running on). We're going to add hosts that are part of our network to gain even more control. You will need to use the following instructions on all hosts that you want to monitor.

First, install nagios-plugins and nagios-nrpe-server:

# apt-get install nagios-plugins nagios-nrpe-server

Configure NRPE

Next, open the /etc/nagios/nrpe.cfg file. Replace the value of allowed_hosts with 127.0.0.1,0.0.0.0 replacing the second IP with the IP address of the Nagios server.

We will now open the file /etc/nagios/nrpe.cfg and replace a couple of values.

  • Replace the value of server_address to the private IP address of the host.

  • Set allowed_hosts to the private IP address of your Nagios server.

  • Execute df -h /, copy the output, and put that as the value of command. It indicates your root file system.

Save the file when you are finished.

Now restart NRPE:

service nagios-nrpe-server restart

Add the Host to Nagios

Now that we've configured the host we're going to monitor, we need to switch back to our Nagios server and add the host to it. Open the following file with your favorite editor:

# nano /usr/local/nagios/etc/servers/host.cfg

Use the following block as a template. Replace host with an appropriate name for your remote host, and update the host_namealias, and address values accordingly.

define host {

        use                             linux-server

        host_name                       yourhost

        alias                           My first Apache server

        address                         1.2.3.4

        max_check_attempts              5

        check_period                    24x7

        notification_interval           30

        notification_period             24x7

}

This will allow you to simply monitor whether the server is up or down. Now reload Nagios:

# service nagios reload

Congratulations, you have completed a very basic Nagios setup for monitoring your servers. Now you can log into the Nagios web panel to view the status of your servers.

COMMENTS

Name

Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
ltr
static_page
DevOpsWorld: Nagios Installation
Nagios Installation
DevOpsWorld
https://www.devopsworld.co.in/p/nagios-installation_16.html
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/p/nagios-installation_16.html
true
5997357714110665304
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content