一、集群&索引&分片关系:
一个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"
}
}