ELK 索引生命周期管理

kibana 索引配置

  • 管理索引

点击设置 --- Elasticsearch 的 Index management 可以查看 elk 生成的所有索引 (设置,Elasticsearch ,管理)

  • 配置 kibana 的索引匹配
    设置,Kibana,索引模式

  • 配置索引生命周期
    点击设置 --- Elasticsearch 的 Index Lifecycle Policies 可以配置策略管理索引生命周期

配置索引策略文档地址:https://www.elastic.co/guide/en/elasticsearch/reference/7.3/index-lifecycle-management.html

首先创建 Index Lifecycle Policies 也就官方文档中的四个阶段配置
需要说明的是并不是每个阶段都是必要配置

配置好生命周期策略后,我们需要创建一个模板,将我们现在的输入 index 接管过来,然后将策略应用于这个模板,这就达到了,每次创建的 index 都能应用于这一策略
其实最方便的就是将你创建的索引都以 logstash-* 开头,默认就包含一个名为 logstash 的模板。

查询当前的模板

# 查询所有模板
GET /_template/

#查询其中某一个模板
GET /_template/logstash

{
  "logstash" : {
    "order" : 0,
    "version" : 60001,
    "index_patterns" : [
      "logstash-*"
    ],
    "settings" : {
      "index" : {
        "lifecycle" : {
          "name" : "watch-history-ilm-policy"
        },
        "number_of_shards" : "1",
        "refresh_interval" : "5s"
      }
    },
    "mappings" : {
      "dynamic_templates" : [
        {
          "message_field" : {
            "path_match" : "message",
            "mapping" : {
              "norms" : false,
              "type" : "text"
            },
            "match_mapping_type" : "string"
          }
        },
        {
          "string_fields" : {
            "mapping" : {
              "norms" : false,
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "ignore_above" : 256,
                  "type" : "keyword"
                }
              }
            },
            "match_mapping_type" : "string",
            "match" : "*"
          }
        }
      ],
      "properties" : {
        "@timestamp" : {
          "type" : "date"
        },
        "geoip" : {
          "dynamic" : true,
          "properties" : {
            "ip" : {
              "type" : "ip"
            },
            "latitude" : {
              "type" : "half_float"
            },
            "location" : {
              "type" : "geo_point"
            },
            "longitude" : {
              "type" : "half_float"
            }
          }
        },
        "@version" : {
          "type" : "keyword"
        }
      }
    },
    "aliases" : { }
  }
}


以上的模板接管了 logstash-* 开头的 index,然后将策略应用于这些 index

如果你不想以 logstash-* 开头创建索引,你可以先创建个模板参考如下:

PUT /_template/my_template
{
  "order" : 0,
  "index_patterns" : [
    "filebeat_cash-*",
    "filebeat_custom-*",
    "filebeat_portal-*",
    "filebeat_user-*",
    "filebeat_hkd-*",
    "filebeat_test_custom-*",
    "filebeat_test_portal-*",
    "filebeat_test_user-*",
    "filebeat_test_hkd-*",
    "filebeat_test_canal_topic-*"
  ],
  "settings" : {
    "index" : {
      "number_of_shards" : "1",
      "refresh_interval" : "5s"
    }
  },
  "mappings" : {
    "dynamic_templates" : [
      {
        "message_field" : {
          "path_match" : "message",
          "mapping" : {
            "norms" : false,
            "type" : "text"
          },
          "match_mapping_type" : "string"
        }
      },
      {
        "string_fields" : {
          "mapping" : {
            "norms" : false,
            "type" : "text",
            "fields" : {
              "keyword" : {
                "ignore_above" : 256,
                "type" : "keyword"
              }
            }
          },
          "match_mapping_type" : "string",
          "match" : "*"
        }
      }
    ],
    "properties" : {
      "@timestamp" : {
        "type" : "date"
      },
      "geoip" : {
        "dynamic" : true,
        "properties" : {
          "ip" : {
            "type" : "ip"
          },
          "latitude" : {
            "type" : "half_float"
          },
          "location" : {
            "type" : "geo_point"
          },
          "longitude" : {
            "type" : "half_float"
          }
        }
      },
      "@version" : {
        "type" : "keyword"
      }
    }
  },
  "aliases" : { }
}

以上的模板接管了 filebeat-* 开头的 index,然后将策略应用于这些 index

现在我们就可以在 index management 里查看索引当前的生命周期状态

原文地址:https://www.cnblogs.com/sanduzxcvbnm/p/11982810.html