我当前使用的设置是具有多个容器的 Docker 组合堆栈。这些容器将其日志记录信息发送到运行 Fluentd 守护进程的日志记录容器(在 compose 堆栈内)。 Fluentd 的配置包括一in_forward
收集日志并将其写入单独文件的源,具体取决于容器。我的 Fluentd 配置文件类似于:
<source>
@type forward
port 24224
bind 0.0.0.0
</source>
<match container1>
@type copy
<store>
@type file
path /fluentd/log/container1.*.log
format single_value
message_key "log"
</store>
</match>
...
我的 docker-compose.yml 文件看起来像这样:
version: '3'
services:
container1:
build: ./container1
container_name: "container1"
depends_on:
- "logger"
logging:
driver: "fluentd"
options:
tag: container1
networks:
static-net:
ipv4_address: 172.28.0.4
...
logger:
build: ./logger
container_name: "logger"
ports:
- "24224:24224"
- "24224:24224/udp"
volumes:
- ./logger/logs:/fluentd/log
networks:
static-net:
ipv4_address: 172.28.0.5
networks:
static-net:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
一切都按预期进行,但我理想情况下希望将 Fluentd 设置为保留一定数量的日志文件。我可以通过配置来更改日志文件的大小chunk_limit_size
缓冲区部分中的参数。然而,即使我想要这个选项,我仍然不希望 Fluentd 写入无穷无尽的文件。这buffer_queue_limit
and overflow_action
缓冲区配置中似乎没有任何影响。该应用程序一旦部署就会持续运行,因此日志轮换是必要的。我有几个问题:
- Fluentd 是否支持日志轮转以将日志写入文件?如果是这样,我应该在 Fluentd 配置文件中设置哪些参数?
- 如果没有,我可以配置 Docker,以便我可以利用 Fluentd 的 json 日志记录驱动程序的日志轮换吗?
- 如果这是不可能的,有没有办法通过插件或在 Fluentd docker 容器本身(或 sidecar 容器)中将日志轮换添加到 Fluentd 中?
当您使用 docker 的 fluidd 日志记录驱动程序时,没有容器日志文件,只有 fluidd 日志,要轮换它们,您可以使用这个链接。 https://docs.fluentd.org/v1.0/articles/logging#log-rotation-setting如果您希望 docker 保留日志并轮换它们,那么您必须将堆栈文件更改为:
logging:
driver: "fluentd"
options:
tag: container1
to
logging:
driver: "json-file"
options:
max-size: "5m" #max size of log file
max-file: "2" #how many files should docker keep
在 fluidd 中,你必须使用 in_tail 插件而不是forward(fluidd 应该有权访问日志文件/var/lib/docker/containers/*/*-json.log
)
<source>
type tail
read_from_head true
pos_file fluentd-docker.pos
path /var/lib/docker/containers/*/*-json.log
tag docker.*
format json
</source>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)