Phần 4 — Loki, Mimir, Tempo: Triển khai 3 storage backends
Ý kiến
0
Chưa có ý kiến nào. Hãy là người đầu tiên chia sẻ!
Chưa có ý kiến nào. Hãy là người đầu tiên chia sẻ!
Tổng quan series: Grafana LGTM (Loki, Tempo, Mimir) + Alloy collector + SeaweedFS object storage + Pyroscope/Beyla. Kiến trúc, hardware, thứ tự deploy.
Vì sao SeaweedFS phù hợp cho Loki/Mimir/Tempo hơn MinIO/Ceph. Kiến trúc 4 thành phần, cài đặt single-node và multi-node, replication, best practices.
Grafana Alloy thay Promtail + Node Exporter + OTEL Collector. Deploy global trên Docker Swarm, file config.alloy đầy đủ cho metrics/logs/traces, mẹo X-Scope-OrgID.
Series Observability với Grafana Stack — 6 phần:
Phần 1 — Tổng quan: Observability với Grafana LGTM, Alloy và SeaweedFS
Phần 2 — SeaweedFS: Object storage gọn nhẹ cho Loki, Mimir, Tempo
Phần 3 — Grafana Alloy: Collector duy nhất cho metrics, logs, traces
Phần 4 — Loki, Mimir, Tempo: Triển khai 3 storage backends ← bạn đang đọc
Phần 5 — Grafana, Pyroscope, Beyla: UI, profiling và auto-instrumentation
Phần 6 — Production checklist: Backup, alerting, troubleshooting
Loki, Mimir, Tempo đều có thể chạy monolithic mode (1 binary làm tất cả) — đủ tốt cho team nhỏ–vừa. Cả 3 đều dùng SeaweedFS làm object storage thay vì cluster MinIO/Ceph.
Trước khi deploy, tạo sẵn buckets (đã hướng dẫn ở Phần 2):
for b in loki tempo mimir-blocks mimir-ruler mimir-alerts; do
aws s3 mb s3://$b --endpoint-url http://seaweed-s3:8333
done
loki/loki-config.yaml:
auth_enabled: true
server:
http_listen_port: 3100
grpc_listen_port: 9095
common:
path_prefix: /loki
replication_factor: 1
ring:
kvstore: { store: inmemory }
schema_config:
configs:
- from: 2026-01-01
store: tsdb
object_store: s3
schema: v13
index:
prefix: index_
period: 24h
storage_config:
aws:
s3: http://test:test@seaweed-s3:8333/loki
s3forcepathstyle: true
insecure: true
tsdb_shipper:
active_index_directory: /loki/index
cache_location: /loki/cache
limits_config:
retention_period: 720h # 30 ngày
max_query_series: 5000
compactor:
working_directory: /loki/compactor
retention_enabled: true
Compose service:
loki:
image: grafana/loki:3.3.0
command: -config.file=/etc/loki/loki-config.yaml
ports: ["3100:3100"]
volumes:
- ./loki/loki-config.yaml:/etc/loki/loki-config.yaml:ro
- loki_data:/loki
networks: [observability-net]
deploy:
resources: { limits: { memory: 2G } }
mimir/mimir-config.yaml (monolithic):
multitenancy_enabled: true
server:
http_listen_port: 8080
grpc_listen_port: 9095
common:
storage:
backend: s3
s3:
endpoint: seaweed-s3:8333
access_key_id: test
secret_access_key: test
insecure: true
bucket_name: mimir-blocks
blocks_storage:
s3: { bucket_name: mimir-blocks }
tsdb:
dir: /data/tsdb
retention_period: 24h
ruler_storage:
s3: { bucket_name: mimir-ruler }
alertmanager_storage:
s3: { bucket_name: mimir-alerts }
limits:
compactor_blocks_retention_period: 30d
ingestion_rate: 50000
max_global_series_per_user: 1500000
Compose service:
mimir:
image: grafana/mimir:2.14.0
command:
- -config.file=/etc/mimir/mimir-config.yaml
- -target=all # monolithic mode
ports: ["8080:8080"]
volumes:
- ./mimir/mimir-config.yaml:/etc/mimir/mimir-config.yaml:ro
- mimir_data:/data
networks: [observability-net]
deploy:
resources: { limits: { memory: 4G } }
tempo/tempo-config.yaml:
server:
http_listen_port: 3200
grpc_listen_port: 9095
distributor:
receivers:
otlp:
protocols:
grpc: { endpoint: "0.0.0.0:4317" }
http: { endpoint: "0.0.0.0:4318" }
ingester:
trace_idle_period: 10s
max_block_duration: 5m
compactor:
compaction:
block_retention: 168h # 7 ngày
storage:
trace:
backend: s3
s3:
bucket: tempo
endpoint: seaweed-s3:8333
access_key: test
secret_key: test
insecure: true
wal: { path: /tmp/tempo/wal }
metrics_generator:
storage:
path: /tmp/tempo/generator
remote_write:
- url: http://mimir:8080/api/v1/push
headers: { X-Scope-OrgID: primary_cluster }
Compose service:
tempo:
image: grafana/tempo:2.6.0
command: -config.file=/etc/tempo/tempo-config.yaml
ports:
- "3200:3200"
- "4317"
volumes:
- ./tempo/tempo-config.yaml:/etc/tempo/tempo-config.yaml:ro
- tempo_data:/tmp/tempo
networks: [observability-net]
deploy:
resources: { limits: { memory: 2G } }
docker stack deploy -c storage-compose.yml obs
Health check nhanh:
# Loki
curl http://loki:3100/ready
# Mimir
curl http://mimir:8080/ready
# Tempo
curl http://tempo:3200/ready
Cả 3 trả ready là OK. Sau ~1 phút, bạn sẽ thấy buckets trên SeaweedFS bắt đầu có data:
aws s3 ls s3://mimir-blocks/ --endpoint-url http://seaweed-s3:8333 --recursive | head
3 backends, 3 retention khác nhau. Hãy thống nhất theo SLA:
| Loại | Retention khuyến nghị | Cấu hình |
|---|---|---|
| Logs (Loki) | 30 ngày | limits_config.retention_period |
| Metrics (Mimir) | 30–90 ngày | compactor_blocks_retention_period |
| Traces (Tempo) | 7 ngày | compactor.compaction.block_retention |
Traces ngắn hạn vì volume rất lớn — chỉ giữ đủ để debug. Metrics và logs lâu hơn vì cần phân tích trend.
Multi-tenancy: cả 3 đều bật. Header X-Scope-OrgID chia tenant. Một stack có thể phục vụ nhiều cluster/team.
Loki cardinality: tránh dùng request_id, user_id làm label — đẩy vào structured log. Label chỉ dùng cho trường có cardinality thấp (service, env, cluster).
Mimir ingestion_rate: 50k samples/s là default an toàn. Tăng theo nhu cầu.
Tempo metrics_generator: bật để Tempo tự sinh RED metrics (Rate/Error/Duration) từ traces — hiện trên Grafana ngay.
← Phần 3: Grafana Alloy: Collector duy nhất cho metrics, logs, traces
Phần 5: Grafana, Pyroscope, Beyla: UI, profiling và auto-instrumentation →