- Deploy a fully updated Ubuntu 20.04 Server.
- Create a non-root user with sudo access.
-
Update the system packages.
sudo apt update
-
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
-
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
-
Extract the downloaded files.
sudo tar -zxvf nagios-4.4.6.tar.gz
-
Navigate to the setup directory.
cd nagios-4.4.6
-
Run the Nagios Core configure script.
sudo ./configure
-
Compile the main program and CGIs.
sudo make all
-
Make and install group and user.
sudo make install-groups-users
-
Add www-data directories user to the nagios group.
sudo usermod -a -G nagios www-data
-
Install Nagios.
sudo make install
-
Initialize all the installation configuration scripts.
sudo make install-init
-
Install and configure permissions on the configs' directory.
sudo make install-commandmode
-
Install sample config files.
sudo make install-config
-
Install apache files.
sudo make install-webconf
-
Enable apache rewrite mode.
sudo a2enmod rewrite
-
Enable CGI config.
sudo a2enmod cgi
-
Restart the Apache service.
sudo systemctl restart apache2
-
Create a user and set the password when prompted.
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users admin
-
provide access to 'admin' user to monitor the hosts and services
sudo vi /usr/local/nagios/etc/cgi.cfg
NOTE: For bulk replace in vi enter as below :%s/nagiosadmin/nagiosadmin,admin/gi
and save the file
-
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
-
Extract the downloaded plugin.
sudo tar -zxvf nagios-plugins-2.3.3.tar.gz
-
Navigate to the plugins' directory.
cd nagios-plugins-2.3.3/
-
Run the plugin configure script.
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
-
Compile Nagios Core plugins.
sudo make
-
Install the plugins.
sudo make install
-
Add / uncomment below to
nagios.cgi
file.sudo nano /usr/local/nagios/etc/nagios.cfg
cfg_dir=/usr/local/nagios/etc/services
Save the file
-
Verify the Nagios Core configuration.
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
-
Start the Nagios service.
sudo systemctl start nagios
-
Enable Nagios service to run at system startup.
sudo systemctl enable nagios
Open your web browser and access Nagios web interface via the URL http://ServerIP/nagios
. For my case:
http://192.168.122.162/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.
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:
sudo apt-get install nagios-plugins nagios-nrpe-server
open the /etc/nagios/nrpe.cfg file. Replace the value of allowed_hosts
with 127.0.0.1,nagios_server_IP
and server_address
with 0.0.0.0
Save the file when you are finished.
restart NRPE:
sudo systemctl restart nagios-nrpe-server
or service nagios-nrpe-server restart
-
Create folder and file
/usr/local/nagios/etc/servers/host.cfg
and update file as belowsudo mkdir -p /usr/local/nagios/etc/servers/
sudo 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 thehost_name
,alias
, andaddress
values accordingly.define host { use linux-server host_name nagios-cli1 alias My first Apache server address 192.168.122.145 max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 }
save the file
-
Uncomment following in
/usr/local/nagios/etc/nagios.cfg
file.Open file
sudo nano /usr/local/nagios/etc/nagios.cfg
Uncomment below and save the file
cfg_file=/usr/local/nagios/etc/services.cfg
-
Verify nagios configuration files syntax
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
-
restart or reload the nagios servie
sudo systemctl restart nagios
orsudo systemctl reload nagios
Open your web browser and access Nagios web interface via the URL http://ServerIP/nagios
. For my case:
http://192.168.122.162/nagios