【问题标题】:Automatically create UDP input for Graylog2 server running in Docker?为在 Docker 中运行的 Graylog2 服务器自动创建 UDP 输入?
【发布时间】:2014-10-28 18:33:09
【问题描述】:

我们正在开发环境中的 Docker 容器中运行 Graylog2 服务器。除了我们每次启动容器时都必须重新创建 UDP 输入这一事实之外,它的作用就像一个魅力。

有没有人想出一种方便的方法来自动创建 Graylog2 输入?

【问题讨论】:

  • 你找到答案了吗?我正在尝试做同样的事情。
  • FWIW,我正在寻求解决方案。输入数据存储在 Mongo 数据库中,所以如果您将 MongoDB 存储在持久化卷中,那么它应该持久化,对吗?好吧,不幸的是,每次容器重新启动时,Graylog2 都会生成一个新的节点 ID,并且输入与节点 ID 相关联。所以我只需要弄清楚如何使节点 ID 静态...
  • 嗨,我得到了一个 80% 的解决方案。我扩展了 qnib/graylog 图像,因此它将所需的配置直接插入到 MongoDB 中。这是一个非常讨厌的解决方案,但它有点工作。

标签: docker graylog2


【解决方案1】:

在新创建的 docker 容器中使用自动加载的内容包。

Dockerfile(从 Graylog 3.2 开始 - 感谢 T. van den Berg):

FROM graylog2/server:latest
COPY udp-input-graylog.json /usr/share/graylog/data/contentpacks
ENV GRAYLOG_CONTENT_PACKS_AUTO_INSTALL udp-input-graylog.json
ENV GRAYLOG_CONTENT_PACKS_LOADER_ENABLED true
ENV GRAYLOG_CONTENT_PACKS_DIR data/contentpacks

Dockerfile (pre 3.0, 见 this pull request)。 :

FROM graylog2/server:latest
COPY udp-input-graylog.json /usr/share/graylog/data/contentpacks
ENV GRAYLOG_CONTENT_PACKS_AUTO_LOAD udp-input-graylog.json
ENV GRAYLOG_CONTENT_PACKS_LOADER_ENABLED true
ENV GRAYLOG_CONTENT_PACKS_DIR data/contentpacks

udp-input-graylog.json:

{
  "name":"UDP GELF input on 12201",
  "description":"Adds a global UDP GELF input on port 12201",
  "category":"Inputs",
  "inputs":[
    {
      "title":"udp input",
      "configuration":{
        "override_source":null,
        "recv_buffer_size":262144,
        "bind_address":"0.0.0.0",
        "port":12201,
        "decompress_size_limit":8388608
      },
      "static_fields":{},
      "type":"org.graylog2.inputs.gelf.udp.GELFUDPInput",
      "global":true,
      "extractors":[]
    }
  ],
  "streams":[],
  "outputs":[],
  "dashboards":[],
  "grok_patterns":[]
}

【讨论】:

  • 无法在 Graylog 3 上运行 - github.com/Graylog2/graylog2-server/pull/5070
  • 谢谢,修改了您对答案的评论。-)如果我们找到解决方法,我们应该更新这个答案:-)
  • 这将从 Graylog 3.2 开始再次起作用。只有一个变化:ENV GRAYLOG_CONTENT_PACKS_AUTO_INSTALL udp-input-graylog.json 所以在 env 名称的末尾使用“INSTALL”而不是“LOAD”。
  • 如果我有多个内容包 json 文件怎么办,GRAYLOG_CONTENT_PACKS_AUTO_INSTALL 是否只接受一个文件作为输入?
【解决方案2】:

使用内容包创建多个输入的步骤:

  • 将它们写入json格式的文件(例如)

    {"id" : null,
     "name":" Inputs",
     "description":"Contentpack that adds global inputs",
     "category":"Inputs",
     "inputs":[
      {
      "title":"udp input",
      "configuration":{
        "override_source":null,
        "recv_buffer_size":262144,
        "bind_address":"0.0.0.0",
        "port":12201,
        "decompress_size_limit":8388608
      },
      "static_fields":{},
      "type":"org.graylog2.inputs.gelf.udp.GELFUDPInput",
      "global":true,
      "extractors":[]
      },
      {
      "title":"tcp input",
      "configuration":{
        "override_source":null,
        "recv_buffer_size":262144,
        "bind_address":"0.0.0.0",
        "port":12202,
        "decompress_size_limit":8388608
      },
      "static_fields":{},
      "type":"org.graylog2.inputs.gelf.tcp.GELFTCPInput",
      "global":true,
      "extractors":[]
      }]
    }  
    
  • 使用 ansible 将 contentpack 复制到 graylog 中的 contentpacks 目录

      - name: create graylog inputs for receiving logs
        shell: cp .templates/inputs.json /usr/share/graylog-server/contentpacks/inputs.json
    
  • 在graylog.conf 中或通过ansible 将内容包自动加载到True

      graylog_content_packs_loader_enabled: true
    
  • 设置内容包自动加载以加载 inputs.json(例如通过 ansible)

      graylog_content_packs_auto_load: inputs.json
    

希望这会有所帮助!

【讨论】:

    【解决方案3】:

    我使用 ansible 在容器中启动和准备 graylog2。我只是通过调用 graylog2 rest api 创建全局 udp 输入(在 graylog2 自动配置完成后):

    - name: create graylog global udp input for receiving logs
      uri:
        url: http://{{ ipv4_address }}:9000/api/system/inputs
        method: POST
        user: "{{ graylog_admin }}"
        password: "{{ graylog_pwd }}"
        body: '{"title":"xxx global input","type":"org.graylog2.inputs.gelf.udp.GELFUDPInput","configuration":{"bind_address":"0.0.0.0","port":12201,"recv_buffer_size":262144,"override_source":null,"decompress_size_limit":8388608},"global":true}'
        force_basic_auth: yes
        status_code: 201
        body_format: json
    

    [ansible] [docker] [graylog2]

    【讨论】:

      【解决方案4】:

      如果有帮助,请使用 graylog3 REST API 创建任意输入。 我想可能是在 graylog-api 可用后使用下面的示例 bash 脚本来调用。

      #!/bin/bash
      
      if [ `curl -s -u admin:admin -H 'Content-Type: application/json' -X GET 'http://graylog:9000/api/system/inputs' | grep -c 'Standard GELF UDP input'` == 0 ]
      then
        curl -u admin:admin -H 'Content-Type: application/json' -X POST 'http://graylog:9000/api/system/inputs' -d '{
          "title": "Standard GELF UDP input",
          "type": "org.graylog2.inputs.gelf.udp.GELFUDPInput",
          "global": true,
          "configuration":   {
                "recv_buffer_size": 1048576,
                "tcp_keepalive": false,
                "use_null_delimiter": true,
                "number_worker_threads": 2,
                "tls_client_auth_cert_file": "",
                "bind_address": "0.0.0.0",
                "tls_cert_file": "",
                "decompress_size_limit": 8388608,
                "port": 12201,
                "tls_key_file": "",
                "tls_enable": false,
                "tls_key_password": "",
                "max_message_size": 2097152,
                "tls_client_auth": "disabled",
                "override_source": null
              },
          "node": null
        }' -H 'X-Requested-By: cli'
      else
        echo "Standard GELF UDP input exists already"
      fi
      

      【讨论】:

        【解决方案5】:

        最后,这对我有用。我最终将相关配置直接插入到 MongoDB 中。

        https://github.com/kimble/graylog2-docker

        【讨论】:

        • 我已经发布了一个基于 Graylog 内容包的更优雅的解决方案。
        【解决方案6】:

        我们为此提供了一个 puppet 解决方案(graylog2 v2.2.2)。基本上在 server.conf 中启用内容包,并列出将成为您的 json 内容的相关文件(参见上面的 UDP 输入作为一个很好的例子)。只需将 puppet 中的文件资源放在配置的目录中的 graylog 服务器上(默认为 /usr/share/graylog-server/contentpacks)

        这将在第一次运行 graylog 时加载。

        这是获取大量配置的好方法。

        【讨论】:

          【解决方案7】:

          在搞砸了一段时间后,我想出了一个杂牌。这可能不是最好的方法,但是文档很少,而且似乎可以工作(但是,请参阅本文末尾的警告)。

          问题是每次重启 Graylog2 容器时,服务器都会生成一个新的唯一节点 ID。您通过 Web 界面定义的输入与特定的节点 ID 相关联。因此,每次节点 ID 更改时,您定义的输入都会变得无用。

          解决方案分为两部分:

          1. 确保 MongoDB 将其数据永久存储在某个位置 - 数据容器或从主机文件系统挂载的目录中。

          2. 强制容器每次使用相同的节点 ID。我通过扩展sjoerdmulder/graylog2 图像来做到这一点:

          这是 Dockerfile:

          FROM sjoerdmulder/graylog2
          
          # set a Graylog2 node ID
          #
          RUN echo "mynodeid" > /opt/graylog2-server/server-node-id
          RUN chmod 0444 /opt/graylog2-server/server-node-id
          

          这会将“mynodeid”写入适当的文件并通过更改权限对其进行写保护。然后服务器正常启动并加载适当的节点 ID。现在您可以进入 Web 界面,创建输入,并确信下次启动容器时,它仍然会存在。

          重要提示:

          我没有使用集群。我只是运行 Graylog2 的单个实例,接受来自单个 Web 应用程序的输入。我不知道当它是集群的一部分时会做什么。

          【讨论】:

            【解决方案8】:

            另一个选项是将您的输入创建为“全局” - 这样无论为当前实例生成的节点 ID 是什么,您都将取回所有已配置的全局输入。

            【讨论】:

              【解决方案9】:

              答案中提供的内容包 json 对我不起作用。我收到一个错误:

              错误:org.graylog2.periodical.ContentPackLoaderPeriodical - 未捕获 定期 java.lang.IllegalArgumentException 中的异常: 不支持的内容包版本:0

              然而,事实证明,创建内容包本身是一个简单直接的过程。

              1. 在 Graylog 的当前实例中创建所有需要的实体,例如输入
              2. 转到“内容包”菜单
              3. 点击创建内容包按钮
              4. 提供详细信息,选择要包含在复选框中的实体,然后点击下一步按钮
              5. 如果需要,提供参数,点击下一步按钮
              6. 点击创建和下载按钮。将下载内容包的 json。

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2014-05-18
                • 2014-09-27
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多