[英]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.