前言:当ELK平台运行的时间越来越长,对服务器磁盘占用空间就会越来越大,传统的清理index索引数据是脚本+计划任务,虽然能够解决定时清理数据的需求,当索引越来越多,每次都要去修改脚本并不方面。ELK官方在6.6版本推出了 ILM (index lifecycle Management) 满足以上的需求

阿里云冷热分离与生命周期管理

es官网生命周期管理

es视频教学

当前的ELK 版本为7.9.3

filebeat.yml文件
filebeat.inputs:
- type: filestreamenabled: trueid: id9tags: ["test-yingjian"]paths:- /root/access.logfields:log_topics: test-yingjian# 这个是用来处理异常产生多行数据时,将多行数据当作一条日志处理,根据自己的异常日志的格式做修改multiline.pattern: '^\['multiline.negate: truemultiline.match: aftertail_files: trueignore_older: 1hfilebeat.config.modules:# Glob pattern for configuration loadingpath: ${path.config}/modules.d/*.yml# Set to true to enable config reloadingreload.enabled: falseoutput.logstash:hosts: ["172.18.138.10:5044"]processors:- add_host_metadata:when.not.contains.tags: forwarded- add_cloud_metadata: ~- add_docker_metadata: ~- add_kubernetes_metadata: ~
logstash.conf 文件
input {beats {port => 5044client_inactivity_timeout => 36000}filter {mutate {}
}output {if "system" in [type]  {elasticsearch {hosts => ["http://172.18.138.10:9200"]# 索引名称,没有会自动创建index => "%{tags}-%{+YYYY.MM}"# 账号user => "elastic"# 密码password => "********"}} else if "test-yingjian" in [tags] {elasticsearch {hosts => ["http://172.18.138.10:9200"]# 索引名称,没有会自动创建index => "test" #对应创建的索引别名# 账号user => "elastic"# 密码password => "********"}} else {elasticsearch {hosts => ["http://172.18.138.10:9200"]# 索引名称,没有会自动创建index => "%{[fields][log_topics]}"# 账号user => "elastic"# 密码password => "********"}}    file {#   path => "/data/eslog/%{+YYYY-MM-dd}/%{tags}.log"path => "/data/eslog/%{+YYYY-MM-dd}/%{[fields][log_topics]}.log"}
}
elasticsearch.yml
cluster.name: es_junzun_pro  #集群名称
node.master: true #主节点 主要用于元数据(metadata)的处理,比如索引的新增、删除、分片分配等
node.data: true  #数据节点 这样的节点负责存储数据。后期提供存储和查询服务
node.attr.rack: r1  # hot节点标识
node.attr.hotwarm_type: hot    #节点类型 [hotwarm] 自定义
node.name: es_jinzun
path.data: /data/elastic/data  #es 存储目录
path.logs: /data/elastic/logs  #es 日志目录
bootstrap.memory_lock: true    #不使用交换分区
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["172.18.138.10"]
transport.tcp.port: 9300
cluster.initial_master_nodes: ["es_jinzun"]
xpack.security.enabled: true  #开启X-pack 认证
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12# x-head 访问配置  master节点配置
http.cors.enabled: true
http.cors.allow-origin: "*"

配置ilm生命管理周期

脚本创建 ilm 策略

在kibana开发工具操作

PUT _ilm/policy/test_policy
{"policy": {                       "phases": {"hot": {                      "actions": {"rollover": {             "max_size": "50GB","max_age": "30d","max_docs" : 10}}},"delete": {"min_age": "30s",           "actions": {"delete": {}              }}}}
}

配置索引模板绑定ilm策略


脚本创建索引模板

PUT _template/test_template
{"index_patterns" : ["test-*"],"settings": {"index.number_of_shards": 1,"index.number_of_replicas": 0,"index.lifecycle.name": "test_policy","index.routing.allocation.require.hotwarm_type":"hot","index.lifecycle.rollover_alias": "test"}
}

基于序号创建初始索引

PUT test-000001
{"aliases": {"test":{   #test 索引别名 对应 rollover_alias 配置"is_write_index": true  #该索引可以被写入}}
}

配置建议

  1. logstash 基于x-pack 传输数据到es 该账号我设置是elastic用户 生产环境建议单独创建一个用户用于传输数据
  2. logstash 对输出到es中的日志数据在本地备份,当日志数据需要重新导入的时候 不需要在每一台服务器上操作,只需要在logstash配置重新采集即可
  3. es 集群master节点保证可用性 3台以上并且为奇数
  4. es 集群node节点 作为数据节点 对应cpu 内存 硬盘 要求比较高
  5. es 每个索引的分片大小控制在 30GB-50GB大小
  6. es 主分片+副本分片数量 总和为1.5~3倍数量的node节点数量为适
  7. es refresh_interval flush 磁盘时间间隔 默认为1s, 根据不同的日志调整该刷新间隔时间,时间越短对服务器压力就越大 (即同一时刻从内存写入到磁盘的日志就越多)
  8. logstash 配置文件中 移除掉不需要的字段

测试filebeat写入数据

当前手动写入9条数据

再写入一条数据,查看索引是否会自动轮转后,并且30s后删除


文档所在的索引为

由于我操作慢了点30s后 test-000001已经被自动删除了

现在再去查询数据,会出现找不到数据


重新写入数据到es,此时数据存在的索引为test-000002

查看冷热节点状态

GET _cat/nodeattrs?v&h=host,attr,value

查看logstash本地备份数据

{"ecs":{"version":"1.12.0"},"@version":"1","agent":{"id":"c0b8166d-df20-4348-aa57-79c08ad2e552","ephemeral_id":"5e35edad-cb7d-48df-aa15-a4dafca785bc","name":"guojing","hostname":"guojing","version":"7.17.4","type":"filebeat"},"input":{"type":"filestream"},"fields":{"log_topics":"test-yingjian"},"@timestamp":"2022-07-28T07:35:59.500Z","log":{"file":{"path":"/root/access.log"},"offset":2095},"tags":["test-yingjian","beats_input_codec_plain_applied"],"host":{"name":"guojing"},"message":"10"}
{"@version":"1","ecs":{"version":"1.12.0"},"agent":{"id":"c0b8166d-df20-4348-aa57-79c08ad2e552","name":"guojing","ephemeral_id":"5e35edad-cb7d-48df-aa15-a4dafca785bc","hostname":"guojing","version":"7.17.4","type":"filebeat"},"input":{"type":"filestream"},"fields":{"log_topics":"test-yingjian"},"@timestamp":"2022-07-28T07:40:23.513Z","log":{"file":{"path":"/root/access.log"},"offset":2098},"tags":["test-yingjian","beats_input_codec_plain_applied"],"host":{"name":"guojing"},"message":"1"}
{"@version":"1","ecs":{"version":"1.12.0"},"agent":{"id":"c0b8166d-df20-4348-aa57-79c08ad2e552","ephemeral_id":"5e35edad-cb7d-48df-aa15-a4dafca785bc","name":"guojing","hostname":"guojing","version":"7.17.4","type":"filebeat"},"input":{"type":"filestream"},"fields":{"log_topics":"test-yingjian"},"@timestamp":"2022-07-28T07:40:23.513Z","log":{"file":{"path":"/root/access.log"},"offset":2100},"tags":["test-yingjian","beats_input_codec_plain_applied"],"host":{"name":"guojing"},"message":"2"}
{"ecs":{"version":"1.12.0"},"@version":"1","agent":{"id":"c0b8166d-df20-4348-aa57-79c08ad2e552","name":"guojing","ephemeral_id":"5e35edad-cb7d-48df-aa15-a4dafca785bc","hostname":"guojing","version":"7.17.4","type":"filebeat"},"input":{"type":"filestream"},"fields":{"log_topics":"test-yingjian"},"@timestamp":"2022-07-28T07:40:23.513Z","log":{"file":{"path":"/root/access.log"},"offset":2102},"tags":["test-yingjian","beats_input_codec_plain_applied"],"host":{"name":"guojing"},"message":"3"}
{"@version":"1","ecs":{"version":"1.12.0"},"agent":{"id":"c0b8166d-df20-4348-aa57-79c08ad2e552","name":"guojing","ephemeral_id":"5e35edad-cb7d-48df-aa15-a4dafca785bc","hostname":"guojing","version":"7.17.4","type":"filebeat"},"input":{"type":"filestream"},"fields":{"log_topics":"test-yingjian"},"@timestamp":"2022-07-28T07:40:23.513Z","log":{"offset":2104,"file":{"path":"/root/access.log"}},"tags":["test-yingjian","beats_input_codec_plain_applied"],"host":{"name":"guojing"},"message":"4"}
{"@version":"1","ecs":{"version":"1.12.0"},"agent":{"id":"c0b8166d-df20-4348-aa57-79c08ad2e552","ephemeral_id":"5e35edad-cb7d-48df-aa15-a4dafca785bc","name":"guojing","hostname":"guojing","version":"7.17.4","type":"filebeat"},"input":{"type":"filestream"},"fields":{"log_topics":"test-yingjian"},"@timestamp":"2022-07-28T07:40:25.514Z","log":{"file":{"path":"/root/access.log"},"offset":2106},"tags":["test-yingjian","beats_input_codec_plain_applied"],"host":{"name":"guojing"},"message":"5"}

当es索引删除时可用该数据还原

服务器定时清理logstash es 日志数据

#!/usr/bin/bash#Tate:2022.4.26
#Author:Yingjian
#function: 定时清理elasticsearch、logstash日志文件
#envworkdir=`cd $(dirname $0);pwd`
seven_day_ago=`date -d '-7 day' "+%F"`cat > $workdir/es_log_dir.txt << EOF
/data/elastic/logs
/usr/local/services/logstash/logs
EOFwhile read line
do
find $line -type f -mtime +7 -exec rm -f {} \;
done < $workdir/es_log_dir.txtrm -rf /data/eslog/$seven_day_ago

ELK ILM 策略实现冷热数据分离 持续更新相关推荐

  1. MySQL基于冷热数据分离优化的LRU刷盘策略

    MySQL基于冷热数据分离优化的LRU刷盘策略 前言 对于计算机刷盘这个概念相信大家都非常熟悉了,刷盘策略,其实在操作系统层面来说的话就是页面置换算法. 不知道各位朋友们还记得页面置换算法有哪些吗? ...

  2. Shopee ClickHouse 冷热数据分离存储架构与实践

    本文首发于微信公众号"Shopee技术团队". 摘要 Shopee ClickHouse 是一款基于开源数据库 ClickHouse 做二次开发.架构演进的高可用分布式分析型数据库 ...

  3. 关于redis的冷热数据分离

    一.概述 当前KV数据库从存储介质可以分为两种模式,一种是以内存为主持久化为辅,如memcache(无持久化).redis等:一种是以持久化为主内存为辅,如ssdb(基于leveldb/rocksdb ...

  4. mysql 冷热数据分离_elasticsearch冷热数据读写分离

    Elasticsearch5.5冷热数据读写分离 前言 冷数据索引:查询频率低,基本无写入,一般为当天或最近2天以前的数据索引 热数据索引:查询频率高,写入压力大,一般为当天数据索引 当前系统日志每日 ...

  5. 云上如何做冷热数据分离

    目录(?)[-] 前言 如何区分冷热数据 冷数据的特点 冷数据的处理 场景一极低频度的查询 冷数据备份 使用冷数据 场景二需要经常查询 方案一冷热RDS 方案二冷数据转存RDS PostgreSQL版 ...

  6. 文件服务器冷热数据划分,游戏服务器冷热数据分离方案

    冷热数据分离 当前场景: gamserver启动时,会将所有数据加载到内存中,提高读取数据的性能.但是有很多数据很可能是不常用甚至再也用不到的数据,将这些数据加载到内存中需要占用更多的内存,极大的浪费 ...

  7. (六)大白话MySQL是如何基于冷热数据分离的方案,来优化LRU算法?

    (一)大白话MySQL执行SQL的流程 (二)大白话InnoDB存储引擎的架构设计 (三)大白话MySQL Binlog是什么? (四)MySQL的Buffer Pool内存结构 (五)MySQL的B ...

  8. 阿里云centos环境之被dos,syn攻击策略和排查方法,持续更新九

    阿里云centos环境之被dos,syn攻击策略和排查方法,持续更新<九> 阿里云centos环境之被dossyn攻击策略和排查方法持续更新九 查看cpu使用情况 查看网络连接情况 检查端 ...

  9. 【elasticsearch】——用ILM策略自动完成冷热数据分离

    一.前言 从Elastic Stack 迎来 6.6 版本后,就增加了ILM生命周期管理的功能.下面我们从以下几个方面来分析: 为什么索引会有生命?什么是索引生命周期? ILM 是如何划分索引生命周期 ...

最新文章

  1. kettle中三种类型: 增量不裁剪,增量裁剪,全量
  2. 传递函数极点与微分方程的解
  3. The prefix “mvc“ for element “mvc:annotation-driven“ is not bound 异常
  4. 5G NR — 频率、频段、载波、载频、载波带宽
  5. java封装示例代码
  6. 电气论文实现:对大规模用户负荷曲线进行聚类
  7. 土豆春季实习试题之惨烈教训
  8. centos 6.9 NTP基准时间服务器配置
  9. html控制按钮里面的文字,有谁可以告诉我web网页制作中通过三个按钮控制页面上的一段文字放? 爱问知识人...
  10. nparray和tensor的相互转化
  11. matlab ode45 初值,为什么设定的初值在ode45里无效?
  12. Python debug —— invalid literal for int() with base 10
  13. linux 欢迎信息
  14. Visual C#中用WMI编写网络应用程序
  15. R语言--字符串操作
  16. 英文键盘盲打最快速练习口诀和方法
  17. com词根词缀_用词根词缀背英语单词靠谱吗丨效果方法
  18. linux 查找pcre源码,pcre使用例子
  19. 宇宙简史——我们在哪儿
  20. Windows平台下搭建Qt编译环境(VS2008)

热门文章

  1. 多行文本展开收起(css)
  2. 苹果客户端支付后,服务器端对数据进行二次验证接口开发
  3. F1 Score详解 查准率较高 召回率较低怎末处理?
  4. android扫描文件,安卓手机怎么扫描文件_手机扫描文件的图文教程-系统城
  5. HTML的id选择器类选择器
  6. antd-select下拉框如何同时获取所选值ID和名字属性
  7. Espresso Idling Resource
  8. 软件能力成熟度模型(Capabilitymaturity model,CMM)
  9. 程序员为什么要学算法?
  10. 明日之后怎么跳过实名认证_明日之后,怎么能跳过教学