Rh1*_*303 5 ruby logging fluentd docker
我当前使用的设置是具有多个容器的 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>
...
Run Code Online (Sandbox Code Playgroud)
我的 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
Run Code Online (Sandbox Code Playgroud)
一切都按预期进行,但我理想情况下希望将 Fluentd 设置为保留一定数量的日志文件。chunk_limit_size
我可以通过配置缓冲区部分中的参数来更改日志文件的大小。然而,即使我想要这个选项,我仍然不希望 Fluentd 写入无穷无尽的文件。buffer_queue_limit
缓冲区配置中的 和似乎overflow_action
没有任何影响。该应用程序一旦部署就会持续运行,因此日志轮换是必要的。我有几个问题:
当您使用适用于 docker 的 Fluentd 日志记录驱动程序时,没有容器日志文件,只有 Fluentd 日志,要轮换它们,您可以使用此链接。 如果您希望 docker 保留日志并轮换它们,那么您必须将堆栈文件更改为:
logging:
driver: "fluentd"
options:
tag: container1
Run Code Online (Sandbox Code Playgroud)
到
logging:
driver: "json-file"
options:
max-size: "5m" #max size of log file
max-file: "2" #how many files should docker keep
Run Code Online (Sandbox Code Playgroud)
在 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>
Run Code Online (Sandbox Code Playgroud)