如何访问使用Docker容器内的流利日志记录的日志日志 [英] How to access logs logged in journald using fluent-bit that's inside a docker container

查看:129
本文介绍了如何访问使用Docker容器内的流利日志记录的日志日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用docker-compose.yml启动我的服务.所有服务如下所示:

I'm using docker-compose.yml that launches my services. All services look something like this:

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收集数据时,我的流利位容器似乎无法获取任何数据:

When I run journalctl -e -f -u docker I see all the logs being logged just fine. The problem I'm having is that my fluent-bit container seems to be unable to get any data when collecting from systemd:

fluent-bit.conf:
[SERVICE]
    Flush        5
    Daemon       Off
    Log_Level    debug

[INPUT]
    Name            systemd
    Tag             *


[OUTPUT]
    Name   stdout
    Match  *

我认为这可能是因为它在容器中并且无法到达日志位置,但是绑定目录/run/log:/run/log 无效.

I figured that it might be because it's in container and can't reach the logs location, but binding directory /run/log:/run/log had no effect.

所以我的问题是:流利的位在容器中时能否到达systemd并读取日志?如果可以,我该如何实现?

So my question would be: Can fluent-bit reach systemd and read journal when it is inside container? If yes - how can I achieve that?

推荐答案

经过更多研究,我偶然发现了这个线程: https://github.com/fluent/fluent-bit/issues/497

After even more research I stumbled acros this thread: https://github.com/fluent/fluent-bit/issues/497

长话短说:

  1. 您需要以root用户身份运行fluent-bit容器,因为访问日志需要root权限
  2. 将docker中的计算机ID设置为与您的根计算机中的计算机相同
  3. 绑定/run/log/journal:/run/log/journal

如此:

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路径:

Then, in fluent-bit.conf you need edit the INPUT path:

[INPUT]
    Name            systemd
    Tag             *
    Path            /run/log/journal
    Systemd_Filter    _SYSTEMD_UNIT=docker.service
    Systemd_Filter    _SYSTEMD_UNIT=kubelet.service

这篇关于如何访问使用Docker容器内的流利日志记录的日志日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆