متقدم
البحث فيأدلة التثبيت
طريقة البحث
  • الصق رسالة الخطأ بين علامتي تنصيص، مثل "permission denied"، لتجد جدول الحل.
  • اختر مجالًا وجزءًا من الدليل (التثبيت، أول الإعدادات، الاستخدام اليومي، الأمان، الحلول) لتصل مباشرة إلى الخطوة الصحيحة.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

الدليل 33Node Exporter · Monitoring

Install and set up Node Exporter (server metrics)

Node Exporter gives Prometheus the health numbers of a Linux server: CPU, memory, disk space and speed, network, load, systemd services and more — over 1,000 metrics on one page. It runs on every server you watch. This guide installs it on RHEL and Ubuntu (package or release file), chooses the collectors, adds your own metrics with the textfile collector (for example "last backup OK"), protects the endpoint with TLS and a password, and gives the queries and alerts you need first.

  • 10 الدروس
  • 16 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

33.1

Know it before you install

Node Exporter reads /proc and /sys and shows the values as text on http://SERVER:9100/metrics. Prometheus scrapes that page every 15–30 seconds. Collectors decide which groups of metrics are shown.

ItemValue
Ubuntu packageprometheus-node-exporter (service prometheus-node-exporter)
Release filenode_exporter from github.com/prometheus/node_exporter/releases (works on RHEL and Ubuntu)
Port9100/tcp
Flagsin the service file (or /etc/default/prometheus-node-exporter on Ubuntu)
Textfile folderfor example /var/lib/node_exporter/textfile/
Runs asa system user without login

33.2

Install on RHEL, Rocky, Alma and Fedora

Use the official release file (choose the version from the releases page):

useradd --system --no-create-home --shell /sbin/nologin node_exporter
NVER=1.9.1
curl -fsSLO https://github.com/prometheus/node_exporter/releases/download/v$NVER/node_exporter-$NVER.linux-amd64.tar.gz
curl -fsSLO https://github.com/prometheus/node_exporter/releases/download/v$NVER/sha256sums.txt
sha256sum -c --ignore-missing sha256sums.txt
node_exporter-1.9.1.linux-amd64.tar.gz: OK
tar -xzf node_exporter-$NVER.linux-amd64.tar.gz
install -m 0755 node_exporter-$NVER.linux-amd64/node_exporter /usr/local/bin/
mkdir -p /var/lib/node_exporter/textfile /etc/node_exporter
/etc/systemd/system/node_exporter.service
[Unit]
Description=Prometheus Node Exporter
After=network-online.target
 
[Service]
User=node_exporter
ExecStart=/usr/local/bin/node_exporter \
  --collector.systemd \
  --collector.processes \
  --collector.textfile.directory=/var/lib/node_exporter/textfile \
  --collector.filesystem.mount-points-exclude='^/(dev|proc|run|sys|var/lib/docker/.+|var/lib/containers/.+)($|/)' \
  --web.config.file=/etc/node_exporter/web.yml
Restart=on-failure
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=read-only
 
[Install]
WantedBy=multi-user.target

(Remove the --web.config.file line until you made that file — see "Make it safe".)

systemctl daemon-reload
systemctl enable --now node_exporter

33.3

Install on Ubuntu and Debian

The package is the quick way; it is a bit older than the release file:

apt-get update
apt-get install -y prometheus-node-exporter
systemctl status prometheus-node-exporter --no-pager

Add flags in /etc/default/prometheus-node-exporter (ARGS="--collector.systemd …") and restart. Or use the release file and service above — the same on all distributions.

الأوامر في هذا الدرس

33.4

First configuration: collectors and firewall

Check the page, then open the port only for the Prometheus server:

curl -s http://localhost:9100/metrics | grep -E '^node_(load1|memory_MemAvailable_bytes|filesystem_avail_bytes\{.*mountpoint="/")'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.5/32" port port="9100" protocol="tcp" accept'
firewall-cmd --reload
ufw allow from 10.0.0.5 to any port 9100 proto tcp
FlagWhy
--collector.systemdState of every systemd unit (alert when nginx.service fails).
--collector.processesProcess and thread counts.
--collector.textfile.directoryYour own metrics from scripts (below).
--collector.filesystem.mount-points-excludeNo noise from container and virtual file systems.
--no-collector.<name>Turn off a collector you do not need (for example --no-collector.wifi).

33.5

Your own metrics: the textfile collector

A script writes a .prom file; Node Exporter shows it. Example: report the backup result at the end of the nightly backup script:

cat > /usr/local/bin/backup-metric.sh <<'EOF'
#!/bin/sh
F=/var/lib/node_exporter/textfile/backup.prom
echo "# HELP backup_last_success_timestamp_seconds Last successful backup." > $F.tmp
echo "# TYPE backup_last_success_timestamp_seconds gauge" >> $F.tmp
echo "backup_last_success_timestamp_seconds $(date +%s)" >> $F.tmp
mv $F.tmp $F
EOF
chmod 755 /usr/local/bin/backup-metric.sh
/usr/local/bin/backup-metric.sh
curl -s localhost:9100/metrics | grep backup_last
backup_last_success_timestamp_seconds 1.7949e+09

Write to a .tmp file and mv it, so Node Exporter never reads half a file. Alert when the backup is older than 26 hours: time() - backup_last_success_timestamp_seconds > 26*3600.

33.6

Daily use: the queries and the first alerts

PromQL
100 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100
(1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100
100 * node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"} / node_filesystem_size_bytes
predict_linear(node_filesystem_avail_bytes{mountpoint="/"}[6h], 24*3600) < 0
rate(node_disk_io_time_seconds_total[5m])
node_load15 / count by (instance) (node_cpu_seconds_total{mode="idle"})
node_systemd_unit_state{state="failed"} == 1
rate(node_network_receive_errs_total[5m]) > 0

Real uses at work:

  • The base of every server dashboard (Grafana dashboard 1860 "Node Exporter Full").
  • Alerts: disk will be full in 24 hours, a systemd unit failed, memory pressure, server down (up == 0).
  • Your own checks: backup age, certificate days, pending updates — with the textfile collector.

33.7

Make it safe

The metrics page shows a lot about the server (users of processes, mounts, versions). Protect it with TLS and a password:

dnf -y install httpd-tools
htpasswd -nBC 12 "" | tr -d ':\n'
New password:
$2y$12$Zq…
/etc/node_exporter/web.yml
tls_server_config:
  cert_file: /etc/node_exporter/node.crt
  key_file: /etc/node_exporter/node.key
basic_auth_users:
  prometheus: $2y$12$Zq…

In Prometheus, add scheme: https, basic_auth and tls_config.ca_file to the job.

Security checklist:

  • Port 9100 only from the Prometheus server (firewall).
  • TLS and basic auth with --web.config.file on untrusted networks.
  • Run as its own user; the systemd hardening options above.
  • Textfile folder writable only by root and your scripts.
  • Update with new releases.

الأوامر في هذا الدرس

33.8

Update and remove

systemctl stop node_exporter
install -m 0755 node_exporter-1.9.2.linux-amd64/node_exporter /usr/local/bin/
systemctl start node_exporter
apt-get install --only-upgrade -y prometheus-node-exporter
systemctl disable --now node_exporter && rm /usr/local/bin/node_exporter /etc/systemd/system/node_exporter.service

33.9

Fix common problems

ProblemCauseFix
Target DOWN: context deadline exceededFirewall drops 9100.Open 9100 for the Prometheus IP.
Target DOWN: connection refusedService not running or another port.systemctl status node_exporter; ss -ltnp | grep 9100.
server returned HTTP status 401 UnauthorizedBasic auth set, Prometheus has no password.Add basic_auth to the scrape job.
textfile: failed to read …: invalid metric in the logBad format in a .prom file.Check the file; promtool check metrics < file.prom.
No node_systemd_* metricsThe systemd collector is off or has no D-Bus access.Add --collector.systemd; do not block D-Bus in hardening.
Too many filesystem seriesContainer overlay mounts.Use --collector.filesystem.mount-points-exclude (above).
Service fails to start: bind: address already in useTwo exporters (package + release file).Keep one; remove the other.

33.10

Next steps

1How do you show your own value (for example the last backup time) in Prometheus without writing an exporter?

Write it to a .prom file in the textfile collector folder.

2Which query finds systemd services that failed?

node_systemd_unit_state{state="failed"} == 1.

كل الأوامر في هذا الفصل