Elasticsearch使用小结之冷热分离

索引迁移

索引setting中的index.routing.allocation.exclude和index.routing.allocation.include可以用于指定索引分配与哪些节点。同时,这两个配置是可以在index存在的时候修改的,我们可以通过修改这两个配置的方式来迁移索引。
比如:
ES集群存在5个节点,ip分别为:
192.168.1.101,
192.168.1.102,
192.168.1.103,
192.168.1.104,
192.168.1.105
1. 我们先创建一个索引,使其分配在192.168.1.101,192.168.1.102上
PUT test_index
{
"settings":{
"index":{
"routing.allocation.exclude._ip":"192.168.1.101,192.168.1.102"
}
}
}
2. 使用cat shards API查看test_index的分片分布
GET _cat/shards/test_index
返回如下:
test_index 2 p STARTED 0 162b 192.168.1.105 Z1SgiFF
test_index 0 p STARTED 0 162b 192.168.1.103 qEu6eMp
test_index 3 p STARTED 0 162b 192.168.1.104 xlTltSO
test_index 5 p STARTED 0 162b 192.168.1.104 xlTltSO
test_index 4 p STARTED 0 162b 192.168.1.105 Z1SgiFF
test_index 1 p STARTED 0 162b 192.168.1.103 qEu6eMp 3. 修改配置
PUT test_index/_settings
{
"settings":{
"index":{
"routing.allocation.exclude._ip":"192.168.1.103,192.168.1.104,192.168.1.105",
"number_of_shards": 6
}
}
}
4. 查看分片
GET _cat/shards/test_index
test_index 2 p STARTED 0 162b 192.168.1.102 9OHYhSa
test_index 4 p STARTED 0 162b 192.168.1.101 -RdAJHx
test_index 0 p STARTED 0 162b 192.168.1.102 9OHYhSa
test_index 5 p STARTED 0 162b 192.168.1.104 xlTltSO -> 192.168.1.101 -RdAJHx
test_index 3 p STARTED 0 162b 192.168.1.101 -RdAJHx
test_index 5 p STARTED 0 162b 192.168.1.102 9OHYhSa

节点tag

在节点启动时,在192.168.1.101和192.168.1.102上指定了
bin/elasticsearch -Enode.attr.rack=rack1
其余三台指定了
bin/elasticsearch -Enode.attr.rack=rack2
使用 GET _nodes/stats 查看:
{
"_nodes": {
"total": 5,
"successful": 5,
"failed": 0
},
"cluster_name": "elasticsearch",
"nodes": {
"-RdAJHxHTf2kHNyfUwHHBw": {
"timestamp": 1559467108509,
"name": "-RdAJHx",
"transport_address": "192.168.1.101:9200",
"host": "192.168.1.101",
"ip": "192.168.1.101:9200",
"roles": [
"data",
"ingest"
],
"attributes": {
"tag": "rack1"
}
....
},
"9OHYhSaxRgKKu_H0q18KyA": {
"timestamp": 1559467108628,
"name": "9OHYhSaxRgKKu_H0q18KyA",
"transport_address": "192.168.1.102:9200",
"host": "192.168.1.102",
"ip": "192.168.1.102:9200",
"roles": [
"data",
"ingest"
],
"attributes": {
"tag": "rack1"
}
....
},
"qEu6eMp9SEK7mlB9HmjCFA": {
"timestamp": 1559467110507,
"name": "qEu6eMp",
"transport_address": "192.168.1.103:9200",
"host": "192.168.1.103",
"ip": "192.168.1.103:9200",
"roles": [
"data",
"ingest"
],
"attributes": {
"tag": "rack2"
}
....
},
"xlTltSOCQmibG9HICbnQyw": {
"timestamp": 1559467110507,
"name": "xlTltSO",
"transport_address": "192.168.1.104:9200",
"host": "192.168.1.104",
"ip": "192.168.1.104:9200",
"roles": [
"data",
"ingest"
],
"attributes": {
"tag": "rack2"
}
....
},
"Z1SgiFFrQMqrPKKGir1EXg": {
"timestamp": 1559467110507,
"name": "Z1SgiFF",
"transport_address": "192.168.1.105:9200",
"host": "192.168.1.105",
"ip": "192.168.1.105:9200",
"roles": [
"data",
"ingest"
],
"attributes": {
"tag": "rack2"
}
....
}
我们也可以通过指定attributes来控制索引的迁移,这里需要配置index.routing.allocation.exclude.tag或者index.routing.allocation.include.tag

冷热分离

结合上述,我们可以很方便的进行冷热分离,先将节点分类,划分为两块,分别用于存储热数据和冷数据,在新建索引时指定索引的index.routing.allocation.exclude.tag为冷节点(或者index.routing.allocation.include.tag为热节点,效果一样),然后在索引不再有数据写入时指定index.routing.allocation.exclude.tag为热节点(与前面用的对应, 建议统一使用exclude或者include,两者混用时,由于两者不能覆盖,需要注意置空)
示例:
在上述的ES中,我们将rack1的作为热节点,rack2的作为冷节点。
1. PUT test_index
{
"settings":{
"routing.allocation.exclude.tag":"rack2",
"number_of_shards": 6
}
}
2. 数据写入
3. PUT test_index/_settings
{
"settings":{
"routing.allocation.exclude.tag":"rack1"
}
}

最新文章

  1. html5 canvas 详细使用教程
  2. ueditor的配置和使用
  3. windows批处理的介绍
  4. UIView的autoresizingMask和autoresizesSubviews属性的剖析
  5. bzoj1797: [Ahoi2009]Mincut 最小割
  6. sublime text 2中Windows下编写的脚本在Linux平台上运行遇到字符问题
  7. python 正则表达式汇总
  8. C# ignoring letter case for if statement(Stackoverflow)
  9. webwervice发布时出错 java.security.PrivilegedActionException
  10. libsvm工具箱C++编程实践2
  11. cocos对lua代码加密
  12. iOS关于蓝牙连接的简单介绍与使用
  13. Makefile模板(C++)
  14. 牛客国庆集训派对Day1.B.Attack on Titan(思路 最短路Dijkstra)
  15. cf954H
  16. ceph储存的S3接口实现(支持断点续传)
  17. 转:MD5辅助类
  18. iosclient发现_世界杯送流量活动项目总结
  19. 并发工具类(二)同步屏障CyclicBarrier
  20. k8s1.8 ingress 配置

热门文章

  1. redis系列(一):安装配置
  2. 线段树详解 (原理,实现与应用)(转载自:http://blog.csdn.net/zearot/article/details/48299459)
  3. IntelliJ IDEA 设置忽略SVN文件和文件夹
  4. UVALive 3716 DNA Regions ——(式子变形)
  5. 使用 Linux Mint 作为主要操作系统的一些个人常用软件
  6. Linux 系统配置永久性时间同步
  7. appdomain概念与应用
  8. 【Linux】安装 PostgreSQL
  9. [Oracle]察看一张表的约束 和 察看一张表的索引
  10. LayerDrawable