Triển khai Prometheus giám sát hệ thống Server & Switch Mình vừa hoàn tất việc triển khai Prometheus để giám sát các máy chủ ảo (VM) và thiết bị mạng (Switch)
Dưới đây là các bước mình thực hiện – ngắn gọn, dễ hiểu và có thể áp dụng ngay.
Đây là cấu hình trích ra từ dự án thực tế.
🔧 1. Cài đặt Prometheus
Tạo user riêng cho Prometheus:
useradd --no-create-home --shell /bin/false prometheus
Tải và cài đặt Prometheus:
Tải bản release chính thức từ GitHub
Giải nén, copy binary vào /usr/local/bin/
Tạo thư mục cấu hình và dữ liệu:
mkdir -p /etc/prometheus /var/lib/prometheus
Cấu hình Prometheus:
Tạo file dịch vụ và khởi động Prometheus:
nano /etc/systemd/system/prometheus.service với nội dung sau:
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
systemctl daemon-reexec
systemctl enable --now prometheus
🖥️ 2. Cài Node Exporter để giám sát Server
Tạo user:
useradd --no-create-home --shell /bin/false node_exporter
Cài đặt Node Exporter:
Tải từ GitHub release
Giải nén, copy binary
Tạo file dịch vụ /etc/systemd/system/node_exporter.service
Thêm vào file với nội dung như sau:
[Unit]
Description=node_exporter
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=default.target
Khởi động dịch vụ:
systemctl enable --now node_exporter
Thêm vào file prometheus.yml:
scrape_configs:
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:9100']
🌐 3. Kiểm tra hệ thống
🔎 Truy cập Prometheus tại:
http://<ip-server>:9090
👉 Vào mục Status > Targets để kiểm tra các exporter đã UP chưa.
💡 Mẹo nhỏ dành cho anh em SysAdmin / SRE
✅ Nhớ restart Prometheus sau khi sửa file .yml
systemctl restart prometheus
✅ Kiểm tra cấu trúc YAML trước khi lưu:
👉 https://www.yamllint.com/
✅ Test exporter trước bằng curl:
curl http://localhost:9100/metrics