elasticsearch 冷熱數據的讀寫分離
阿新 • • 發佈:2017-08-06
prop 掛載 res arc ima 支持 enable hot ear
步驟
一、冷熱分離集群配置
比如三個機器共六個node的es集群。
每個機器上各掛載一個ssd 和 一個sata。每個機器需要啟動兩個es進程、每個進程對應不同類型的磁盤。
關鍵配置:
node.max_local_storage_nodes: 2 #允許每個機器啟動兩個es進程
path.data: /home/centos/es/elasticsearch-2.1.0/data/ssd #需要顯示指定es對應的數據目錄
啟動命令中需要指定node tag
./elasticsearch -d -Des.path.conf=/home/centos/es/elasticsearch-2.1.0/config/ssd -d --node.tag=ssd ./elasticsearch -d -Des.path.conf=/home/centos/es/elasticsearch-2.1.0/config/sata -d --node.tag=sata
啟動以後節點如下:
二、創建索引模板
http://192.168.126.132:9200/_template/hottest/ PUT
{ "order": 1, "template": "hottest*", "settings": { "index": { "number_of_shards": "3","number_of_replicas": "1", "refresh_interval": "1s", "routing.allocation.require.tag": "ssd" } }, "mappings": { "_default_": { "properties": { "userid": { "index": "not_analyzed", "type": "string" },"username": { "index": "not_analyzed", "type": "string" }, "sex": { "index": "not_analyzed", "type": "string" }, "address": { "index": "no", "type": "string" } }, "_all": { "enabled": false } } }, "aliases": { "hottest": {} } }
"routing.allocation.require.tag": "ssd" 指定默認寫入到 ssd 節點。
三、插入數據
http://192.168.126.132:9200/hottest_20170805/def/100001/ PUT
{ "userid": "100001", "username": "zhangsan", "sex": "1", "address": "beijing" }
在head 中看到數據全部保存在的 ssd 節點。
四、定時遷移老數據到 sata
http://192.168.126.132:9200/hottest_20170805/_settings/ PUT
{ "index.routing.allocation.require.tag": "sata" }
在head中看到數據移動到了 sata 節點
解決了兩個問題
一、使用有限的ssd節點資源來實現同時支持高並發讀寫和大數據量的存儲。
通過配置使最新的數據保存在ssd磁盤節點上,較老的數據自動遷移到廉價sata節點。
二、用戶做一次大的查詢,大量的讀io和聚合操作導致集群load升高,阻塞新數據的寫入,能做到一定程度的讀寫分離。
elasticsearch 冷熱數據的讀寫分離