elasticsearch unassigned shard 解决方法

张映 发表于 2021-02-05

分类目录: elasticsearch

标签:, ,

elasticsearch出现unassigned的分片,导致kibana和elasticsearch-head现黄色。

# curl -XGET 'http://localhost:9200/_cluster/allocation/explain?pretty'

。。。。。。。。。。。。。。。。。。。。。。。。。省略。。。。。。。。。。。。。。。。。。。。。。。。。。

      "deciders" : [
        {
          "decider" : "node_version",
          "decision" : "NO",
          "explanation" : "cannot allocate replica shard to a node with version [6.8.12] since this is older than the primary version [6.8.13]"
        }
      ]
    }
  ]
}

集群中elasticsearch的版本不一样,导致分片出错。版本升级成一至的就好了。

下面有自己实践的,也有些网上找的。主要是关于分片和集群这块的api接口demo

//查看所有分片状态
# curl -s "http://localhost:19200/_cat/shards"

///获取当前master信息
# curl -XGET "http://localhost:9200/_cat/master?v"

//获取节点信息
# curl -XGET "http://localhost:9200/_cat/nodes?format=json&pretty"

//获取索引信息
# curl -XGET "http://localhost:9200/_cat/indices?format=json&pretty"

//查看集群节点状态
# curl -XGET "http://localhost:9200/_cluster/state/nodes?format=json&pretty"

//集群统计
# curl -XGET "http://localhost:9200/_cluster/stats?format=json&pretty"

//集群配置信息
# curl -XGET "http://localhost:9200/_cluster/settings?format=json&pretty"

//查看集群健康状态
# curl -XGET 'http://localhost:19200/_cluster/health?level=indices;pretty=true'

//查看节点信息
# curl -XGET "http://localhost:9200/_cat/nodes?format=json&pretty"

//查看某一索引分片
# curl -XGET 'http://localhost:9200/.monitoring-es-6-2021.02.04/_search_shards?pretty'

//查看所有索引状态
# curl -XGET 'http://127.0.0.1:9200/_cat/indices?v'

//某个索引的配置
# curl -XGET 'http://localhost:9200/.monitoring-es-6-2021.02.04/_settings?pretty'

//分片重新分配给节点:
# curl -H "Content-Type: application/json"  -XPOST 'http://localhost:9200/_cluster/reroute' -d '{
         "commands" : [ {
               "allocate" : {
                   "index" : ".monitoring-es-6-2021.02.04",  #index名称
                   "shard" : 0,    #分片序号,不是总数
                   "node" : "_r-lsF2hQ9GX7zr5CDfs2Q",  # nodeid
                   "allow_primary" : true
               }
             }
         ]
     }'

//修改硬盘配置:
# curl -XPUT localhost:9200/_cluster/settings -d '{
  "persistent": {
    "cluster.routing.allocation.disk.watermark.low": "90%",
    "cluster.routing.allocation.disk.watermark.high": "90%",
    "cluster.routing.allocation.disk.watermark.flood_stage": "95%",
    "cluster.info.update.interval": "1m"
    }
}'

//关闭索引块自动释放
# curl -XPUT 'localhost:9200/_cluster/settings' -d '{
	"index.blocks.read_only_allow_delete": null
}'

//启动用分片动态分配
# curl -XPUT 'localhost:9200/_cluster/settings' -d '{
    "transient" : {
        "cluster.routing.allocation.enable" : "all"
    }
}'

//允许自动分配
# curl -XPUT 'localhost:9200/_settings' -d '{
    "index.routing.allocation.disable_allocation": false
}'

//允许test索引自动分配
# curl -XPUT 'localhost:9200/test/_settings' -d '{
    "index.routing.allocation.disable_allocation": false
}'

//分片移动
# curl -H "Content-Type: application/json"  -XPOST 'localhost:9200/_cluster/reroute?pretty -d '{
    "commands" : [
        {
            "move" : {
                "index" : "test",
                "shard" : 1,
                "from_node" : "10.0.40.237_9200",
                "to_node" : "10.0.40.200_9200"
            }
        }
    ]
}'

//分配主分片,有可能部门数据丢失
# curl -H "Content-Type: application/json"  -XPOST 'localhost:9200/_cluster/reroute?pretty -d '{
    "commands" : [ {
        "allocate_stale_primary" :
            {
              "index" : "test",
              "shard" : 1,
              "node" : "10.0.40.200_9200",
              "accept_data_loss" : true
            }
        }
    ]
}'

//分配空分片
# curl -H "Content-Type: application/json"  -XPOST 'localhost:9200/_cluster/reroute?pretty -d '{
    "commands" : [ {
        "allocate_empty_primary" :
            {
              "index" : "test",
              "shard" : 1,
              "node" : "10.0.40.200_9200",
              "accept_data_loss" : true
            }
        }
    ]
}'

# 不带过滤参数,默认显示所有节点信息
GET /_nodes
# 获取所有节点信息
GET /_nodes/_all
# 获取当前节点信息
GET /_nodes/_local
# 获取master节点信息
GET /_nodes/_master
# 以主机名作为条件过滤节点,或者使用通配符匹配节点
GET /_nodes/node_name_goes_here
GET /_nodes/node_name_goes_*
# 可以使用IP地址加通配符过滤节点
GET /_nodes/10.0.0.3,10.0.0.4
GET /_nodes/10.0.0.*
# 以role作为过滤条件
GET /_nodes/_all,master:false
GET /_nodes/data:true,ingest:true
GET /_nodes/coordinating_only:true
# 根据elasticsearch.yml文件定义的node.attr.rack属性过滤节点,例如`node.attr.rack: 2`
GET /_nodes/rack:2
GET /_nodes/ra*:2
GET /_nodes/ra*:2*

 



转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/elasticsearch/2498.html