Docker & DevOps

Trên AlmaLinux 9: Hướng dẫn cài đặt Node Exporter và Promtail đẩy metric về Grafana

Cập nhật: 2 phút đọc
Mục lục
  1. Cài đặt Node Exporter trên AlmaLinux 9
  2. Cấu hình Promtail đẩy Log về Grafana Loki
  3. Bảng đối chiếu vai trò Node Exporter và Promtail
  4. Câu hỏi thường gặp (FAQ)
  5. Có nên mở cổng 9100 của Node Exporter ra toàn Internet không?
  6. Promtail không đọc được /var/log/messages trên AlmaLinux 9 là do đâu?
  7. Node Exporter + Promtail tốn bao nhiêu tài nguyên trên mỗi VPS?

Hướng dẫn cài đặt Node Exporter và Promtail trên AlmaLinux 9 để thu thập chỉ số CPU, RAM, Disk IOPS và log hệ thống đẩy về Prometheus/Grafana Loki.

Trên AlmaLinux 9: Hướng dẫn cài đặt Node Exporter và Promtail đẩy metric về Grafana

Khi vận hành nhiều máy chủ VPS Việt Nam cho hệ thống microservices hoặc web traffic cao, việc chỉ SSH vào gõ htop là không đủ để bắt được các điểm nghẽn xảy ra lúc nửa đêm. Trên AlmaLinux 9, bộ đôi Node Exporter (thu thập metric phần cứng) và Promtail (thu thập log đẩy về Grafana Loki) là giải pháp giám sát chuẩn mực, tiêu tốn cực ít tài nguyên.

Tóm tắt nhanh (TL;DR): - Cài đặt node_exporter chạy dưới user hệ thống không quyền login, lắng nghe trên cổng 9100 (chỉ mở qua IP VPN nội bộ). - Cài đặt promtail đọc /var/log/messages hoặc systemd-journal đẩy thẳng về Grafana Loki trung tâm. - Chú ý cấu hình SELinux trên AlmaLinux 9 để Promtail đọc được log hệ thống mà không cần tắt SELinux. - Cập nhật: 11/2026

Cài đặt Node Exporter trên AlmaLinux 9

Tạo user node_exporter, tải bản phát hành chính thức và chạy bằng systemd (xem thêm các giải pháp giám sát):

sudo useradd --no-create-home --shell /sbin/nologin node_exporter
curl -LO https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz
tar xvf node_exporter-1.8.2.linux-amd64.tar.gz
sudo cp node_exporter-1.8.2.linux-amd64/node_exporter /usr/local/bin/
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter

Tạo file /etc/systemd/system/node_exporter.service và mở cổng 9100 chỉ cho IP máy chủ Prometheus (ví dụ qua WireGuard 10.10.0.0/24):

sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.10.0.0/24" port protocol="tcp" port="9100" accept'
sudo firewall-cmd --reload
sudo systemctl enable --now node_exporter

Cấu hình Promtail đẩy Log về Grafana Loki

Cấu hình /etc/promtail/config.yml để đẩy log dịch vụ Nginx và SSH về Loki server:

server:
  http_listen_port: 9080
positions:
  filename: /tmp/positions.yaml
clients:
  - url: http://10.10.0.10:3100/loki/api/v1/push
scrape_configs:
  - job_name: system
    static_configs:
      - targets: [localhost]
        labels:
          job: varlogs
          host: almalinux-node-01
          __path__: /var/log/nginx/*.log

Bảng đối chiếu vai trò Node Exporter và Promtail

Công cụLoại dữ liệu thu thậpGiao thức / CổngĐích lưu trữ
Node ExporterCPU, RAM, Disk IOPS, NetworkHTTP Pull (:9100/metrics)Prometheus / VictoriaMetrics
PromtailSystem log, Nginx log, JournaldHTTP Push (:3100/loki/api/v1/push)Grafana Loki

Kết hợp dữ liệu từ Node Exporter sẽ giúp bạn tinh chỉnh chính xác hơn khi áp dụng TCP BBRv3 Production, tối ưu Falco Kubernetes hoặc cài đặt MPTCP. Tham khảo thêm bảng giá VPS để chọn node lưu trữ Grafana/Prometheus riêng.

Dựng hệ thống Observability mượt mà tại ThueCloud.Vn: Hạ tầng KVM Enterprise NVMe tại vn-hn, VAT 0%, SLA 99,9%, hoàn tiền 07 ngày. Gói VPS VN 1 (45.000đ–60.000đ/tháng) chạy nhẹ nhàng cho từng node con, còn VPS VN 3 (139.000đ–170.000đ/tháng) lý tưởng làm máy chủ trung tâm Prometheus + Grafana Loki.

Câu hỏi thường gặp (FAQ)

Có nên mở cổng 9100 của Node Exporter ra toàn Internet không?

Không. Dù Node Exporter chỉ xuất metric phần cứng, việc mở công khai dễ lộ thông tin cấu hình và có thể bị quét. Hãy chỉ mở cổng 9100 trên dải IP mạng nội bộ hoặc WireGuard VPN.

Promtail không đọc được /var/log/messages trên AlmaLinux 9 là do đâu?

Thường do user chạy Promtail không thuộc nhóm adm hoặc systemd-journal. Hãy thêm user promtail vào các nhóm này (usermod -aG adm,systemd-journal promtail) và kiểm tra quyền SELinux.

Node Exporter + Promtail tốn bao nhiêu tài nguyên trên mỗi VPS?

Cả hai tiến trình chỉ tiêu thụ tổng cộng khoảng 40–70 MB RAM và dưới 1% CPU trên một VPS có tải thông thường.