ElasticSearch实战系列十: ElasticSearch冷热分离架构
前言
本文主要介绍ElasticSearch冷热分离架构以及实现。
冷热分离架构介绍
冷热分离是目前ES非常火的一个架构,它充分的利用的集群机器的优劣来实现资源的调度分配。ES集群的索引写入及查询速度主要依赖于磁盘的IO速度,冷热数据分离的关键点为使用固态磁盘存储数据。若全部使用固态,成本过高,且存放冷数据较为浪费,因而使用普通机械磁盘与固态磁盘混搭,可做到资源充分利用,性能大幅提升的目标。因此我们可以将实时数据(5天内)存储到热节点中,历史数据(5天前)的存储到冷节点中,并且可以利用ES自身的特性,根据时间将热节点的数据迁移到冷节点中,这里因为我们是按天建立索引库,因此数据迁移会更加的方便。
架构图:
一个例子
使用冷热分离的时候,我们需要将索引库建立在热节点中,等到一定的时间时间在将该索引库迁移冷节点中。因此这里我们需要更加热节点的量来进行设置分片数。
比如,我们拥有6个热节点,9个冷节点,索引库的主分片的数据量500G左右,那么该索引库建立18个分片并且都在在热节点中,此时该索引库的分片的分布是,热节点:18,冷节点0;等到该数据不是热数据之后,将该索引库的分片全部迁移到冷节点中,索引库的分片的分布是, 热节点:0,冷节点18。
单个索引库热冷节点分片分布示例:
时间 | 索引库名称 | 热节点分片数量 | 冷节点分片数量 |
---|---|---|---|
20190707 | TEST_20190703 | 18 | 0 |
20190708 | TEST_20190703 | 0 | 18 |
最终实现效果图,这里我用cerebro界面截图来表示
cerebro示例图:
写入ES索引库中,分片分布在热节点中
过了一段时间之后进行了迁移,分片数据迁移到了冷节点:
更多ElasticSearch的相关介绍可以查看我的这篇博文:https://www.cnblogs.com/xuwujing/p/12093933.html
ElasticSearch冷热分离架构实现
ElasticSearch冷热分离架构是一种思想,其实现原理是使用ElasticSearch的路由完成,在data节点设置对应的路由,然后在创建索引库时指定分布到那些服务器,过一段时间之后,根据业务要求在将这些索引库的数据进行迁移到其他data节点中。
ElasticSearch节点配置
这里需要改变的节点为data节点,其他的节点配置无需更改。这里我就用以前写的ElasticSearch实战系列一: ElasticSearch集群+Kibana安装教程里面的配置进行更改。
data节点的elasticsearch.yml原配置:
cluster.name: pancm
node.name: data1
path.data: /home/elk/datanode/data
path.logs: /home/elk/datanode/logs
network.host: 0.0.0.0
network.publish_host: 192.169.0.23
transport.tcp.port: 9300
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.169.0.23:9301","192.169.0.24:9301","192.169.0.25:9301"]
node.master: false
node.data: true
node.ingest: false
index.number_of_shards: 5
index.number_of_replicas: 1
discovery.zen.minimum_master_nodes: 1
bootstrap.memory_lock: true
http.max_content_length: 1024mb
相比普通的data节点, 主要是增加了这两个配置:
node.attr.rack: r1
node.attr.box_type: hot
热节点配置示例:
cluster.name: pancm
node.name: data1
path.data: /home/elk/datanode/data
path.logs: /home/elk/datanode/logs
network.host: 0.0.0.0
network.publish_host: 192.169.0.23
transport.tcp.port: 9300
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.169.0.23:9301","192.169.0.24:9301","192.169.0.25:9301"]
node.master: false
node.data: true
node.ingest: false
index.number_of_shards: 5
index.number_of_replicas: 1
discovery.zen.minimum_master_nodes: 1
bootstrap.memory_lock: true
http.max_content_length: 1024mb
node.attr.rack: r1
node.attr.box_type: hot
冷节点配置大体相同,就是后面的值进行更改
node.attr.rack: r9
node.attr.box_type: cool
冷节点配置示例:
cluster.name: pancm
node.name: data1
path.data: /home/elk/datanode/data
path.logs: /home/elk/datanode/logs
network.host: 0.0.0.0
network.publish_host: 192.169.0.23
transport.tcp.port: 9300
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.169.0.23:9301","192.169.0.24:9301","192.169.0.25:9301"]
node.master: false
node.data: true
node.ingest: false
index.number_of_shards: 5
index.number_of_replicas: 1
discovery.zen.minimum_master_nodes: 1
bootstrap.memory_lock: true
http.max_content_length: 1024mb
node.attr.rack: r1
node.attr.box_type: hot
ElasticSearch索引库设置
在创建索引库的时候需要指定默认索引库的分片归属,如果没有指定,就会根据ElasticSearch默认进行均匀分布。这里我们将索引库默认创建到hot节点中,满足业务条件之后在使用命令或代码将该索引库设置到冷节点中。
索引示例:
PUT TEST_20190717
{
"index":"TEST_20190717",
"settings": {
"number_of_shards" :18,
"number_of_replicas" : 1,
"refresh_interval" : "10s",
"index.routing.allocation.require.box_type":"hot"
},
"mappings": {
"mt_task_hh": {
"properties": {
"accttype": {
"type": "byte"
},
....
}
}
索引库冷节点设置
根据业务要求,我们可以对索引库的数据进行迁移,使用dsl语句在kibana上执行或者使用java代码实现都可以。
dsl语句:
PUT TEST_20190717/_settings
{
"index.routing.allocation.require.box_type":"cool"
}
java代码实现:
public static void setCool(String index) throws IOException {
RestClient restClient = null;
try {
Objects.requireNonNull(index, "index is not null");
restClient = client.getLowLevelClient();
String source = "{\"index.routing.allocation.require.box_type\": \"%s\"}";
source = String.format(source, "cool");
HttpEntity entity = new NStringEntity(source, ContentType.APPLICATION_JSON);
restClient.performRequest("PUT", "/" + index + "/_settings", Collections.<String, String>emptyMap(), entity);
} catch (IOException e) {
throw e;
} finally {
if (restClient != null) {
restClient.close();
}
}
}
完整代码地址: https://github.com/xuwujing/java-study/tree/master/src/main/java/com/pancm/elasticsearch
其它
其实这篇文章本应来说在2019年就完成了初稿,但是因为其他的事情一直耽搁,好在查看草稿是发现了,于是便补了。因为时隔太久,细节上相比之前的文章有一定的差距。不过好在是写出来了,以后的话写文章的话还是尽早,不然后面就忘了。目前ElasticSearch实战系列已经写了10篇了,虽然中间的间隔有点久,后面我会慢慢的更新这个系列,尽量把自己所学所感悟的写出来,如有写的不好,希望能够指出讨论。
- ElasticSearch实战系列一: ElasticSearch集群+Kinaba安装教程
- ElasticSearch实战系列二: ElasticSearch的DSL语句使用教程---图文详解
- ElasticSearch实战系列三: ElasticSearch的JAVA API使用教程
- ElasticSearch实战系列四: ElasticSearch理论知识介绍
- ElasticSearch实战系列五: ElasticSearch的聚合查询基础使用教程之度量(Metric)聚合
- ElasticSearch实战系列六: Logstash快速入门
- ElasticSearch实战系列七: Logstash实战使用-图文讲解
- ElasticSearch实战系列八: Filebeat快速入门和使用---图文详解
- ElasticSearch实战系列九: ELK日志系统介绍和安装
音乐推荐
原创不易,如果感觉不错,希望给个推荐!您的支持是我写作的最大动力!
版权声明:
作者:虚无境
博客园出处:http://www.cnblogs.com/xuwujing
CSDN出处:http://blog.csdn.net/qazwsxpcm
掘金出处:https://juejin.im/user/5ae45d5bf265da0b8a6761e4
个人博客出处:http://www.panchengming.com
ElasticSearch实战系列十: ElasticSearch冷热分离架构的更多相关文章
- ElasticSearch实战系列十一: ElasticSearch错误问题解决方案
前言 本文主要介绍ElasticSearch在使用过程中出现的各种问题解决思路和办法. ElasticSearch环境安装问题 1,max virtual memory areas vm.max_ma ...
- ElasticSearch实战系列四: ElasticSearch理论知识介绍
前言 在前几篇关于ElasticSearch的文章中,简单的讲了下有关ElasticSearch的一些使用,这篇文章讲一下有关 ElasticSearch的一些理论知识以及自己的一些见解. 虽然本人是 ...
- ElasticSearch实战系列二: ElasticSearch的DSL语句使用教程---图文详解
前言 在上一篇中介绍了ElasticSearch集群和kinaba的安装教程,本篇文章就来讲解下 ElasticSearch的DSL语句使用. ElasticSearch DSL 介绍 Elastic ...
- ElasticSearch实战系列三: ElasticSearch的JAVA API使用教程
前言 在上一篇中介绍了ElasticSearch实战系列二: ElasticSearch的DSL语句使用教程---图文详解,本篇文章就来讲解下 ElasticSearch 6.x官方Java API的 ...
- ElasticSearch实战系列五: ElasticSearch的聚合查询基础使用教程之度量(Metric)聚合
Title:ElasticSearch实战系列四: ElasticSearch的聚合查询基础使用教程之度量(Metric)聚合 前言 在上上一篇中介绍了ElasticSearch实战系列三: Elas ...
- ElasticSearch实战系列一: ElasticSearch集群+Kinaba安装教程
前言 本文主要介绍的是ElasticSearch集群和kinaba的安装教程. ElasticSearch介绍 ElasticSearch是一个基于Lucene的搜索服务器,其实就是对Lucene进行 ...
- ElasticSearch实战系列六: Logstash快速入门和实战
前言 本文主要介绍的是ELK日志系统中的Logstash快速入门和实战 ELK介绍 ELK是三个开源软件的缩写,分别表示:Elasticsearch , Logstash, Kibana , 它们都是 ...
- ElasticSearch实战系列八: Filebeat快速入门和使用---图文详解
前言 本文主要介绍的是ELK日志系统中的Filebeat快速入门教程. ELK介绍 ELK是三个开源软件的缩写,分别表示:Elasticsearch , Logstash, Kibana , 它们都是 ...
- ElasticSearch实战系列九: ELK日志系统介绍和安装
前言 本文主要介绍的是ELK日志系统入门和使用教程. ELK介绍 ELK是三个开源软件的缩写,分别表示:Elasticsearch , Logstash, Kibana , 它们都是开源软件.新增了一 ...
随机推荐
- ESLint & vue
ESLint & vue { "name": "app", "version": "1.0.1", " ...
- node --experimental-modules & node.js ES Modules
node --experimental-modules & node.js ES Modules how to run esm modules in node.js cli $ node -v ...
- X-Frame-Options & iframe & CORS
X-Frame-Options & iframe & CORS https://github.com/xgqfrms/FEIQA/issues/23 X-Frame-Options i ...
- GitHub Sponsors
GitHub Sponsors https://github.com/sponsors https://github.com/sponsors/xgqfrms?preview=true https:/ ...
- markdown & typora
markdown & typora Markdown Editor Typora https://www.typora.io/ https://github.com/typora xgqfrm ...
- flutter 插件调用callback函数
dart plugin class TestLib { static MethodChannel _channel = const MethodChannel('test_lib') ..setMet ...
- CodeMirror动态修改代码(关键: editor.getDoc().setValue(data); editor.refresh();)
在使用codemirror时,其原理是根据form中的textarea标签,自动加载其内容,获得代码行的显示.(具体使用方式参见 codemirror官网使用手册 http://codemirror. ...
- JDK源码阅读-DirectByteBuffer
本文转载自JDK源码阅读-DirectByteBuffer 导语 在文章JDK源码阅读-ByteBuffer中,我们学习了ByteBuffer的设计.但是他是一个抽象类,真正的实现分为两类:HeapB ...
- Java自学第6期——Collection、Map、迭代器、泛型、可变参数、集合工具类、集合数据结构、Debug
集合:集合是java中提供的一种容器,可以用来存储多个数据. 集合和数组既然都是容器,它们有啥区别呢? 数组的长度是固定的.集合的长度是可变的. 数组中存储的是同一类型的元素,可以存储基本数据类型值. ...
- JS相关基础
1. ES5和ES6继承方式区别 ES5定义类以函数形式, 以prototype来实现继承 ES6以class形式定义类, 以extend形式继承 2. Generator了解 ES6 提供的一种异步 ...