Prometheus: Add TLS encryption to Prometheus Node Exporter
This documentation is part of the Retrieving metrics from Linux guide. View the full guide here: How to retrieve Linux server metrics in Prometheus using Node Exporter.
👋 Welcome to the Stackhero documentation!
Stackhero delivers a fully managed Prometheus cloud platform designed for reliability and simplicity:
Alert Manageris built in, so you can route alerts directly toSlack,Mattermost,PagerDuty, and other popular destinations.- A dedicated email server lets you send unlimited email alerts without extra setup.
Blackboxis included, allowing you to probeHTTP,ICMP,TCP, and other protocols for comprehensive monitoring.- Configure your instance quickly using the online configuration file editor. There is no need to manage YAML by hand.
- Apply updates with a single click. Stackhero handles the upgrade process for you, minimizing downtime and manual intervention.
- High performance and strong security are built in, thanks to your own private, dedicated infrastructure.
Get up and running in about 5 minutes. Stackhero takes care of the setup so you can focus on monitoring, not maintenance. Try Prometheus cloud hosting on Stackhero to streamline your monitoring and alerting workflows.
By default, Node Exporter does not encrypt communications. This means that credentials, including the previously defined password, are transmitted in plain text. To secure communications, you can enable TLS encryption as follows.
Creating TLS certificates
Run the following commands to create a TLS certificate and key:
# Create TLS certificate
cd /tmp
sudo openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 \
-keyout /etc/prometheus_node_exporter/tlsCertificate.key \
-out /etc/prometheus_node_exporter/tlsCertificate.crt \
-subj "/CN=`hostname`" \
-addext "subjectAltName = DNS:`hostname`"
sudo chmod 600 /etc/prometheus_node_exporter/*
sudo chown -R node_exporter:node_exporter /etc/prometheus_node_exporter
Updating the configuration
Append the following lines to the configuration file to add TLS settings and then restart Node Exporter:
sudo cat << 'EOF' >> /etc/prometheus_node_exporter/configuration.yml
tls_server_config:
cert_file: /etc/prometheus_node_exporter/tlsCertificate.crt
key_file: /etc/prometheus_node_exporter/tlsCertificate.key
EOF
# Restart Prometheus Node Exporter
sudo systemctl restart node_exporter
You can verify that TLS is active by connecting via HTTPS with the following command:
curl -k -u prometheus:${password} https://localhost:9100/metrics
Note that this method does not use a CA certificate, so you need to pass the "-k" option to cURL to bypass certificate verification.