elasticsearch:集群运维常用API

一、调整节点磁盘水位线
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-cluster.html#disk-based-shard-allocation
1、ES默认会根据data节点磁盘使用空间情况分配新shards,或将节点上已有shards迁移到其它节点上;

  • cluster.routing.allocation.disk.watermark.low:意味着ES不会为磁盘使用率超过此值的节点分配新shards,支持动态调整,默认85%或;
curl -H 'Content-Type:application/json' -XPUT   http://127.0.0.1:9200/_cluster/settings -d '{"transient" : {"cluster.routing.allocation.disk.watermark.low":"85%"}}'
  • cluster.routing.allocation.disk.watermark.high:意味着ES会为磁盘使用率超过此值的节点迁出shards或重分配shards,支持动态调整,默认90%;
curl -H 'Content-Type:application/json' -XPUT   http://127.0.0.1:9200/_cluster/settings -d '{"transient" : {"cluster.routing.allocation.disk.watermark.high":"90%"}}'
  • cluster.routing.allocation.disk.watermark.flood_stage:意味着ES会对磁盘使用率超过此值的节点上的所有索引设置只读(index.blocks.read_only_allow_delete),拒绝新数据写入,支持动态调整,默认95%。
curl -H 'Content-Type:application/json' -XPUT   http://127.0.0.1:9200/_cluster/settings -d '{"transient" : {"cluster.routing.allocation.disk.watermark.flood_stage":"95%"}}'

2、以上3个控制节点磁盘使用率的参数也支持将百分比值修改成磁盘空间剩余的绝对值,API如下

PUT _cluster/settings 
{ 
  "transient": { 
    "cluster.routing.allocation.disk.watermark.low": "100gb",
    "cluster.routing.allocation.disk.watermark.high": "50gb",
    "cluster.routing.allocation.disk.watermark.flood_stage": "10gb"
  } 
}

二、集群中Shards分配与恢复
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-cluster.html#cluster-shard-allocation-settings
1、cluster.routing.allocation.enable:控制shards分配规则,默认all,需要快速重启data节点的情况下建议将值设置为none;

  • all:允许分配集群中所有的分片;
  • none:不允许分片集群中所有的分片;
  • primaries:只允许分配集群中索引的新分片;
  • new_primaries:只允许分配集群中新索引的主分片;
curl -H 'Content-Type:application/json' -XPUT   http://127.0.0.1:9200/_cluster/settings -d '{"transient" : {"cluster.routing.allocation.enable":"all"}}'

2、分片恢复

  • cluster.routing.allocation.node_concurrent_incoming_recoveries:分片恢复过程中单节点允许多少并发分片传入数,默认2;
curl -H 'Content-Type:application/json' -XPUT   http://127.0.0.1:9200/_cluster/settings -d '{"transient" : {"cluster.routing.allocation.node_concurrent_incoming_recoveries":"2"}}'
  • cluster.routing.allocation.node_concurrent_outgoing_recoveries:分片恢复过程中单节点允许多少并发分片传出数,默认2;
curl -H 'Content-Type:application/json' -XPUT   http://127.0.0.1:9200/_cluster/settings -d '{"transient" : {"cluster.routing.allocation.node_concurrent_outgoing_recoveries":"2"}}'
  • cluster.routing.allocation.node_concurrent_recoveries:同时设置分片传入与传出的并发数;
curl -H 'Content-Type:application/json' -XPUT   http://127.0.0.1:9200/_cluster/settings -d '{"transient" : {"cluster.routing.allocation.node_concurrent_recoveries":"4"}}'

3、控制分片分配到单个data节点的数量

  • index.routing.allocation.total_shards_per_node:控制indices的分片分配到单个节点的分片数;
curl -H 'Content-Type:application/json' -XPUT   http://127.0.0.1:9200/indices_test/_settings -d '{"index.routing.allocation.total_shards_per_node":"3"}'
  • cluster.routing.allocation.total_shards_per_node:控制集群中所有分片分配到单个节点的分片数,不常用。
PUT _cluster/settings 
{ 
    "transient" : { 
        "cluster.routing.allocation.exclude._ip" : "10.0.0.1"     } 
}
curl -H 'Content-Type:application/json' -XPUT   http://127.0.0.1:9200/_cluster/settings -d '{"transient" : {"cluster.routing.allocation.exclude._ip":"127.0.0.1"}}'

三、集群中Shards rebalance
https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-cluster.html#cluster-shard-allocation-filtering
1、cluster.routing.rebalance.enable:控制集群shards rebalance参数,默认all,需要快速重启节点的情况下建议将值设置为none;

  • all:允许集群中所有shards进行rebalance;
  • none:不允许集群中所有indices的shards进行rebalance;
  • primaries:只允许集群中主shards进行rebalance;
  • replicas:只允许集群中副本shards进行rebalance;
curl -H 'Content-Type:application/json' -XPUT   http://127.0.0.1:9200/_cluster/settings -d '{"transient" : {"cluster.routing.rebalance.enable":"all"}}'

2、cluster.routing.allocation.cluster_concurrent_rebalance:允许集群中分片rebalance的并发数量,默认是2,集群扩容新data节点后通过调大此参数值让分片更快迁移到新节点上,快速达到集群分片Rebalance;

curl -H 'Content-Type:application/json' -XPUT   http://127.0.0.1:9200/_cluster/settings -d '{"transient" : {"cluster.routing.allocation.cluster_concurrent_rebalance":"2"}}'

四、索引settings
1、调整索引分片数

curl -H 'Content-Type:application/json' -XPUT   http://127.0.0.1:9200/indices_test/_settings -d '{"index":{"number_of_replicas" : 1}}'

2、调整索引refresh频率

curl -H 'Content-Type:application/json' -XPUT   http://127.0.0.1:9200/indices_test/_settings -d '{"index":{"refresh_interval" : "30s"}}'

3、调整索引translog flush策略

curl -H 'Content-Type:application/json' -XPUT   http://127.0.0.1:9200/indices_test/_settings -d '{"index":{"translog.durability" : "async","translog.flush_threshold_size":"1gb"}}'

你可能感兴趣的