暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

ES冷热架构

IT那活儿 2022-04-18
2680

点击上方“IT那活儿”,关注后了解更多内容,不管IT什么活儿,干就完了!!!

冷热架构介绍
为了保证Elasticsearch的读写性能,官方建议磁盘使用SSD固态硬盘。
然而Elasticsearch要解决的是海量数据的存储和检索问题,海量的数据就意味需要大量的存储空间,如果都使用SSD固态硬盘成本将成为一个很大的问题,这也是制约许多企业和个人使用Elasticsearch的因素之一。为了解决这个问题,Elasticsearch冷热分离架构应运而生。
冷热架构是一项十分强大的功能,能够让将 Elasticsearch 部署划分为“热”数据节点和“冷”数据节点。
热数据节点处理所有新输入的数据,并且存储速度也较快,以便确保快速地采集和检索数据。
冷节点的存储密度则较大,如需在较长保留期限内保留日志数据,不失为一种具有成本效益的方法。
将这两种类型的数据节点结合到一起后,便能够有效地处理输入数据,并将其用于查询,同时还能在节省成本的前提下在较长时间内保留数据。此架构对日志用例来说尤其大有帮助,因为在日志用例中,人们的大部分精力都会专注于近期的日志(例如最近两周),而较早的日志(由于合规性或者其他原因仍需要保留)则可以接受较慢的查询时间。

冷热架构架构图

典型应用场景
一句话:在成本有限的前提下,让客户关注的实时数据和历史数据硬件隔离,最大化解决客户反应的响应时间慢的问题。
业务场景描述:
每日增量6TB日志数据,高峰时段写入及查询频率都较高,集群压力较大,查询ES时,常出现查询缓慢问题。
ES集群的索引写入及查询速度主要依赖于磁盘的IO速度,冷热数据分离的关键为使用SSD磁盘存储热数据,提升查询效率。
若全部使用SSD,成本过高,且存放冷数据较为浪费,因而使用普通SATA磁盘与SSD磁盘混搭,可做到资源充分利用,性能大幅提升的目标。

测试环境配置

冷热分离架构实现
ElasticSearch冷热分离架构是一种思想,其实现原理是使用ElasticSearch的路由完成,在data节点设置对应的路由,然后在创建索引库时指定分布到那些服务器,过一段时间之后,根据业务要求在将这些索引库的数据进行迁移到其他data节点中。
--hot节点参数配置:
cluster.name : es-clusternode.name : es01node.master : truenode.data : truenetwork.host : 192.168.43.137transport.tcp.port : 9300http.port : 9200http.cors.enabled : truehttp.cors.allow-origin : "*"bootstrap.memory_lock : truepath.data : /home/elasticsearch/datapath.logs : /home/elasticsearch/logsdiscovery.zen.ping.unicast.hosts : ["192.168.43.137:9300","192.168.43.137:9301", "192.168.43.138:9300", "192.168.43.139:9300", "192.148.43.140:9300"]discovery.zen.minimum_master_nodes : 1xpack.security.enabled : truexpack.security.transport.ssl.enabled : truexpack.security.transport.ssl.verification_mode: certificate xpack.ssl.key: elasticsearch-6.8.2/elasticsearch-6.8.2.keyxpack.ssl.certificate: elasticsearch-6.8.2/elasticsearch-6.8.2.crtxpack.ssl.certificate_authorities: ca/ca.crthttp.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Typenode.attr.box_type: hotcluster.name : es-clusternode.name : es02node.master : falsenode.data : truenetwork.host : 192.168.43.138transport.tcp.port : 9300http.port : 9200http.cors.enabled : truehttp.cors.allow-origin : "*"bootstrap.memory_lock : truepath.data : /home/elasticsearch/datapath.logs : /home/elasticsearch/logsdiscovery.zen.ping.unicast.hosts : ["192.168.43.137:9300","192.168.43.137:9301", "192.168.43.138:9300", "192.168.43.139:9300", "192.148.43.140:9300"]discovery.zen.minimum_master_nodes : 1xpack.security.enabled : truexpack.security.transport.ssl.enabled : truexpack.security.transport.ssl.verification_mode: certificate xpack.ssl.key: elasticsearch-6.8.2/elasticsearch-6.8.2.keyxpack.ssl.certificate: elasticsearch-6.8.2/elasticsearch-6.8.2.crtxpack.ssl.certificate_authorities: ca/ca.crthttp.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Typenode.attr.box_type: hotcluster.name : es-clusternode.name : node-2021070702node.master : falsenode.data : truenetwork.host : 192.168.43.137transport.tcp.port : 9300http.port : 9200http.cors.enabled : truehttp.cors.allow-origin : "*"bootstrap.memory_lock : truediscovery.zen.ping.unicast.hosts : ["192.168.43.137:9300","192.168.43.137:9301", "192.168.43.138:9300", "192.168.43.139:9300", "192.148.43.140:9300"]discovery.zen.minimum_master_nodes : 1xpack.security.enabled : truexpack.security.transport.ssl.enabled : truexpack.security.transport.ssl.verification_mode: certificate xpack.ssl.key: elasticsearch-6.8.2/elasticsearch-6.8.2.keyxpack.ssl.certificate: elasticsearch-6.8.2/elasticsearch-6.8.2.crtxpack.ssl.certificate_authorities: ca/ca.crthttp.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Typenode.attr.box_type: hotcluster.name : es-clusternode.name : es03node.master : falsenode.data : truenetwork.host : 192.168.43.139transport.tcp.port : 9300http.port : 9200http.cors.enabled : truehttp.cors.allow-origin : "*"bootstrap.memory_lock : truepath.data : /home/elasticsearch/datapath.logs : /home/elasticsearch/logsdiscovery.zen.ping.unicast.hosts : ["192.168.43.137:9300","192.168.43.137:9301", "192.168.43.138:9300", "192.168.43.139:9300", "192.148.43.140:9300"]discovery.zen.minimum_master_nodes : 1xpack.security.enabled : truexpack.security.transport.ssl.enabled : truexpack.security.transport.ssl.verification_mode: certificatexpack.ssl.key: elasticsearch-6.8.2/elasticsearch-6.8.2.keyxpack.ssl.certificate: elasticsearch-6.8.2/elasticsearch-6.8.2.crtxpack.ssl.certificate_authorities: ca/ca.crthttp.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Typenode.attr.box_type: cold
--cold节点参数配置:
cluster.name : es-clusternode.name : es04node.master : falsenode.data : truenetwork.host : 192.168.43.140transport.tcp.port : 9300http.port : 9200http.cors.enabled : truehttp.cors.allow-origin : "*"bootstrap.memory_lock : truepath.data : /home/elasticsearch/datapath.logs : /home/elasticsearch/logsdiscovery.zen.ping.unicast.hosts:["192.168.43.137:9300","192.168.43.137:9301","192.168.43.138:9300", "192.168.43.139:9300", "192.148.43.140:9300"]discovery.zen.minimum_master_nodes : 1xpack.security.enabled: truexpack.security.transport.ssl.enabled: truexpack.security.transport.ssl.verification_mode: certificatexpack.ssl.key: elasticsearch-6.8.2/elasticsearch-6.8.2.keyxpack.ssl.certificate: elasticsearch-6.8.2/elasticsearch-6.8.2.crtxpack.ssl.certificate_authorities: ca/ca.crthttp.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Typenode.attr.box_type: cold

索引库设置
在创建索引库的时候需要指定默认索引库的分片归属,如果没有指定,就会根据ElasticSearch默认进行均匀分布。这里我们将索引库默认创建到hot节点中,满足业务条件之后在使用命令或代码将该索引库设置到冷节点中。
索引示例:
创建索引test_20220125,主分片数5,副本数1,索引刷新时间10s,索引存放至hot节点。
curl -XPUT -H "Content-Type: application/json" http://elastic:qwer123@192.168.43.138:9200/test_20220125 -d'{  "index":"test_20220125",  "settings": {    "number_of_shards" :5,    "number_of_replicas" : 1,    "refresh_interval" : "10s",    "index.routing.allocation.require.box_type":"hot"  }}'
查看此时该索引的分片分布情况,分片全部分布在hot节点上。
向索引test_20220125中插入数据:
curl -H "Content-Type: application/json" -XPOST -u elastic:qwer123 -s http://192.168.43.139:9200/test_20220125/_doc -d '{"name":"dd","age":"23","profession":"dd"}'
查询索引test_20220125数据:
curl -H "Content-Type: application/json" -XGET -u elastic:qwer123 -s http://192.168.43.138:9200/test_20220125/_search?pretty -d'{"size" : 1}'

将该索引迁移至cold节点:
curl -XPUT -H "Content-Type: application/json" http://elastic:qwer123@192.168.43.138:9200/test_20220125/_settings -d'{"index.routing.allocation.require.box_type":"cold"}'
查看此时该索引的分片分布情况,分片全部迁移至cold节点上。
测试此时索引test_20220125是否正常,可以看到索引已正常迁移至cold节点,索引可正常查询写入。
插入一条数据:
curl -H "Content-Type: application/json" -XPOST -u elastic:qwer123 -s http://192.168.43.139:9200/test_20220125/_doc -d '{"name":"cc","age":"26","profession":"cc"}'
查看索引数据:
curl -H "Content-Type: application/json" -XGET -u elastic:qwer123 -s http://192.168.43.138:9200/test_20220125/_search?pretty -d'{"size" : 2}'


本文作者:刘能

本文来源:IT那活儿(上海新炬王翦团队)

文章转载自IT那活儿,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论