我正在使用docker-compose.yml启动我的服务。所有服务如下所示:
A-service:
image: A-service
restart: always
network_mode: host
logging:
driver: journald
options:
tag: "{{.ImageName}}/{{.Name}}/{{.ID}}"
fluent-bit:
image: 'bitnami/fluent-bit:latest'
restart: always
network_mode: host
command: /fluent-bit/bin/fluent-bit -c /fluent-bit/etc/fluent-bit.conf
volumes:
- ./service/config/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
- type: bind
source: /run/log
target: /run/log
当我运行journalctl -e -f -u docker
时,我看到所有日志记录都很好。
我遇到的问题是,从systemd收集数据时,我的流利容器似乎无法获取任何数据:
fluent-bit.conf:
[SERVICE]
Flush 5
Daemon Off
Log_Level debug
[INPUT]
Name systemd
Tag *
[OUTPUT]
Name stdout
Match *
我认为这可能是因为它在容器中并且无法到达日志位置,但是绑定目录/run/log:/run/log
无效。
所以我的问题是: 流利的位在容器中时能否到达systemd并读取日志?如果可以,我该如何实现?
答案 0 :(得分:1)
经过更多研究,我偶然发现了这个线程的错位: https://github.com/fluent/fluent-bit/issues/497
长话短说:
如此:
fluent-bit:
image: 'bitnami/fluent-bit:latest'
restart: always
user: root
network_mode: host
command: /fluent-bit/bin/fluent-bit -c /fluent-bit/etc/fluent-bit.conf
volumes:
- ./service/config/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
- /etc/machine-id:/etc/machine-id:ro
- /run/log/journal:/run/log/journal
然后,在fluent-bit.conf中,您需要编辑INPUT路径:
[INPUT]
Name systemd
Tag *
Path /run/log/journal
Systemd_Filter _SYSTEMD_UNIT=docker.service
Systemd_Filter _SYSTEMD_UNIT=kubelet.service