【实践】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

相关推荐

  1. 实践Filebeats

    2024-06-14 16:42:03       6 阅读
  2. React

    2024-06-14 16:42:03       41 阅读
  3. 离线语音识别 sherpa-ncnn 体验

    2024-06-14 16:42:03       38 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-14 16:42:03       17 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-14 16:42:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-14 16:42:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-14 16:42:03       18 阅读

热门阅读

  1. Selenium入门之环境搭建

    2024-06-14 16:42:03       8 阅读
  2. ES6+Vue

    ES6+Vue

    2024-06-14 16:42:03      5 阅读
  3. 十进制转二进制的计算法则

    2024-06-14 16:42:03       6 阅读
  4. opensips ACC模块扩展字段

    2024-06-14 16:42:03       9 阅读
  5. 【深度学习】【Prompt】使用GPT的一些提示词

    2024-06-14 16:42:03       10 阅读
  6. PHP中的while循环:用法、技巧与最佳实践

    2024-06-14 16:42:03       10 阅读
  7. 一个cache的设计总结

    2024-06-14 16:42:03       6 阅读
  8. Windows 11部署FunASR离线语音识别系统

    2024-06-14 16:42:03       10 阅读
  9. Scikit-learn 基础教程:机器学习的初步指南

    2024-06-14 16:42:03       12 阅读
  10. Python教程:机器学习 - 百分位数(4)

    2024-06-14 16:42:03       10 阅读
  11. 养殖业自动化设备厂家

    2024-06-14 16:42:03       8 阅读