自动为在Docker中运行的Graylog2服务器创buildUDPinput?
我们正在开发环境中的Docker容器中运行一个Graylog2服务器。 除了我们每次启动容器时都必须重新创buildUDPinput这一事实之外,它的function就像是一种魅力。
有没有人想出一个方便的方法来自动创buildGraylog2input?
我们在新创build的docker容器中使用自动加载的内容包 。
Dockerfile:
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-inputgraylog.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":[] }
最后,这对我来说是个诡计。 我最终直接将相关configuration插入到MongoDB中。
我使用容器来启动和准备graylog2。 我只是通过调用graylog2 rest api创build全局udpinput(在graylog2自动configuration完成后):
- 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]
我们有一个木偶解决scheme(graylog2 v2.2.2)。 基本上启用server.conf中的内容包,并列出将作为json内容的相关文件(请参阅上面的UDPinput作为一个很好的例子)。 简单的说就是放置在configuration好的目录中的木偶上的文件资源(默认是/ usr / share / graylog-server / contentpacks)
这将在第一次运行graylog时加载。
这是获取大量configuration的好方法。
经过一段时间的搞乱之后,我想出了一个烂泥。 这可能不是最好的办法,但文件是稀疏的,它似乎工作(但是,看到这篇文章的结尾警告)。
问题是,每当您重新启动您的Graylog2容器时,服务器都会生成一个新的唯一节点ID。 您通过Web界面定义的input绑定到特定的节点ID。 因此,每当节点ID发生变化时,您定义的input变得无用。
解决scheme有两个部分:
-
确保MongoDB正在将其数据存储在持久的地方 – 数据容器或从主机文件系统挂载的目录中。
-
强制容器每次都使用相同的节点ID。 我通过扩展sjoerdmulder / graylog2映像来实现这个function:
这里是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界面,创build您的input,并确信下次启动容器时,它仍然在那里。
重要的提示:
我没有使用群集。 我只是运行一个Graylog2实例接受来自单个Web应用程序的input。 我不知道集群的一部分会做什么。
另一种select是将input创build为“全局” – 这样,不pipe为当前实例生成的节点标识如何,您都将取回所有已configuration的全局input。
使用contentpack创build多个input的步骤:
-
把它们写成一个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":[] }] }
-
将内容包复制到graylog中的contentpacks目录
- name: create graylog inputs for receiving logs shell: cp .templates/inputs.json /usr/share/graylog server/contentpacks/inputs.json
-
在
graylog.conf
或者通过一个graylog.conf
autoload设置为True
graylog_content_packs_loader_enabled: true
-
设置
inputs.json
autoload加载inputs.json
(例如,通过ansible)graylog_content_packs_auto_load: inputs.json
希望这可以帮助!