NavigationContentFooter
Jump toSuggest an edit

Configuring a Nagios Monitoring System on Scaleway

Reviewed on 16 September 2024Published on 19 June 2018
  • Nagios
  • monitoring
  • Apache

Monitoring your resources is an indispensable building block for the success of your SaaS or e-commerce application. An unnoticed system failure can have serious financial consequences and negatively impact your image. Therefore, you will learn by following this tutorial how to install and configure a Nagios monitoring application with an Apache web server to monitor your servers. It is an open-source monitoring system that can automatically alert you in case of a server dysfunction.

Before you start

To complete the actions presented below, you must have:

  • A Scaleway account logged into the console
  • Owner status or IAM permissions allowing you to perform actions in the intended Organization
  • An SSH key
  • At least 2 Instances or 2 Elastic Metal servers

Installing Nagios

In this tutorial, we will install and configure Nagios from its source to make sure that we have the latest version of the tool.

  1. Update the system and install the required packages:
    apt update && apt upgrade
    apt install wget build-essential apache2 php apache2-mod-php7.0 php-gd libgd-dev sendmail unzip
  2. Create a user to run Nagios:
    useradd nagios
    groupadd nagcmd
    usermod -a -G nagcmd nagios
    usermod -a -G nagios,nagcmd www-data
  3. Download the sources of Nagios, unpack the downloaded file and enter the directory:
    wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.10.tar.gz
    tar -xzf nagios*.tar.gz
    cd nagios-*
  4. Before compiling the software, define the user and group to use:
    ./configure --with-nagios-group=nagios --with-command-group=nagcmd
  5. Compile the software:
    make all
  6. Once it has been compiled, run the following make commands to install the application, init scripts and configuration files:
    make install
    make install-commandmode
    make install-init
    make install-config

Installing Apache

In this tutorial, we use Apache as a web server for the Nagios interface. Nagios provides a sample configuration file, that we will use.

  1. Copy the configuration file to the Apache directory:
    /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf
  2. Install the Nagios Plugins to have a set of tools to monitor your different services:
    apt install build-essential libssl-dev gcc
    wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-2.4.3/nagios-plugins-2.4.3.tar.gz
    tar -xzf nagios-plugins*.tar.gz
    cd nagios-plugins*
  3. Configure, compile, and install them with the following commands:
    ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
    make
    make install

Nagios and the required plugins are installed.

Configuring Nagios

To monitor servers, we have to configure Nagios by editing the file /usr/local/nagios/etc/nagios.cfg.

  1. Uncomment the line cfg_dir=/usr/local/nagios/etc/servers and save the file.
  2. Create the folder to store configurations:
    mkdir -p /usr/local/nagios/etc/servers
  3. Configure the contact email address in the file /usr/local/nagios/etc/objects/contacts.cfg:
    define contact{
    contact_name nagiosadmin ; Short name of user
    use generic-contact ; Inherit default values from generic-contact template (defined above)
    alias Nagios Admin ; Full name of user
    email nagios@localhost ; <<**\*** CHANGE THIS TO YOUR EMAIL ADDRESS **\*\***
    }

Configuring Apache

We are using the Apache web server as an application to serve the Nagios web interface.

  1. Start by enabling the required Apache modules:
    a2enmod rewrite
    a2enmod cgi
  2. Create a nagiosadmin user for the web interface with the htpasswd command:
    htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
  3. Enable the Apache vHost:
    ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/

Configuring the systemd script

By default, Nagios does not provide a systemd configuration file, so we have to create one by ourselves.

This file contains the information where systemd can find the Nagios executable and configuration files and when to start it.

  1. Create the file:

    nano /etc/systemd/system/nagios.service
  2. Put the following content in the file:

    [Unit]
    Description=Nagios
    BindTo=network.target
    [Install]
    WantedBy=multi-user.target
    [Service]
    Type=simple
    User=nagios
    Group=nagios
    ExecStart=/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg
  3. Save the file and enable the service:

    systemctl daemon-reload
    systemctl enable nagios.service
  4. Start the applications:

    systemctl restart apache2.service
    systemctl start nagios.service

    Your Nagios server is ready, and you can access the interface at http://your.server.ip.address/nagios.

    We use the nagiosadmin user and the password that you have created previously to log in.

  5. Once you are connected, click Hosts on the left to see what Nagios is monitoring. By default, it will only monitor the local host.

Monitoring a Server with the NPRE service

Important

NPRE is deprecated. Use this feature at your own risk.

The NPRE service (Nagios Remote Plugin Executor) is an add-on that allows you to execute Nagios commands on remote Linux servers. It is used to gather “local” information (like disk usage, RAM usage, CPU usage) of a remote machine. As this information is not broadcasted on the Internet, an agent has to run on the server which reports to the Nagios server.

Note

These steps have to be done on the remote server.

  1. Install the software on the remote server:

    apt install autoconf gcc libc6 libmcrypt-dev make libssl-dev wget bc gawk dc build-essential snmp libnet-snmp-perl gettext
  2. Download and unpack NRPE:

    cd /tmp
    wget --no-check-certificate -O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/master.tar.gz
    tar xzf nrpe.tar.gz
  3. Compile it with the following commands:

    cd /tmp/nrpe-master/
    ./configure --enable-command-args
    make all
  4. Create users and groups:

    make install-groups-users
  5. Install the configuration files:

    make install-config
  6. Install NRPE:

    make install
  7. Install the service, so NPRE can be managed by systemd:

    make install-init
    systemctl enable nrpe.service
  8. Edit the file /usr/local/nagios/etc/nrpe.cfg. Replace IP_of_your_Nagios_Server with the IP address of your Nagios host:

    allowed_hosts=127.0.0.1,IP_of_your_Nagios_Server
  9. Restart the service:

    systemctl start nrpe.service
  10. Download and install the Nagios plugins:

    wget http://www.nagios-plugins.org/download/nagios-plugins-2.4.0.tar.gz
    tar xfz nagios-plugins-2.2.1.tar.gz
    cd nagios-plugins-2.2.1/
    ./configure
    make all
    make install
    Note

    The following steps have to be done on the Nagios server

  11. On the Nagios server, create a configuration file in the directory /usr/local/nagios/etc/servers/ for each remote host that we want to monitor:

    nano /usr/local/nagios/etc/servers/remote_host.cfg
  12. Replace remote_host with the name of the remote server and put the following content in the file:

    # Remote Host configuration file
    define host {
    use linux-server
    host_name remote_host
    alias Remote Host
    address 163.172.168.167
    register 1
    }
    define service {
    host_name remote_host
    service_description PING
    check_command check_ping!100.0,20%!500.0,60%
    max_check_attempts 2
    check_interval 2
    retry_interval 2
    check_period 24x7
    check_freshness 1
    contact_groups admins
    notification_interval 2
    notification_period 24x7
    notifications_enabled 1
    register 1
    }
    define service {
    host_name remote_host
    service_description Disk Usage
    check_command check_local_disk!20%!10%!/
    max_check_attempts 2
    check_interval 2
    retry_interval 2
    check_period 24x7
    check_freshness 1
    contact_groups admins
    notification_interval 2
    notification_period 24x7
    notifications_enabled 1
    register 1
    }
    define service {
    host_name remote_host
    service_description SSH Service
    check_command check_ssh
    max_check_attempts 2
    check_interval 2
    retry_interval 2
    check_period 24x7
    check_freshness 1
    contact_groups admins
    notification_interval 2
    notification_period 24x7
    notifications_enabled 1
    register 1
    }

    This file will monitor if the remote host replies on ping, the disk usage of the host, and if the SSH service is up. You can find more configuration examples in the file /usr/local/nagios/etc/objects/commands.cfg. Nagios allows you to monitor a wide range of services.

  13. Save the file and restart the application:

    systemctl restart nagios.service

    The remote server will appear in your Nagios interface and you can see the status of the monitored services:

Nagios is widely used because of its flexibility and versatility. Do not hesitate to refer to the official documentation of the software to find more out about further configuration options.

Was this page helpful?
API DocsScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCareers
© 2023-2024 – Scaleway