---
title: "Docker Grafana + Prometheus: Hướng dẫn cài đặt với Docker Compose và chứng chỉ SSL tự động"
description: "Hướng dẫn triển khai bộ giám sát Grafana + Prometheus + Node Exporter bằng Docker Compose trên VPS NVMe, kèm reverse proxy và chứng chỉ SSL tự động."
canonical: "https://thuecloud.vn/docker-grafana-prometheus-huong-dan-cai-dat-voi-docker-compose-va-chung-chi-ssl-tu-dong"
markdown_url: "https://thuecloud.vn/docker-grafana-prometheus-huong-dan-cai-dat-voi-docker-compose-va-chung-chi-ssl-tu-dong.md"
locale: "vi"
kind: "article"
published_at: "2026-11-22T16:18:11.257Z"
updated_at: "2026-11-22T16:18:10.011Z"
site: "ThueCloud.Vn"
estimated_tokens: 1924
---
# Docker Grafana + Prometheus: Hướng dẫn cài đặt với Docker Compose và chứng chỉ SSL tự động

> Hướng dẫn triển khai bộ giám sát Grafana + Prometheus + Node Exporter bằng Docker Compose trên VPS NVMe, kèm reverse proxy và chứng chỉ SSL tự động.

- Canonical HTML: https://thuecloud.vn/docker-grafana-prometheus-huong-dan-cai-dat-voi-docker-compose-va-chung-chi-ssl-tu-dong
- Markdown URL: https://thuecloud.vn/docker-grafana-prometheus-huong-dan-cai-dat-voi-docker-compose-va-chung-chi-ssl-tu-dong.md
- Organization: ThueCloud.Vn
- Support Email: support@thuecloud.vn
- Hotline: 03333 499 48
- Published: 2026-11-22
- Updated: 2026-11-22

## Mục lục

- Cấu hình docker-compose.yml và prometheus.yml
- Khởi chạy và mở rộng quy trình vận hành
- Câu hỏi thường gặp (FAQ)
  - Stack Grafana + Prometheus + Node Exporter tốn bao nhiêu RAM?
  - Tại sao không mở trực tiếp cổng 9090 của Prometheus ra ngoài Internet?
  - Có thể dùng Grafana để gửi cảnh báo về Telegram khi VPS đầy ổ cứng không?

Vận hành ứng dụng trên [VPS Việt Nam](https://thuecloud.vn/vps-viet-nam) mà không có hệ thống giám sát lịch sử tài nguyên giống như lái xe trong sương mù: khi server sập lúc 3 giờ sáng, bạn không biết nguyên nhân do tràn RAM, nghẽn I/O hay CPU tăng đột biến. Triển khai bộ ba **Prometheus + Node Exporter + Grafana** bằng Docker Compose kèm HTTPS tự động là [giải pháp giám sát tiêu chuẩn](https://thuecloud.vn/giai-phap) chỉ mất 10 phút cài đặt.

> **Tóm tắt nhanh (TL;DR):**
> - **Node Exporter** thu thập thông số phần cứng Linux (CPU, RAM, Disk I/O, Network) ở cổng `9100`.
> - **Prometheus** kéo (scrape) metrics định kỳ 15 giây/lần và lưu vào cơ sở dữ liệu chuỗi thời gian (TSDB).
> - **Grafana** kết nối Prometheus để vẽ biểu đồ trực quan, đặt sau **Caddy** hoặc **Nginx + Certbot** để có chứng chỉ SSL tự động.
> - *Cập nhật: 11/2026*

## Cấu hình `docker-compose.yml` và `prometheus.yml`

Tạo thư mục `/opt/monitoring` và file `prometheus.yml` để khai báo target thu thập dữ liệu:

```yaml
# /opt/monitoring/prometheus.yml
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: "node_exporter"
    static_configs:
      - targets: ["node-exporter:9100"]
```

Tiếp theo, tạo file `docker-compose.yml` tích hợp sẵn Caddy làm Reverse Proxy tự động cấp chứng chỉ SSL Let's Encrypt cho tên miền `monitor.example.com`:

```yaml
services:
  node-exporter:
    image: prom/node-exporter:latest
    restart: unless-stopped
    volumes:
      - /proc:/host/proc:ro
      - /sys:/host/sys:ro
      - /:/rootfs:ro
    command:
      - "--path.procfs=/host/proc"
      - "--path.sysfs=/host/sys"
      - "--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)"

  prometheus:
    image: prom/prometheus:latest
    restart: unless-stopped
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prom_data:/prometheus
    command:
      - "--config.file=/etc/prometheus/prometheus.yml"
      - "--storage.tsdb.retention.time=15d"

  grafana:
    image: grafana/grafana:latest
    restart: unless-stopped
    volumes:
      - grafana_data:/var/lib/grafana
    environment:
      - GF_SERVER_DOMAIN=monitor.example.com
      - GF_SERVER_ROOT_URL=https://monitor.example.com

  caddy:
    image: caddy:latest
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    command: caddy reverse-proxy --from monitor.example.com --to grafana:3000
    volumes:
      - caddy_data:/data

volumes:
  prom_data:
  grafana_data:
  caddy_data:
```

| Thành phần | Vai trò | Lưu ý tài nguyên |
| :--- | :--- | :--- |
| `node-exporter` | Đọc metrics từ `/proc` và `/sys` | Cực nhẹ (~25MB RAM) |
| `prometheus` | Lưu trữ TSDB, mặc định giữ 15 ngày | Giới hạn `--storage.tsdb.retention.time` tránh đầy đĩa |
| `grafana` | Dashboard & Alerting (ID mẫu: `1860`) | Đổi mật khẩu `admin` ngay lần đầu đăng nhập |

## Khởi chạy và mở rộng quy trình vận hành

Chạy `docker compose up -d` và truy cập `https://monitor.example.com`. Vào *Connections > Data Sources > Add data source > Prometheus*, nhập URL `http://prometheus:9090`, sau đó import Dashboard ID `1860` (Node Exporter Full).

Khi vận hành song song các hệ thống khác, bạn có thể tham khảo thêm bài [tối ưu chi phí token, RAM cho Flowise AI](https://thuecloud.vn/flowise-ai-huong-dan-toi-uu-chi-phi-token-ram-va-cau-hinh-vps-phu-hop), [thiết lập sao lưu tự động cho Laravel PHP-FPM Queue](https://thuecloud.vn/thiet-lap-sao-luu-tu-dong-va-khoi-phuc-nhanh-cho-laravel-php-fpm-queue) và [kiến thức gỡ IP khỏi blacklist Spamhaus](https://thuecloud.vn/kien-thuc-nen-tang-go-ip-ten-mien-khoi-blacklist-spamhaus-trong-thiet-ke-he-thong-cloud).

---
> **Dựng cụm Monitoring mượt mà trên VPS NVMe ThueCloud.Vn:**
> Máy chủ KVM Enterprise NVMe tại **vn-hn** với **VAT 0%**, **SLA 99,9%** và **hoàn tiền 07 ngày** giúp Prometheus ghi dữ liệu TSDB nhanh và ổn định. Chọn ngay **VPS VN 1** (`45.000đ`–`60.000đ`), **VPS VN 2** (`78.000đ`–`90.000đ`) hoặc **VPS VN 3** (`139.000đ`–`170.000đ`) tại [bảng giá](https://thuecloud.vn/pricing).

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

### Stack Grafana + Prometheus + Node Exporter tốn bao nhiêu RAM?
Ở cấu hình giám sát 1–3 máy chủ, toàn bộ stack này tiêu tốn khoảng 350MB–550MB RAM, hoàn toàn chạy tốt trên gói VPS 1GB–2GB RAM.

### Tại sao không mở trực tiếp cổng 9090 của Prometheus ra ngoài Internet?
Prometheus không có cơ chế xác thực đăng nhập tích hợp sẵn. Nếu mở công khai cổng `9090`, bất kỳ ai cũng có thể xem cấu trúc hạ tầng và endpoint nội bộ của bạn.

### Có thể dùng Grafana để gửi cảnh báo về Telegram khi VPS đầy ổ cứng không?
Có. Grafana tích hợp sẵn Contact Point **Telegram** trong mục *Alerting*; bạn chỉ cần tạo Bot Token, lấy Chat ID và thiết lập rule cảnh báo khi dung lượng trống dưới 15%.

## References / Sources

- https://prometheus.io/docs/prometheus/latest/installation/
- https://grafana.com/docs/grafana/latest/setup-grafana/installation/docker/
- https://caddyserver.com/docs/quick-starts/reverse-proxy

---

## Navigation & Machine-Readable Endpoints

- [Site Summary (llms.txt)](https://thuecloud.vn/llms.txt)
- [Full Technical Reference (llms-full.txt)](https://thuecloud.vn/llms-full.txt)
- [Pricing Catalog (Markdown)](https://thuecloud.vn/pricing.md)
- [Blog & Technical Guides (Markdown)](https://thuecloud.vn/blog.md)
- [XML Sitemap](https://thuecloud.vn/sitemap.xml)
