To monitor Apache2 on an Ubuntu server where Icinga agent is installed, while Icinga server is installed on another Ubuntu server, you can follow these step-by-step instructions. This guide assumes that Icinga 2 and Icinga Web 2 are properly installed and configured on your Icinga server, and the Icinga agent is installed and connected to your Icinga server.
Step 1: Install Necessary Plugins
On the Icinga Agent Server: Ensure you have the nagios-plugins package installed, as it includes the check for Apache. Install it using:
$ sudo apt-get update
$ sudo apt-get install nagios-plugins
Step 2: Configure Icinga Agent
Check the Apache Status Module: Make sure that the Apache status module is enabled on the Apache server. You can enable it with:
$ sudo a2enmod status
$ sudo systemctl restart apache2
Ensure the /etc/apache2/mods-enabled/status.conf is configured to allow access from the Icinga server IP. It might look something like this:
<Location /server-status>
SetHandler server-status
Require local
Require ip 192.168.x.x # IP of your Icinga server
</Location>
Configure the Agent: On the Icinga agent, ensure it can execute the Apache check. You might need to create a command in Icinga if it doesn’t exist:
object CheckCommand "check_apache_status" {
import "plugin-check-command"
command = [ PluginDir + "/check_http" ]
arguments = {
"-H" = "$address$"
"-u" = "/server-status?auto"
}
}
Step 3: Configure Icinga Server
Define the Host Object: If you haven't already defined the host object for the Apache server in your Icinga configuration, add it:
object Host "apache-server" {
import "generic-host"
address = "apache-agent-ip"
check_command = "hostalive"
}
Define Service for Apache Monitoring: Create a service definition to check Apache status:
apply Service "apache-status" {
import "generic-service"
check_command = "apache_status"
vars.address = "$host.address$"
assign where host.name == "apache-server"
}
OR
apply Service "apache-status" {
import "generic-service"
check_command = "http"
vars.address = "$host.address$"
assign where host.name == "apache-server"
}
Reload Icinga 2: After making changes to the configuration files, reload the Icinga 2 service to apply the changes:
sudo systemctl reload icinga2
Step 4: Verify the Configuration
Icinga Web 2: Log into Icinga Web 2 and navigate to the 'Services' section. You should see your new service for monitoring Apache. Verify that it is checking the status as expected.
Troubleshooting: If there are issues, check the Icinga 2 logs for any errors related to the Apache checks. The logs are usually located in /var/log/icinga2/icinga2.log.
===================================================== | |
Step 1 - Install icinga2 in Agent Server | |
===================================================== | |
8 apt update | |
9 apt -y install apt-transport-https wget gnupg | |
10 wget -O - https://packages.icinga.com/icinga.key | gpg --dearmor -o /usr/share/keyrings/icinga-archive-keyring.gpg | |
11 . /etc/os-release; if [ ! -z ${UBUNTU_CODENAME+x} ]; then DIST="${UBUNTU_CODENAME}"; else DIST="$(lsb_release -c| awk '{print $2}')"; fi; echo "deb [signed-by=/usr/share/keyrings/icinga-archive-keyring.gpg] https://packages.icinga.com/ubuntu icinga-${DIST} main" > /etc/apt/sources.list.d/${DIST}-icinga.list | |
12 apt update | |
13 apt install icinga2 | |
14 apt install monitoring-plugins | |
===================================================== | |
Step 2 - Enable icinga2 Agent | |
===================================================== | |
root@ip-172-31-4-57:~# icinga2 node wizard | |
Welcome to the Icinga 2 Setup Wizard! | |
We will guide you through all required configuration details. | |
Please specify if this is an agent/satellite setup ('n' installs a master setup) [Y/n]: Y | |
Starting the Agent/Satellite setup routine... | |
Please specify the common name (CN) [ip-172-31-4-57.ap-south-1.compute.internal]: | |
Please specify the parent endpoint(s) (master or satellite) where this node should connect to: | |
Master/Satellite Common Name (CN from your master/satellite node): ip-172-31-12-175.ap-south-1.compute.i nternal | |
Do you want to establish a connection to the parent node from this node? [Y/n]: Y | |
Please specify the master/satellite connection information: | |
Master/Satellite endpoint host (IP address or FQDN): 172.31.12.175 | |
Master/Satellite endpoint port [5665]: | |
Add more master/satellite endpoints? [y/N]: N | |
Parent certificate information: | |
Version: 3 | |
Subject: CN = ip-172-31-12-175.ap-south-1.compute.internal | |
Issuer: CN = Icinga CA | |
Valid From: May 10 04:17:19 2024 GMT | |
Valid Until: Jun 11 04:17:19 2025 GMT | |
Serial: f0:c6:d1:1c:f0:78:1b:6b:2d:7c:20:4b:1b:50:3c:be:f0:25:a2:17 | |
Signature Algorithm: sha256WithRSAEncryption | |
Subject Alt Names: ip-172-31-12-175.ap-south-1.compute.internal | |
Fingerprint: 54 FD AD AC 55 39 7F 7A 5F C2 2D BB 09 22 BE 43 08 15 FB DF 0D F6 5C 2B 76 15 0F C 1 DD 29 00 7B | |
Is this information correct? [y/N]: y | |
Please specify the request ticket generated on your Icinga 2 master (optional). | |
(Hint: # icinga2 pki ticket --cn 'ip-172-31-4-57.ap-south-1.compute.internal'): 94deed8004eefccb459689dbc6fe1112543b01eb | |
Please specify the API bind host/port (optional): | |
Bind Host []: | |
Bind Port []: | |
Accept config from parent node? [y/N]: y | |
Accept commands from parent node? [y/N]: y | |
Reconfiguring Icinga... | |
Disabling feature notification. Make sure to restart Icinga 2 for these changes to take effect. | |
Enabling feature api. Make sure to restart Icinga 2 for these changes to take effect. | |
Local zone name [ip-172-31-4-57.ap-south-1.compute.internal]: | |
Parent zone name [master]: | |
Default global zones: global-templates director-global | |
Do you want to specify additional global zones? [y/N]: | |
Do you want to disable the inclusion of the conf.d directory [Y/n]: n | |
Done. | |
Now restart your Icinga 2 daemon to finish the installation!\ | |
$ systemctl restart icinga2 | |
===================================================== | |
Step 3 - Install Apache 2 | |
===================================================== | |
26 apt-get update | |
27 apt install apache2 | |
28 clear | |
29 ls | |
30 systemctl start apache2 | |
31 systemctl status apache2 | |
===================================================== | |
Step 4 - Verify if Mod_Staus module in Apache2 | |
===================================================== | |
$ ls /etc/apache2/mods-enabled | grep status* | |
status.conf | |
status.load | |
$ sudo /usr/sbin/a2enmod status | |
Module status already enabled | |
Note - If you want to enable - follow this - https://www.devopsschool.com/blog/how-to-install-mod_status-on-your-apache-servers-and-enable-extendedstatus/ | |
===================================================== | |
Step 5 - Enable Mod Status Module from icinga server | |
===================================================== | |
$ more /etc/apache2/mods-enabled/status.conf | |
$ vi /etc/apache2/mods-enabled/status.conf | |
$ systemctl restart apache2 | |
<IfModule mod_status.c> | |
# Allow server status reports generated by mod_status, | |
# with the URL of http://servername/server-status | |
# Uncomment and change the "192.0.2.0/24" to allow access from other hosts. | |
<Location /server-status> | |
SetHandler server-status | |
Require local | |
Require ip 172.31.12.175 | |
</Location> | |
# Keep track of extended status information for each request | |
ExtendedStatus On | |
# Determine if mod_status displays the first 63 characters of a request or | |
# the last 63, assuming the request itself is greater than 63 chars. | |
# Default: Off | |
#SeeRequestTail On | |
<IfModule mod_proxy.c> | |
# Show Proxy LoadBalancer status in mod_status | |
ProxyStatus On | |
</IfModule> | |
</IfModule> | |
===================================================== | |
Step 6 - Enable Apache check in Icinga Server | |
===================================================== | |
49 cd /etc/icinga2/conf.d/ | |
50 ls | |
51 vi commands.conf | |
object CheckCommand "check_apache_status" { | |
import "plugin-check-command" | |
command = [ PluginDir + "/check_http" ] | |
arguments = { | |
"-H" = "$address$" | |
"-u" = "/server-status?auto" | |
} | |
} | |
OR | |
object CheckCommand "check_apache_status" { | |
import "plugin-check-command" | |
command = [ PluginDir + "/check_http" ] | |
arguments = { | |
"-H" = "172.31.4.57" | |
"-u" = "/server-status?auto" | |
} | |
} | |
$ systemctl restart icinga2 | |
$ systemctl status icinga2 |
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND