欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 手游 > 【实践】Filebeats的尝鲜

【实践】Filebeats的尝鲜

2025/2/22 16:41:36 来源:https://blog.csdn.net/NiDeHaoPengYou/article/details/139681249  浏览:    关键词:【实践】Filebeats的尝鲜

背景

落盘的日志文件, 查询起来比较麻烦,所以想将其存入ES中,然后通过使用Kibana来查询

方案:Filebeat

第三方存储: ES

链路: filebeat ----> [logstash]----> ES

前期验证

Filebeat输出ES连接问题?

ES,目前使用的es版本为7.10.x,

第一步: 使用filebeat最新版本,连接ES容易报下面的错误:

Connection marked as failed because the onConnect callback failed: could not connect to a compatible version of Elasticsearch: 400 Bad Request: {"error":{"root_cause":[{"type":"invalid_index_name_exception","reason":"Invalid index name [_license], must not start with '_'.","index uuid":"_na_","index":"_license"}],"type":"invalid_index_name_exception","reason":"Invalid index name [_license], must not start with '_'.","index uuid":"_na_","index":"_license"},"status":400}

问题原因: ES版本和filebeat版本不兼容的问题, 查了一下, 说是filebeat自7.13.X之后, 会存在一些与ES版兼容性的问题

第二步: 准备降低filebeat版本:使用1.12.1, 连接ES报其他错误:

Filebeat requires the default distribution of Elasticsearch. Please update to the default distribution of Elasticsearch for full access to all free features, or switch to the OSS distribution of Filebeat.

第三步: 根据报错信息, 查了一下,应该是ES的部署和Filebeat的方式不兼容,

提示显示: 要么修改ES集群, 要么切换OSS版本的Filebeat

第四步: 选择切换OSS版的Filebeat,版本: 7.12.1

最终: 顺利能连上ES

mapping的字段膨胀爆炸?

报错如下:

Private:(*input_logfile.updateOp)(0xc0088cb840), TimeSeries:false}, Flags:0x1, Cache:publisher.EventCache{m:common.MapStr(nil)}} (status=400): {"type":"illegal_argument_exception","reason":"Limit of total fields [1000] has been exceeded"

ES默认配置

参考:Mapping limit settings | Elasticsearch Guide [8.14] | Elastic

index.mapping.total_fields.limit

The maximum number of fields in an index. Field and object mappings, as well as field aliases count towards this limit. Mapped runtime fields count towards this limit as well. The default value is 1000.

可以通过修改: index.mapping.total_fields.limit的值来解决这个问题,但是字段太多无法有效控制

那么要如何配置呢?

可以考虑的思路:

  1. 尝试禁用不必要的字段mapping

  2.  只提取需要的字段保留下来

这两种思路各有优缺点,具体可自行跟进业务场景判断使用哪个方案

这里介绍一下第一种思路:尝试禁用不必要的字段mapping

使用ES的索引模版,在自动创建索引时,应用该模版来设置索引的mapping等参数

动态索引模版创建如下:

curl -XPUT "http://ip:8200/_index_template/filebeat-flatten-fields" -H 'Content-Type: application/json' -d'{"index_patterns": ["filebeat_logs*"],"template": {"mappings": {"dynamic_templates": [{"filebeat-flatten-fields-request": {"path_match": "message.request.*","match_mapping_type":"object","mapping": {"enabled": false}}},{"filebeat-flatten-fields-response": {"path_match": "message.response.*","match_mapping_type":"object","mapping": {"enabled": false}}},{"request-not-enabled-1": {"pat

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词