![](/img/trans.png)
[英]How to send logs to multiple outputs with same match tags in Fluentd?
[英]how to add multiple outputs in fluentd-kubernetes-daemonset in kubernetes
我正在使用fluentd daemonset docker 映像,并通过使用以下代码片段将日志发送到 ES 与 fluentd 完美运行:
containers:
- name: fluentd
image: fluent/fluentd-kubernetes-daemonset:v1.4.2-debian-elasticsearch-1.1
env:
- name: FLUENT_ELASTICSEARCH_HOST
value: "my-aws-es-endpoint"
- name: FLUENT_ELASTICSEARCH_PORT
value: "443"
- name: FLUENT_ELASTICSEARCH_SCHEME
value: "https"
- name: FLUENT_ELASTICSEARCH_USER
value: null
- name: FLUENT_ELASTICSEARCH_PASSWORD
value: null
但是发生的问题是针对 DR/HA,我们也即将将日志保存到 S3 中。 我的问题是无论如何我们可以在 fluentd-kubernetes-daemonset 中添加多个输出,例如 S3、Kinesis 等 kubernetes?
您如何将 Fluentd 部署到集群是主观的。 你使用像 Helm 或 Skaffold 这样的模板引擎吗?
如果是这样,它们内部应该有一个 configmap / 配置选项来自定义部署并提供您自己的输入。 例如,Helm fluentd 可以通过在此处添加输出来定义:
https://github.com/helm/charts/blob/master/stable/fluentd/values.yaml#L97
这应该允许您制作多个流,以便将流畅的数据输出到多个位置。
我注意到在您的特定 Docker 映像中,您提供了一些 Ruby 模板项。 该配置特别允许您将卷挂载到 fluentd 文件夹中的conf.d/
: https : //github.com/fluent/fluentd-kubernetes-daemonset/blob/master/templates/conf/fluent.conf.erb# L9
也许/etc/fluentd
但我建议在本地运行映像并/etc/fluentd
检查。
只要您的配置文件以.conf
结尾,您就应该能够添加任何您想要的内容。
如第一个答案中所述-您需要覆盖整个配置。 您正在寻找输出类型 "copy" :
<match **>
@type copy
<store>
@type elasticsearch
...
</store>
<store>
@type s3
...
</store>
<store>
@type kinesis_streams
...
</store>
</match>
提示:因为每个<store>
都会很长,所以它在存储数量较多的情况下变得不太可读。 我通常将每个商店都包装在一个标签中以增加可读性:
<match **>
@type copy
<store>
@type relabel
@label @es
</store>
<store>
@type relabel
@label @s3
</store>
<store>
@type relabel
@label @stream
</store>
</match>
<label @es>
<match **>
@type elasticsearch
...
</match>
</label>
<label @s3>
<match **>
@type s3
...
</match>
</label>
<label @stream>
<match **>
@type kinesis_streams
...
</match>
</label>
现在您可以将标签移动到单独的配置文件。 除了可读性之外,这还有更多好处:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.