Installation of Nagios Monitoring Software on Ubuntu EC2 Instance
Prerequisite : 2 EC2 Ubuntu Instance
Server Machine----172.16.0.5 (Private IP)
Client Machine----172.16.0.6 (Client IP)
Step 1 - Install Packages Dependencies
1.Update the Ubuntu repository using the apt command below.
sudo apt update
2.install packages dependencies for Nagios installation.
sudo apt install -y autoconf bc gawk dc build-essential gcc libc6 make wget unzip apache2 php
libapache2-mod-php libgd-dev libmcrypt-dev make libssl-dev snmp libnet-snmp-perl gettext
Step 2 - Install Nagios Core 4.4.6
3.Go to your home directory and download the Nagios Core source code
cd ~/
wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.6.tar.gz
4.Extract the Nagios package and go to the extracted Nagios directory.
tar -xf nagios-4.4.6.tar.gz
cd nagioscore-*/
5.compile Nagios source code and define the Apache virtual host configuration for Nagios.
sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
sudo make all
6.Create the Nagios user and group, and add the 'www-data' Apache user to the 'nagios' group
sudo make install-groups-users
sudo usermod -a -G nagios www-data
7.Install Nagios binaries, service daemon script, and the command mode.
sudo make install
sudo make install-daemoninit
sudo make install-commandmode
8.install the sample script configuration.
sudo make install-config
9.Then install the Apache configuration for Nagios and activate the mod_rewrite and mode_cgi modules.
sudo make install-webconf
sudo a2enmod rewrite cgi
10.Now restart the Apache service.
sudo systemctl restart apache2
11.After installing the Nagios Core, we will add the basic authentication for accessing the Nagios dashboard. And we will be using the basic Apache authentication.
Create a new apache basic authentication for the user the "nagiosadmin".
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
12.For the firewall configuration, you will need to add the Apache service and the Nagios server port to the UFW firewall.
Add the SSH and Apache HTTP port using the ufw command below.
sudo su
for svc in Apache ssh;
do ufw allow $svc;
done
13.start the UFW firewall service and add it to the system boot
ufw enable
Type 'y' and the UFW firewall service will be activate.
14.Now check all available rules using the command below.
ufw status numbered
Now you will get both the SSH and Apache services added to the UFW firewall.
Step 3 - Install Nagios Plugins and NRPE Plugin
15.we will install the Nagios Plugins and NRPE Plugins.
Both Nagios and NRPE plugins are available by default on the Ubuntu repository. You can install those packages using the apt command below.
apt install monitoring-plugins nagios-nrpe-plugin
16.go to the nagios installation directory "/usr/local/nagios/etc" and create a new directory for for storing all server hosts configuration
cd /usr/local/nagios/etc
mkdir -p /usr/local/nagios/etc/servers
17.edit the Nagios configuration 'nagios.cfg' using vim editor
vim nagios.cfg
Uncomment the 'cfg_dir' option that will be used for sotring all server hots configurations.
cfg_dir=/usr/local/nagios/etc/servers
escape :wq (to save and close)
18.edit the configuration file "resource.cfg" and define the path binary files of Nagios Monitoring Plugins.
vim resource.cfg
Define the Nagios Monitoring Plugins path by changing the default configuration as below.
$USER1$=/usr/lib/nagios/plugins
escape :wq (to save and close)
19.After that, add the nagios admin email contacts by editing the configuration file "objects/contacts.cfg"
vim objects/contacts.cfg
Change the email address with your own.
define contact{
......
email email@host.com
}
escape :wq (to save and close)
20.Now define the nrpe check command by editing the configuration file "objects/commands.cfg".
vim objects/commands.cfg
Add the following configuration to the end of the line.
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
escape :wq (to save and close)
21.start the Nagios service and add it to the system boot.
systemctl start nagios
systemctl enable nagios
22.The Nagios service is up and running, check using the following command
systemctl status nagios
23.Nagios service is up and running. Now we need to restart the Apache service to apply a new Nagios configuration
systemctl restart apache2
And the Nagios configuration has been completed.
Open your web browser and type the server IP address following the "nagios" URL path. http://172.16.0.5/nagios/
Client Machine----
23.Once you've logged in, update the Ubuntu repository and install Nagios Plugins and NRPE Server.
sudo apt update
sudo apt install nagios-nrpe-server monitoring-plugins
24.Next, go to the NRPE installation directory "/etc/nagios" and edit the configuration file "nrpe.cfg".
cd /etc/nagios
sudo chmod +777 nrpe.cfg
vim nrpe.cfg
Uncomment the "server_address" line and change the value with the "client01" IP address.
server_address=172.16.0.6
One the "allowed_hosts" line, add the Nagios Server IP address "172.16.0.5".
allowed_hosts=127.0.0.1,::1,172.16.0.5
escape :wq (to save and close)
25.Next, edit the "nrpe_local.cfg" configuration.
sudo chmod +777 nrpe_local.cfg
vim nrpe_local.cfg
Change the IP address with the "client01" IP address, and paste the configuration into it.
command[check_root]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_ping]=/usr/lib/nagios/plugins/check_ping -H 172.16.0.6 -w 100.0,20% -c 500.0,60% -p 5
command[check_ssh]=/usr/lib/nagios/plugins/check_ssh -4 172.16.0.6
command[check_http]=/usr/lib/nagios/plugins/check_http -I 172.16.0.6
command[check_apt]=/usr/lib/nagios/plugins/check_apt
escape :wq (to save and close)
26.Now restart the NRPE service and add it to the system boot.
sudo systemctl restart nagios-nrpe-server
sudo systemctl enable nagios-nrpe-server
27.Check the NRPE service using the following command.
sudo systemctl status nagios-nrpe-server
Add Hosts Configuration to the Nagios Server
28.Back to the Nagios server terminal, go to the "/usr/local/nagios/etc" directory and create a new configuration "server/client01.cfg".
cd /usr/local/nagios/etc
vim servers/client.cfg
define host {
use linux-server
host_name client01
alias Ubuntu Host
address 172.16.0.6
register 1
}
define service {
host_name client01
service_description PING
check_command check_nrpe!check_ping
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 client01
service_description Check Users
check_command check_nrpe!check_users
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 client01
service_description Check SSH
check_command check_nrpe!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
}
define service {
host_name client01
service_description Check Root / Disk
check_command check_nrpe!check_root
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 client01
service_description Check APT Update
check_command check_nrpe!check_apt
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 client01
service_description Check HTTP
check_command check_nrpe!check_http
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
}
escape :wq (to save and close)
29.Now restart the Nagios Server.
sudo systemctl restart nagios
No Comments Yet!!