Files
docker_practice/11_ops/logs/README.md
Baohua Yang b44c9acd6c Restruct
2026-02-09 12:56:12 -08:00

27 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 日志管理
在容器化环境中日志管理比传统环境更为复杂容器是短暂的意味着容器内的日志文件可能会随着容器的销毁而丢失因此我们需要一种集中式的日志管理方案来收集存储和分析容器日志
## Docker 日志驱动
Docker 提供了多种日志驱动Log Driver机制允许我们将容器日志转发到不同的后端
常见的日志驱动包括
* `json-file`: 默认驱动将日志以 JSON 格式写入本地文件
* `syslog`: 将日志转发到 syslog 服务器
* `journald`: 将日志写入 systemd journal
* `fluentd`: 将日志转发到 fluentd 收集器
* `gelf`: 支持 GELF 协议的日志后端 Graylog
* `awslogs`: 发送到 Amazon CloudWatch Logs
## 日志管理方案
对于大规模的容器集群我们通常会采用 EFK (Elasticsearch + Fluentd + Kibana) ELK (Elasticsearch + Logstash + Kibana) 方案
* **Elasticsearch**: 负责日志的存储和全文检索
* **Fluentd/Logstash**: 负责日志的采集过滤和转发
* **Kibana**: 负责日志的可视化展示
本章将介绍如何使用 EFK 方案来处理 Docker 容器日志