Fluent-bit.conf
[INPUT]
Name http
Listen 0.0.0.0
port 24224
[OUTPUT]
Name stdout
Match **
Fluentbit Dockerfile
FROM fluent/fluent-bit:2.1.8
ADD fluent-bit.conf /fluent-bit/etc/
docker-compose.yaml
services:
fluentbit:
image: 'shubham01/fluentbit:latest'
container_name: fluentbit
hostname: fluentbit
ports:
- "24224:24224"
- "24224:24224/udp"
volumes:
- ./fluentbit/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
- ./log/:/etc/data
app:
container_name: app
hostname: app
image: app
stdin_open: true
tty: true
build:
context: .
dockerfile: Dockerfile
args:
END: 'TEST'
volumes:
- "/tmp:/tmp"
ports:
- '8080:8080'
restart: 'on-failure'
depends_on:
- fluentbit
logging:
driver: fluentd
options:
fluentd-address: "fluentbit:24224"
fluentd-async-connect: "true"
tag: 'containerssh.{{.ID}}'
流畅的位容器日志
Fluent Bit v2.1.8
* Copyright (C) 2015-2022 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io
[2024/01/14 09:02:55] [ info] [fluent bit] version=2.1.8, commit=1d83649441, pid=1
[2024/01/14 09:02:55] [ info] [storage] ver=1.4.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2024/01/14 09:02:55] [ info] [cmetrics] version=0.6.3
[2024/01/14 09:02:55] [ info] [ctraces ] version=0.3.1
[2024/01/14 09:02:55] [ info] [input:http:http.0] initializing
[2024/01/14 09:02:55] [ info] [input:http:http.0] storage_strategy='memory' (memory only)
[2024/01/14 09:02:55] [ info] [output:stdout:stdout.0] worker #0 started
我正在尝试将日志从 docker 容器获取到一个中心位置,以便可以将它们转发到任何地方。
日志显示在服务应用程序的容器日志中,但未显示在 Fluentbit 的标准输出上。
Dockerd 正在 Ubuntu 上执行。
配置中有两个问题
fluentbit
的主机无效(应该是“localhost”)INPUT
(name
应该是forward
)另一件事要提到的是使用
fluentd-async-connect: "true"
使调试变得困难,因为当主机不可用时,你不会收到任何错误
问题#1
要理解为什么在这种情况下
localhost
是正确的,你必须从Docker Daemon而不是容器app
的角度思考,app
仅生成日志,但发送它是由Docker Daemon完成的。查看 docker 文档我们可以发现:- "24224:24224"
,但您必须使用 localhost
而不是容器名称。
问题#2
您使用的 INPUT 名称为
http
,对于 Docker Daemon 发送的数据来说不是有效的读取器,深入研究 Docker 文档,您可以找到显示 @type forward
的示例 测试容器记录器(就像您配置中的
name
)这一切的发生是因为 docker 已经实现了 fluentd
日志记录协议。
当您有 INPUT
name http
Fluentd 期待原始 HTTP 请求时,您可以使用 curl
发送该请求(基于 Fluent Bit 的示例):
curl -d '{"key1":"value1","key2":"value2"}' -XPOST -H "content-type: application/json" http://localhost:24224/app.log
奖金
当您必须对 docker 日志记录进行故障排除时,最好禁用
fluentd-async-connect: "true"
,只需删除或设置为 false
,因为它将帮助您调试 Docker Daemon 和 flient bit 之间的连接
更改了我用来验证它的示例(我将你的
app
更改为nginx
)
services:
fluentbit:
image: 'shubham01/fluentbit:latest'
container_name: fluentbit
hostname: fluentbit
ports:
- "24224:24224"
volumes:
- ./fluentbit/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
- ./log/:/etc/data
app:
container_name: nginx
hostname: nginx
image: nginx
stdin_open: true
tty: true
volumes:
- "/tmp:/tmp"
ports:
- '8080:80'
restart: 'on-failure'
depends_on:
- fluentbit
logging:
driver: fluentd
options:
fluentd-address: "localhost:24224"
tag: 'containerssh.{{.ID}}'