How to install and configure Nagios Core

Configurare noua (How To)

Situatie

1.Prerequisites

Make sure your system is updated and install necessary packages:

bash
sudo apt update && sudo apt upgrade -y
sudo apt install -y apache2 php libapache2-mod-php build-essential libgd-dev unzip curl openssl libssl-dev daemon

Create a Nagios user and group:

bash
sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios

Install required dependencies:

bash
sudo apt install -y gcc make autoconf libc6 libmcrypt-dev libssl-dev bc gawk dc build-essential snmp libnet-snmp-perl gettext

2.  Install Nagios Core

Step 1: Download Nagios Core

bash
cd /tmp
curl -LO https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.5.1.tar.gz
tar -xvzf nagios-4.5.1.tar.gz
cd nagios-4.5.1

Step 2: Compile and Install Nagios

bash
./configure --with-command-group=nagcmd
make all
sudo make install-groups-users
sudo make install
sudo make install-daemoninit
sudo make install-commandmode
sudo make install-config
sudo make install-webconf

Step 3: Set up Web Interface

Set up Apache user password:

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

Enable Apache modules and restart Apache:

bash
sudo a2enmod cgi rewrite
sudo systemctl restart apache2

3.  Install Nagios Plugins

Nagios uses plugins to monitor services.

bash
cd /tmp
curl -LO https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
tar -zxvf nagios-plugins-2.3.3.tar.gz
cd nagios-plugins-2.3.3
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
sudo make install

4. Install NRPE (for remote monitoring)

bash
sudo apt install -y nagios-nrpe-server nagios-plugins

Edit the NRPE config file on remote hosts (/etc/nagios/nrpe.cfg):

  • Add your Nagios server IP to allowed_hosts

  • Restart NRPE: sudo systemctl restart nagios-nrpe-server

On the Nagios server, install NRPE plugin:

bash
sudo apt install nagios-nrpe-plugin

5. Configure Nagios

Main configuration directory:
/usr/local/nagios/etc/

Verify default config:

bash
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Enable additional configs in nagios.cfg:

bash
cfg_dir=/usr/local/nagios/etc/servers

Create the directory:

bash
sudo mkdir /usr/local/nagios/etc/servers

6. Start Nagios and Access Web UI

Enable and start Nagios:

bash
sudo systemctl enable nagios
sudo systemctl start nagios

Access via browser:
http://<server_ip>/nagios/
Login with user: nagiosadmin and the password you set earlier.

7. Add Hosts and Services

 (/usr/local/nagios/etc/servers/webserver.cfg):

cfg
define host {
use linux-server
host_name webserver
alias Web Server
address 192.168.1.10
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
}
define service {
use generic-service
host_name webserver
service_description HTTP
check_command check_http
}

Restart Nagios:

bash
sudo systemctl restart nagios

8. Optional Enhancements

  • Email alerts: Configure contacts.cfg with email details

  • SSL for web UI: Use Let’s Encrypt or self-signed certs

  • Mobile UI: Install mobile-friendly frontends like NagiosMobile or Nagios V-Shell

  • NagiosQL / Centreon: Use GUIs for easier management

  • Performance Graphing: Integrate with PNP4Nagios or NagiosGraph.

Check for errors:

bash
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Log file:
/usr/local/nagios/var/nagios.log

Web Interface:
Monitor hosts/services and acknowledge problems.

Solutie

Tip solutie

Permanent

Voteaza

(5 din 9 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?