Installation of blackbox exporter in production environment consists from following high level steps:
-
Install exporter;
-
Configure authentication;
-
Configure firewall;
-
Configure service for autostart and restart;
-
Check access to exporter from I&B monitoring platform.
1. Install blackbox exporter.
-
Check latest version, available platforms on blackbox_exporter GitHub page and make necessary changes in variables on next step.
-
Prepare environment variables to simplify installation and configuration process.
export EXPORTER_VERSION=0.27.0
export EXPORTER_PLATFORM=linux-amd64
-
Download exporter
wget https://github.com/prometheus/blackbox_exporter/releases/download/v$EXPORTER_VERSION/blackbox_exporter-$EXPORTER_VERSION.$EXPORTER_PLATFORM.tar.gz
-
Create directory /usr/local/bin/blackbox_exporter and untar exporter into it.
sudo mkdir -p /usr/local/bin/blackbox_exporter
sudo tar xvfz blackbox_exporter-$EXPORTER_VERSION.$EXPORTER_PLATFORM.tar.gz -C /usr/local/bin/blackbox_exporter
-
Create prometheus user. If it already exist - go to step 6.
Fedora (RHEL, CentOS)
sudo useradd -M -s /sbin/nologin prometheus
-
-M(or--no-create-home): This option prevents the creation of a home directory for the new user; -
-s /sbin/nologin: This option sets the user's login shell to/sbin/nologin. This effectively prevents the user from interactively logging into the system. While the user won't have a password set, this further ensures they cannot log in.
Debian (Ubuntu)
sudo useradd -s /sbin/nologin prometheus --no-create-home
-
Make prometheus user owner of blackbox_exporter directory
sudo chown -hR prometheus:prometheus /usr/local/bin/blackbox_exporter
2. Configure firewall
Configure firewall on resource
-
blackbox exporter uses default port 9115, so allow it in firewall on resource.
Fedora (RHEL, CentOS)
sudo firewall-cmd --zone=public --add-port=9115/tcp --permanent
sudo systemctl reload firewalld
Check firewall configuration
sudo firewall-cmd --list-all
You should see in output:
ports: 9115/tcp
Debian (Ubuntu)
sudo ufw allow 9115
You should see in output:
Rules updated
Rules updated (v6)
Check firewall configuration
sudo ufw status
You should see in output:
To Action From
-- ------ ----
9115 ALLOW Anywhere
its good
3. Configure authentication for exporter
Do the steps described in Exporters configuration → Authentication section.
4. Check configuration
-
Create config file with command
sudo nano /usr/local/bin/blackbox_exporter/config.yml
-
And paste into file minimal configuration for tests
modules:
http_2xx:
prober: http
-
Run blackbox_exporter
/usr/local/bin/blackbox_exporter/blackbox_exporter-$EXPORTER_VERSION.$EXPORTER_PLATFORM/blackbox_exporter --config.file /usr/local/bin/blackbox_exporter/config.yml --web.config.file=/usr/local/bin/blackbox_exporter/web-config.yml
In output you should see:
... msg="Loaded config file"
... msg="TLS is enabled." ...
Check with browser if it is accessible at:
https://resource-hostname-or-ip:9115/metrics
After entering exporter’s user name and password you should see page like this:
# HELP blackbox_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, goversion from which blackbox_exporter was built, and the goos and goarch for the build.
# TYPE blackbox_exporter_build_info gauge
blackbox_exporter_build_info{branch="HEAD",goarch="amd64",goos="linux",goversion="go1.24.4",revision="46ea0224f57b708fdff317f8872765a77ef64034",tags="unknown",version="0.27.0"} 1
# HELP blackbox_exporter_config_last_reload_success_timestamp_seconds Timestamp of the last successful configuration reload.
# TYPE blackbox_exporter_config_last_reload_success_timestamp_seconds gauge
blackbox_exporter_config_last_reload_success_timestamp_seconds 1.759910771420019e+09
...
Stop blackbox exporter with Ctrl-c in terminal where you run it.
Make blackbox_exporter service for autostart and restart.
Create file with your preferred text editor, for example nano …
sudo nano /etc/systemd/system/blackbox_exporter.service
… and paste following text into it.
[Unit]
Description=blackbox Exporter
[Service]
User=prometheus
ExecStart=/usr/local/bin/blackbox_exporter/blackbox_exporter-0.27.0.linux-amd64/blackbox_exporter --config.file /usr/local/bin/blackbox_exporter/config.yml --web.config.file=/usr/local/bin/blackbox_exporter/web-config.yml
[Install]
WantedBy=multi-user.target
Save file and exit editor.
Start service …
sudo systemctl daemon-reload
sudo systemctl start blackbox_exporter
sudo systemctl enable blackbox_exporter
… and check
sudo systemctl status blackbox_exporter
You should see following output similar to:
In case of any problem, you should view log entries for service:
journalctl -u blackbox_exporter.service -e
Now blackbox exporter is ready to accept data and then expose it to Prometheus.