【问题标题】:Fluentd in docker cannot tail from my log filedocker 中的 Fluentd 无法从我的日志文件中拖尾
【发布时间】:2020-10-26 10:45:01
【问题描述】:

Docker 中的Fluentd 无法从我的日志文件中拖尾

我在/var/log/logf/a.log 中的输入:

test 1st log
test 2nd log
test 3rd log

还有我在/opt/app/conf/fluent.conf中的配置:

<source>
   @type tail
   path /var/log/logf/a.log
   tag test
   read_from_head true
   <parse>
      @type none
      message_key test
   </parse>
</source>

<match test>
   @type stdout
</match>

还有我的Dockerfile id /opt/app/Dockerfile

FROM fluent/fluentd:v1.11-debian-1
USER root

COPY ./conf/fluent.conf /fluentd/etc
RUN ["gem", "install", "fluent-plugin-elasticsearch", "--no-document", "--version", "3.5.2"]
USER fluent

我运行我的Dockerfile

$ sudo docker build -t log-app .
$ sudo docker run -d --name logging log-app:latest
$ sudo docker logs -f logging

结果卡住了,不知道为什么

2020-10-26 10:24:58 +0000 [info]: parsing config file is succeeded path="/fluentd/etc/fluent.conf"
2020-10-26 10:24:58 +0000 [info]: gem 'fluent-plugin-elasticsearch' version '3.5.2'
2020-10-26 10:24:58 +0000 [info]: gem 'fluentd' version '1.11.4'
2020-10-26 10:24:58 +0000 [warn]: 'pos_file PATH' parameter is not set to a 'tail' source.
2020-10-26 10:24:58 +0000 [warn]: this parameter is highly recommended to save the position to resume tailing.
2020-10-26 10:24:58 +0000 [info]: using configuration file: <ROOT>
 <source>
   @type tail
   path "/var/log/logf/a.log"
   tag "test"
   read_from_head true
   <parse>
      @type "none"
      message_key "test"
      unmatched_lines
   </parse>
 </source>
 <match test>
    @type stdout
 </match>
</ROOT>
2020-10-26 10:24:58 +0000 [info]: starting fluentd-1.11.4 pid=6 ruby="2.6.6"
2020-10-26 10:24:58 +0000 [info]: spawn command to main:  cmdline=["/usr/local/bin/ruby", "-Eascii- 8bit:ascii-8bit", "/usr/local/bundle/bin/fluentd", "-c", "/fluentd/etc/fluent.conf", "-p", "/fluentd/plugins", "--under-supervisor"]
2020-10-26 10:24:59 +0000 [info]: adding match pattern="test" type="stdout"
2020-10-26 10:24:59 +0000 [info]: adding source type="tail"
2020-10-26 10:24:59 +0000 [warn]: #0 'pos_file PATH' parameter is not set to a 'tail' source.
2020-10-26 10:24:59 +0000 [warn]: #0 this parameter is highly recommended to save the position to resume tailing.
2020-10-26 10:24:59 +0000 [info]: #0 starting fluentd worker pid=15 ppid=6 worker=0
2020-10-26 10:24:59 +0000 [info]: #0 fluentd worker is now running worker=0

我认为这是一个权限问题,但我不确定因为这个Fluentd 不会抛出错误,你们能解决这个问题吗?


[已解决]完全被卡兰沙阿先生的解释解决了

我已通过带有安装卷的 docker-compose 解决,如下:

在文件/opt/app/docker-compose.yaml

version: '2'

services:
  fluentd:
    build: .
    container_name: fl-logging
    volumes:
      - "./conf/:/fluentd/etc:ro"
      - "/var/log/logf:/var/log/logf"

然后运行 ​​docker compose

 $ sudo docker-compose up -d --build

【问题讨论】:

  • 如何启动 fluentd 容器?如何挂载要解析的日志文件夹?
  • sudo docker build -t log-app && sudo docker run -d --name logging log-app:latest @AndreasJägle 我不知道如何使用装载先生,你能给我一个例子吗?但是谢谢你回答我的问题先生

标签: docker logging kubernetes elastic-stack fluentd


【解决方案1】:

问题是您没有将本地日志文件挂载到 Fluentd 容器中以使其可访问。

使用如下命令。

sudo docker run -d --name logging -v PATHTOYOURLOGFILE:/var/log/logf/ log-app:latest

阅读有关卷的更多信息here

您也可以使用如下所示的 docker-compose 文件

version: '2.2'
services:
 fluentd:
    build: ./opt/app/
    container_name: fl01
    volumes:
      - "/opt/app/conf/:/fluentd/etc/:ro"
      - "PATHTOYOURLOGFILE:/var/log/logf/"
    networks:
      - elastic
    ports:
      - "9880:9880"
networks:
  elastic:
    driver: bridge

【讨论】:

  • 真棒和完整的描述,谢谢先生,现在我真的了解 docker 中的挂载或卷功能。
  • @Ganang wahyu:很高兴我能提供帮助。请接受答案或投票?
猜你喜欢
  • 2021-10-29
  • 1970-01-01
  • 1970-01-01
  • 2021-01-05
  • 1970-01-01
  • 2021-01-04
  • 1970-01-01
  • 2019-01-20
  • 2022-10-15
相关资源
最近更新 更多