ES 运维技巧收集--持续更新

设置磁盘空间水位线

PUT _cluster/settings

{

  "transient": {

    "cluster.routing.allocation.disk.watermark.low": "80%",

    "cluster.routing.allocation.disk.watermark.high": "90%",

  }

}

集群重启后个别分配一直处于UNASSIGNED状态

收到将为分配的分片分配

$curl -XPOST 'http://localhost:9200/_cluster/reroute' -d '{
"commands":[{
"allocate":{
"index":"filebeat-ali-hk-fd-tss1",
"shard":1,
"node":"ali-hk-ops-elk1",

allow_primary" : true   (允许该分片做主分片)

 

}
}]
}'

遇到几百个分片未分配的情况就不可能一条条手动执行了,我写了一个执行脚本仅供参考

#!/bin/bash
# batch assign shards
address="http://10.3.69.137:9200"
nodenum=24
curl -XPOST ''$address'/_cat/shards' | grep UNASSIGNED > sourceFile
count=1
offset=0
node=0
cat sourceFile | while read line
do
    echo "Line $count: $line"
    count=$[ $count + 1 ]
    for token in $line
    do
        offset=$[ $offset + 1 ]
        case "$offset" in
        1) index=$token;;
        2) shard=$token;;
        3) primary=$token;;
        esac
    done
    offset=0
    num1=$(( $node % $nodenum + 1 ))
    echo $num1
    num2=` printf "%03d" $num1`
    nodename=node$num2

    if [ $primary = "p"]
    then
        node=$[ $node + 1 ]
        curl -XPOST ''$address'/_cluster/reroute' -d '{"commands":[{"allocate":{"index":"'$index'","shard":'$shard',"node":"'$nodename'","allow_primary" : true }}]}'
    fi
done

该脚本使用者需要修改的参数是

  • address:填写自己的ip:port;
  • nodenum: 集群节点的个数

参考:https://www.cnblogs.com/sunny3096/articles/7155044.html

ES相同请求多次结果不同

如果请求的结果安装timestamp排序,两个文档的timestamp值相同,由于请求是随机去主分片或者副本的结果的,不能保证主分片和副本返回的这两个文档的排序一致,因此会导致相同请求多次结果不一致问题。这就是Bouncing Results问题。参考https://www.elastic.co/guide/en/elasticsearch/guide/master/_search_options.html

要解决这个问题需要在查询url中加preference参数,参考
https://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-preference.html

大集群重启

集群节点临时重启
当修改配置时可能需要重启集群才生效,或者集群发生严重错误无法恢复时都可能需要重启集群
一个集群节点重启前要先临时禁用自动分配,设置cluster.routing.allocation.enable为none,否则节点停止后,当前节点的分片会自动分配到其他节点上,本节点启动后需要等其他节点RECOVERING后才会RELOCATING,也就是分片在其他节点恢复后又转移回来,浪费大量时间
首先禁用自动分配
curl -XPUT http://127.0.0.1:9200/_cluster/settings -d ‘{
“transient” : {
“cluster.routing.allocation.enable” : “none”
}
}’
然后再重启集群
集群启动后再改回配置
curl -XPUT http://127.0.0.1:9200/_cluster/settings -d ‘{
“transient” : {
“cluster.routing.allocation.enable” : “all”
}
}’

#切换ES使用的netty版本

// 切换netty3
./bin/elasticsearch -Ehttp.type=netty3

猜你喜欢

转载自blog.csdn.net/qqqq0199181/article/details/82259440