【问题标题】:How to collect logs via fluentd in swarm mode如何通过 fluentd 在 swarm 模式下收集日志
【发布时间】:2018-05-10 18:25:55
【问题描述】:

我尝试在 swarm 模式下运行服务 (mongo),并通过 fluentd 将日志收集到 elasticsearch。它的工作(!)与:

docker-compose up

但是当我通过堆栈部署时,服务启动了,但没有收集日志,我不知道如何查看是什么原因。

docker stack deploy -c docker-compose.yml env_staging

docker-compose.yml:

version: "3"
services:
    mongo:
        image: mongo:3.6.3
        depends_on:
         - fluentd
        command: mongod
        networks:
         - webnet
        logging:
          driver: "fluentd"
          options:
            fluentd-address: localhost:24224
            tag: mongo
    fluentd:
        image: zella/fluentd-es
        depends_on:
         - elasticsearch
        ports:
         - 24224:24224
         - 24224:24224/udp
        networks:
         - webnet
    elasticsearch:
        image: elasticsearch
        ports:
         - 9200:9200
        networks:
         - webnet
    kibana:
        image: kibana
        depends_on:
         - elasticsearch
        ports:
         - 5601:5601
        networks:
         - webnet
networks:
     webnet:

更新

我删除了fluentd-address: localhost:24224,问题就解决了。但我不明白什么是“本地主机”?为什么我们不能设置“fluentd”主机。如果有人解释什么是fluentd-address,我会接受答案。

【问题讨论】:

    标签: docker docker-compose docker-swarm fluentd


    【解决方案1】:

    fluentd-address 是 fluentd 守护进程所在的地址(默认是 localhost,这种情况下不需要指定)。

    在您的情况下(使用堆栈),您的 fluentd 守护程序将在节点上运行,您应该使用服务名称访问该服务(在您的情况下为 fluentd,您尝试过吗?)。

    记得在您的选项中添加fluentd-async-connect: "true"

    参考在: https://docs.docker.com/config/containers/logging/fluentd/#usage

    【讨论】:

    • 我用fluentd-address: localhost:24224fluentd-address: fluentd:24224试了几次。使用“localhost”服务无法启动。当我使用“fluentd”主机时,es 中没有日志。只有没有这条线,它才能工作。所以我不确定,“localhost”是默认值
    • 在您的网络中,您可以 ping fluentd 吗?您收到回复了吗?
    • 我在这里找到了答案 stackoverflow.com/questions/45346005/… 和默认主机 127.0.0.1 可以工作
    【解决方案2】:

    您不需要指定 fluentd-address。当您将日志驱动程序设置为 fluentd 时,Swarm 会自动发现最近的 fluentd 实例并将所需容器的所有标准输出发送到那里。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-18
      • 2023-01-01
      • 2017-07-10
      • 1970-01-01
      • 2018-06-19
      • 1970-01-01
      • 2020-02-15
      相关资源
      最近更新 更多