elasticsearch 实现冷热隔离
前言
冷数据索引:查询频率低,基本无写入,一般为当天或最近2天以前的数据索引
热数据索引:查询频率高,写入压力大,一般为当天数据索引
优点
1冷热数据分离
ES集群的索引写入及查询速度主要依赖于磁盘的IO速度,冷热数据分离的关键为使用SSD磁盘存储数据。
若全部使用SSD,成本过高,且存放冷数据较为浪费,因而使用普通SATA磁盘与SSD磁盘混搭,可做到资源充分利用,性能大幅提升的目标。
2 数据读写分离
几点结论:
若使当天索引及副本都写在SSD磁盘上,SSD磁盘使用量需翻倍,代价可能过高。(读写效率最高,但由于SSD节点肯定较少,读写都在相同节点上,节点压力会非常大)
现有的方式,只使用普通的SATA磁盘存储,代价最低。(读写效率最低,即为当前运行状况)
使用集群路由分配策略,SSD与SATA各存放1份数据,SSD磁盘只需分配原先的一半。(读写效率折中,均有较大提升)
先安装es集群
我以elasticsearch-6.3.2.tar.gz为例,
各节点的es配置
172.16.129.8 master
172.16.128.244 cold
172.16.128.174 hot
master
cluster.name: elk
node.master: true
node.data: false
node.name: 172.16.129.8
#node.attr.box_type: hot
#node.tag: hot
path.data: /usr/local/elasticsearch-6.3.2/data
path.logs: /usr/local/elasticsearch-6.3.2/log
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
transport.tcp.compress: true
discovery.zen.ping.unicast.hosts: ["172.16.129.8"]
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节点
cluster.name: elk
node.master: false
node.data: true
node.name: 172.16.128.174
node.attr.box_type: hot
path.data: /usr/local/elasticsearch-6.3.2/data
path.logs: /usr/local/elasticsearch-6.3.2/log
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
transport.tcp.compress: true
discovery.zen.ping.unicast.hosts: ["172.16.129.8"]
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节点
cluster.name: elk
node.master: false
node.data: true
node.name: 172.16.128.244
node.attr.box_type: cold
path.data: /usr/local/elasticsearch-6.3.2/data
path.logs: /usr/local/elasticsearch-6.3.2/log
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
transport.tcp.compress: true
discovery.zen.ping.unicast.hosts: ["172.16.129.8"]
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: "*"
启动es之后 启动filebeat将日志导入es
通过header查看 发现数据显示的不对
删除索引
通过kibana 执行如下命令
或者curl命令如下
curl -XPUT "http://172.16.129.8:9200/tomcat-test-2019.02.02/_settings" -H 'Content-Type: application/json' -d'
{
"settings": {
"index.routing.allocation.require.box_type": "cold"
}
}'
再次启动filebeat
查看es日志 日志存在于hot 节点上
测试是否可以将hot节点的数据 迁移到cold上
执行
或者
curl -XPUT "http://172.16.129.8:9200/tomcat-test-2019.02.02/_settings" -H 'Content-Type: application/json' -d'
{
"settings": {
"index.routing.allocation.require.box_type": "cold"
}
}'
迁移成功
后来生成新的索引 还是会在hot节点
参考
http://www.mamicode.com/info-detail-2361555.html
https://elasticsearch.cn/article/6127