elasticsearch高可用集群的索引分片等设置

一、集群&索引&分片关系:

一个es高可用集群可由N个分布在不同机器上的多个节点组成,每个节点包含N个索引,同时每个索引可以分为多个shard分片,关系图:

es对加入集群的节点会自动分配副本shard,同时也允许手动修改配置

二、配置修改:

1.创建&获取索引信息:

PUT http://localhost:9200/my_index/
{"index:{"number_of_replicas":0,"number_of_shards":3}} //创建索引并设置副本为0,分片为3,创建成功后非动态的分片数量不可更改
GET http://localhost:9200/_settings     //获取全部索引信息
GET http://localhost:9200/my_index/_settings     //获取索引my_index信息

2.修改索引的replicas数量:

PUT http://localhost:9200/my_index_v1/_settings
{"index":{"number_of_replicas":0}} //设置副本数量为0,默认为1

3.设置某个索引在每个节点的最大shard数量:

PUT http://localhost:9200/my_index_v1/_settings
{"index.routing.allocation.total_shards_per_node":3} //默认为5,如果此值小于number_of_shards值则会出现某些shard的UNASSIGNED情况

注:一般情况下,节点数= (副本数+1)*分片数

4.移动shard:

1) 将shard1从node2到node3:

POST http://localhost:9200/_cluster/reroute
{"commands":[{"move":{"index":"index_name","shard":1,"from_node":"node-2","to_node":"node-3"}}]}

2) 将未分配的shard0移动到node2:

POST http://localhost:9200/_cluster/reroute
{"commands": [{"allocate": {"index": "index_name", "shard": 0, "node": "node2"}}]}

5.根据磁盘使用率调整shard:

PUT http://localhost:9200/_cluster/_settings
{
  "transient": {
    "cluster.routing.allocation.disk.watermark.low": "85%",   //或者容量大小,如:50gb
    "cluster.routing.allocation.disk.watermark.high": "95%",  
    "cluster.info.update.interval": "1m"  
  }
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值