elasticsearch实现冷热数据分离

 

目录(?)[-]

  1. es架构
  2. 各节点的es配置
  3. 如何实现某索引数据写到指定的node根据节点tag即可
  4. 如何实现数据从hot节点迁移到老的cold节点
  5. cold节点数据保留1个月
  6. 优化点
  7. logstash测试
  8. 关于es的index template

 

本文以最新的elasticsearch-6.3.0.tar.gz为例,为了节约资源,本文将副本调为0, 无client角色

https://www.elastic.co/blog/hot-warm-architecture-in-elasticsearch-5-x

以前es2.x版本配置elasticsearch.yml 里的node.tag: hot这个配置不生效了

被改成了这个
node.attr.box_type: hot

es架构

各节点的es配置

master节点:
[root@n1 ~]# cat /usr/local/elasticsearch/config/elasticsearch.yml 
cluster.name: elk
node.master: true
node.data: false
node.name: 192.168.2.11
#node.attr.box_type: hot
#node.tag: hot
path.data: /data/es 
path.logs: /data/log
network.host: 192.168.2.11
http.port: 9200
transport.tcp.port: 9300
transport.tcp.compress: true
discovery.zen.ping.unicast.hosts: ["192.168.2.11"]
cluster.routing.allocation.disk.watermark.low: 85%
cluster.routing.allocation.disk.watermark.high: 90%
indices.fielddata.cache.size: 10%
indices.breaker.fielddata.limit: 30%
http.cors.enabled: true
http.cors.allow-origin: "*"

- client节点(这里就不配置了)

node.master: false
node.data: false
- hot节点
[root@n2 ~]# cat /usr/local/elasticsearch/config/elasticsearch.yml 
cluster.name: elk
node.master: false
node.data: true
node.name: 192.168.2.12
node.attr.box_type: hot
path.data: /data/es
network.host: 192.168.2.12
http.port: 9200
transport.tcp.port: 9300
transport.tcp.compress: true
discovery.zen.ping.unicast.hosts: ["192.168.2.11"]
cluster.routing.allocation.disk.watermark.low: 85%
cluster.routing.allocation.disk.watermark.high: 90%
indices.fielddata.cache.size: 10%
indices.breaker.fielddata.limit: 30%
http.cors.enabled: true
http.cors.allow-origin: "*"
- cold节点
[root@n3 ~]# cat /usr/local/elasticsearch/config/elasticsearch.yml 
cluster.name: elk
node.master: false
node.data: true
node.name: 192.168.2.13
node.attr.box_type: cold
path.data: /data/es
network.host: 192.168.2.13
http.port: 9200
transport.tcp.port: 9300
transport.tcp.compress: true
discovery.zen.ping.unicast.hosts: ["192.168.2.11"]
cluster.routing.allocation.disk.watermark.low: 85%
cluster.routing.allocation.disk.watermark.high: 90%
indices.fielddata.cache.size: 10%
indices.breaker.fielddata.limit: 30%
http.cors.enabled: true
http.cors.allow-origin: "*"

如何实现某索引数据写到指定的node?(根据节点tag即可)

我hot节点打了tag

node.attr.box_type: cold
创建一个template(这里我用kibana来操作es的api)

PUT _template/test
{
    "index_patterns": "test-*",
    "settings": {
        "index.number_of_replicas": "0",
        "index.routing.allocation.require.box_type": "hot"
     }
}

意思是test-*索引命名的,都将其数据放到hot节点上.

如何实现数据从hot节点迁移到老的cold节点?

以test-2018.07.05索引为例,将它从hot节点迁移到cold节点

kibana里操作:

PUT /test-2018.07.05/_settings 
{ 
  "settings": { 
    "index.routing.allocation.require.box_type": "cold"
  } 
}

生产中可能每天,或每h,生成一个index.

test-2018.07.01
test-2018.07.02
test-2018.07.03
test-2018.07.04
test-2018.07.05
...

我可以写一个sh定时任务,每天晚上定时迁移数据.
如我在hot节点只保留7天的数据,7天以前的索引我匹配到, 每天晚上执行以下迁移命令即可.

cold节点数据保留1个月?

https://www.cnblogs.com/iiiiher/p/8029062.html

优化点:

1.为了提高吞吐量

path.data:/data1,/data2,/data3,/data4,/data5 可以每个目录挂一块盘

2.如果有10台hot节点,可以设置10个shards

logstash测试

input { stdin { } }
output {
    elasticsearch { 
        index => "test-%{+YYYY.MM.dd}"
        hosts => ["192.168.2.11:9200"] 
    }
    stdout {codec => rubydebug}
}

/usr/local/logstash/bin/logstash -f logstash.yaml --config.reload.automatic

关于es的index template

关于es的template
es数据入库时候都会匹配一个index template,默认匹配的是logstash这个template

template大致分成setting和mappings两部分

  1. settings主要作用于index的一些相关配置信息,如分片数、副本数,tranlog同步条件、refresh等。
  2. mappings主要是一些说明信息,大致又分为_all、_source、prpperties这三部分: https://elasticsearch.cn/article/335

根据index name来匹配使用哪个index template. index template属于节点范围,而非全局. 需要给某个节点单独设置index_template(如给设置一些特有的tag).

 

<think>好的,我现在需要处理用户关于ELK冷热数据分离的配置问题。首先,用户提到ELK的冷热数据分离,我应该先回忆一下ELK中相关组件的作用,尤其是Elasticsearch在这方面的功能。 根据引用[1],里面提到了冷热数据分离的思想和数据层的划分,比如内容层、热、温、冷、冻结层。这说明Elasticsearch数据分层策略是关键。我需要确认Elasticsearch的版本是否支持这些特性,因为冷热架构通常需要节点角色分配,比如热节点、冷节点等。 然后,用户可能想知道如何配置节点角色。引用[1]中的节点角色部分提到了内容节点、热数据节点、温数据节点等,所以需要指导用户如何在Elasticsearch的配置文件中设置node.roles参数,例如热节点配置为["data_hot", "data_content"],冷节点则是["data_cold"]。同时,硬件配置方面,热节点可能需要SSD,而冷节点使用HDD,这符合常规做法。 接下来是索引生命周期管理(ILM)。这部分需要说明如何创建策略,将索引从热层转移到冷层,并最终删除。可能需要引用Elasticsearch的ILM API,设置阶段(hot, warm, cold, delete)以及各阶段的动作,比如滚动更新、分片分配等。例如,在hot阶段设置rollover条件,在warm阶段设置副本数调整,cold阶段迁移到冷节点,最后删除。 另外,用户的问题中还提到了Kibana,引用[3]指出Kibana可以可视化集群状态,所以需要说明如何在Kibana中配置ILM策略,这样用户可以通过界面操作,而不仅是用API。 存储路径的配置也很重要。引用[4]提到可以通过多个数据路径提高吞吐量,比如path.data设置多个挂载点,每个目录挂一块盘。这可能适用于热节点需要更高IOPS的情况,而冷节点可能不需要那么多磁盘。 可能还需要考虑主从模式或读写分离,如引用[2]中的MySQL主从模式,但这里用户关注的是ELK,所以需要确保数据层的读写操作正确分配到不同节点,比如热节点处理写操作,冷节点只读。 最后,生成的相关问题需要覆盖配置步骤、优化方法、监控工具、硬件选择以及与其他系统的对比。例如,如何监控分层效果,硬件配置差异,以及和Hadoop冷热分离的区别。 需要确保回答结构清晰,分步骤说明配置方案,并引用提供的资料来支持每个部分,比如节点角色设置引用[1],存储路径引用[4],Kibana部分引用[3]。同时,检查是否有遗漏的配置点,比如索引属性设置、ILM策略的具体JSON示例等,可能需要提供代码块或配置示例,帮助用户实际操作。</think>### ELK冷热数据分离实现与配置方案 #### 一、核心实现原理 冷热数据分离通过**节点角色划分**和**索引生命周期管理(ILM)**实现[^1]。Elasticsearch数据按访问频率划分为多个层级: - **热层(Hot Tier)**:处理高频写入和查询,部署在SSD硬件上 - **温层(Warm Tier)**:存储近期访问数据,使用混合存储 - **冷层(Cold Tier)**:存储低频访问数据,使用大容量HDD - **冻结层(Frozen Tier)**:存储归档数据,采用可挂载存储 #### 二、具体配置步骤 1. **节点角色配置** 在`elasticsearch.yml`中定义节点角色: ```yaml # 热节点配置 node.roles: ["data_hot", "data_content"] path.data: /ssd1,/ssd2 # 多SSD提升吞吐量[^4] # 冷节点配置 node.roles: ["data_cold"] path.data: /hdd1 ``` 2. **索引生命周期策略** 通过Kibana界面或API创建ILM策略: ```json PUT _ilm/policy/hot_cold_policy { "policy": { "phases": { "hot": { "actions": { "rollover": {"max_size": "50GB"}, "set_priority": {"priority": 100} } }, "warm": { "min_age": "7d", "actions": { "allocate": {"require": {"data": "warm"}}, "shrink": {"number_of_shards": 1} } }, "cold": { "min_age": "30d", "actions": { "allocate": {"require": {"data": "cold"}} } } } } } ``` 3. **索引模板关联** ```json PUT _index_template/logs_template { "index_patterns": ["logs-*"], "template": { "settings": { "index.lifecycle.name": "hot_cold_policy", "index.routing.allocation.require.data": "hot" } } } ``` #### 三、监控与优化 1. 通过Kibana的**Stack Monitoring**模块查看数据分布[^3] 2. 使用`_ilm/explain`接口检查策略执行状态 3. 优化建议: - 热节点采用NVMe SSD提升IOPS - 冷节点启用压缩存储(`index.codec: best_compression`) - 冻结层数据使用可搜索快照(Searchable Snapshots)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值