ES common commands and precautions

Modify the es configuration file:

sed -i 's/\<120s\>/300s/g' /opt/elasticsearch/config/elasticsearch.yml

s/\<120s\>/300s/g 为完全匹配才会替换,但要注意唯一性

vim编辑器中亦常用
:%s/\<old\>/new/g

kill the es process

ps -ef|grep elasticsearch|grep -v grep|awk '{print $2}'|xargs kill -9
除了kill,可以用页面--action--关停,这种方式更好一些

Turn off automatic allocation (restart is first off)

curl -XPUT 192.168.14.161:9200/_cluster/settings -d'{
  "transient": {
  "cluster.routing.allocation.enable": "none"
       }
}'

ES start

/opt/elasticsearch/bin/elasticsearch -d

Enable automatic allocation (on after most nodes come online)

curl -XPUT 192.168.14.148:9200/_cluster/settings -d'{
     "transient": {
         "cluster.routing.allocation.enable": "all"
     }
 }'

Failed node retry, refresh es (used after all nodes are online)

curl -XPOST '192.168.14.148:9200/_cluster/reroute?retry_failed'

View settings

curl -XGET '192.168.14.161:9200/_settings?pretty' 
curl -XPUT "192.168.14.161:9200/_cluster/settings 

" -d '{
    "persistent" : {
        "indices.recovery.max_bytes_per_sec" : "40mb"
    }
}'

Set the number of shard replicas

curl -XPUT "http://192.168.14.161:9200/_settings " -d' { "number_of_replicas" : 1 } '

View delayed_timeout

curl -s '192.168.14.161:9200/_all/_settings ' | grep delayed_timeout --color

set delayed_timeout

curl -XPUT "192.168.14.161:9200/_all/_settings 

" -d '{
"settings": {
"index.unassigned.node_left.delayed_timeout": "5m"
    }
}'

View the number of shards for UNASSIGNED

curl -s '192.168.14.161:9200/_cat/shards ' | grep UNASSIGNED

View details of UNASSIGNED shards

curl -XGET 192.168.14.161:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason| grep UNASSIGNED

View the value of node

curl '192.168.14.161:9200/_nodes/process?pretty

Repair unassinged shards (it is recommended to try the retry_failed command and restart the cluster if the problem is not resolved)

curl -XPOST '192.168.14.161:9200/_cluster/reroute' -d '{
        "commands" : [ {
              "allocate" : {
                  "index" : "skynet_public_content_v6",
                  "shard" : 16,
                  "node" : "lH7pzwfTQQOezWDgTtDxpg",
                  "allow_primary" : true
              }
            }
        ]
    }'

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326038774&siteId=291194637