Bài viết này hướng dẫn bạn cách cài Prometheus và Grafana trên hệ điều hành Linux (Ubuntu/RockyLinux), phù hợp cho mục đích giám sát server, ứng dụng và hệ thống.
1. Giới thiệu
Prometheus là hệ thống giám sát mã nguồn mở chuyên thu thập dữ liệu dạng time-series. Grafana là công cụ trực quan hóa dữ liệu mạnh mẽ, thường dùng chung với Prometheus để tạo dashboard.
2. Chuẩn Bị
- 1 server Linux (Ubuntu 20.04+ hoặc RockyLinux 8/9)
- Quyền
roothoặcsudo - Kết nối Internet
3. Cài Đặt Prometheus
3.1 Tạo user Prometheus
sudo useradd –no-create-home –shell /bin/false prometheus
3.2 Tải Prometheus
3.3 Cấu hình thư mục
3.4 Tạo file cấu hình Prometheus
File: /etc/systemd/system/prometheus.service/etc/prometheus/prometheus.yml
3.5 Khởi động Prometheus
sudo systemctl daemon-reload
sudo systemctl enable –now prometheus
sudo systemctl status prometheus
Prometheus sẽ chạy tại: http://SERVER_IP:9090
4. Cài Đặt Grafana
4.1 Thêm repository
Ubuntu:
sudo apt update sudo apt install -y software-properties-common sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" sudo wget -q -O /usr/share/keyrings/grafana.key https://packages.grafana.com/gpg.key echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
RockyLinux:
4.2 Cài đặt Grafana
4.3 Khởi động Grafana
sudo systemctl enable --now grafana-server
sudo systemctl status grafana-server
Grafana chạy tại: http://SERVER_IP:3000
Đăng nhập mặc định:
- Username: admin
- Password: admin
5. Kết nối Grafana với Prometheus
- Truy cập Grafana → Configuration → Data Sources
- Chọn Add data source
- Chọn Prometheus
- Nhập URL:
http://localhost:9090
- Bấm Save & Test
Như vậy Grafana đã kết nối thành công.
6. Thêm Dashboard
Grafana có nhiều dashboard dựng sẵn trên https://grafana.com/grafana/dashboards/
Các dashboard phổ biến:
- Node Exporter Full
- Docker Monitoring
- MySQL Exporter
Import bằng cách:
Dashboard → Import → Nhập ID hoặc file JSON
7. Kết luận
Bạn đã cài đặt xong Prometheus và Grafana trên Linux, cấu hình dữ liệu và có thể bắt đầu giám sát hệ thống. Tiếp theo, bạn có thể cài Node Exporter để giám sát Linux hoặc Windows Exporter cho Windows.









