[英]Does Fluentd support log rotation for file output?
我正在使用的当前设置是带有多个容器的Docker compose堆栈。 这些容器将其日志记录信息发送到运行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
和overflow_action
似乎没有任何影响。 部署后,该应用程序将连续运行,因此有必要进行日志轮换。 我有几个问题:
当您为docker使用fluentd日志驱动程序时,则没有容器日志文件,只有fluentd日志,要旋转它们,您可以使用此链接。 如果您想让docker保留日志并对其进行轮换,则必须从以下位置更改堆栈文件:
logging:
driver: "fluentd"
options:
tag: container1
至
logging:
driver: "json-file"
options:
max-size: "5m" #max size of log file
max-file: "2" #how many files should docker keep
在fluentd中,您必须使用in_tail插件而不是forward(fluentd应该可以访问/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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.