You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker Compose配置GELF日志驱动遇阻:路径配置矛盾求助

问题根源与解决方案

核心问题

Docker的GELF日志驱动不支持HTTP协议的路径参数,它原生是为Graylog的GELF TCP/UDP输入设计的,而你当前创建的是GELF HTTP输入,这是两者不兼容的根本原因。


方案1:改用Graylog的GELF TCP/UDP输入(推荐,无需额外容器)

  1. 在Graylog控制台删除现有GELF HTTP输入,创建GELF TCP或GELF UDP输入:
    • 选择对应输入类型,设置监听端口(比如默认12201,确保无端口冲突)
    • 绑定地址设为0.0.0.0,允许容器访问
  2. 修改Docker Compose日志配置:
    • TCP版本:
      driver: gelf
      options:
         gelf-address: "tcp://graylog:12201"
      
    • UDP版本:
      driver: gelf
      options:
         gelf-address: "udp://graylog:12201"
      
  3. 重启目标容器,日志将自动发送到Graylog的GELF TCP/UDP输入。

方案2:保留GELF HTTP输入,通过Sidecar容器转发日志

若必须使用GELF HTTP输入,需借助中间容器(如fluentd)转发日志:

  1. 创建fluent.conf配置文件:
    <source>
      @type gelf
      port 12200
      bind 0.0.0.0
    </source>
    
    <match **>
      @type http
      endpoint http://graylog:12201/gelf
      headers {"Content-Type": "application/json"}
      <buffer>
        @type memory
        flush_interval 5s
      </buffer>
    </match>
    
  2. 修改Docker Compose配置:
    • 添加fluentd服务:
      services:
        fluentd:
          image: fluent/fluentd:v1.16-debian-1
          volumes:
            - ./fluent.conf:/fluentd/etc/fluent.conf
          ports:
            - "12200:12200/udp"
            - "12200:12200/tcp"
      
    • 目标容器日志配置指向fluentd:
      driver: gelf
      options:
         gelf-address: "tcp://fluentd:12200"
      
  3. 重启所有容器,日志将先转发到fluentd,再发送到Graylog的GELF HTTP输入。

内容的提问来源于stack exchange,提问作者Isaac Ray

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 23:20:39