elasticsearch 常用查询语句
1.查看集群健康状态:curl -u elastic:password -XGET http://localhost:9200/_cluster/health\?pretty #-u:发送亲求时带上账号密码
2.查看所有分片状态:curl -u elastic:password -XGET http://localhost:9200/_cat/shards (显示所有分片状态)
3.查看所有未分配分片:curl -u elastic:password -s "http://localhost:9200/_cat/shards" | grep UNASSIGNED
4.查看master节点的唯一标识:curl -u elastic:password 'localhost:9200/_nodes/process?pretty'
5.执行reroute(分多次,逐个修复 变更shard的值为UNASSIGNED查询结果中编号, 上一步查询结果是/0 1 2 3 4)
inde:需要修复的索引的名字(这里需要修复三个索引)
shard:shard的编号,图中可以看出
node:master节点的唯一标识
curl -u elastic:password -XPOST 'localhost:9200/_cluster/reroute' -d ' { "commands" : [{ "allocate" : { "index" : "k8s-boamp-2019.05.31", "shard" : 3, "node" : "Xp-ARwguQKS3rTETdAxzJA", "allow_primary" : true } }] } '
6.在kibana页面提交请求
常用查询总结:
POST _cluster/reroute?retry_failed #执行 POST _cluster/reroute?retry_failed,分片分配重试,可以重新分配分片,可能需要多执行几次
GET _cluster/health/?pretty #查看集群健康状态
GET _cat/shards #查看所有分片状态
GET _nodes/process?pretty #查看master节点的唯一标识
GET _cat/shards?h=index,shard,unassigned.reason #查看分片不能够进行分配的原因【目前问题出现在标红的两个原因上】
1. INDEX_CREATED Unassigned as a result of an API creation of an index. 索引创建 由于API创建索引而未分配的 2. CLUSTER_RECOVERED Unassigned as a result of a full cluster recovery. 集群恢复 由于整个集群恢复而未分配 3. INDEX_REOPENED Unassigned as a result of opening a closed index. 索引重新打开 4. DANGLING_INDEX_IMPORTED Unassigned as a result of importing a dangling index. 导入危险的索引 5. NEW_INDEX_RESTORED Unassigned as a result of restoring into a new index. 重新恢复一个新索引 6. EXISTING_INDEX_RESTORED Unassigned as a result of restoring into a closed index. 重新恢复一个已关闭的索引 7. REPLICA_ADDED Unassigned as a result of explicit addition of a replica. 添加副本 8. ALLOCATION_FAILED Unassigned as a result of a failed allocation of the shard. 分配分片失败 9. NODE_LEFT Unassigned as a result of the node hosting it leaving the cluster. 集群中节点丢失 10. REROUTE_CANCELLED Unassigned as a result of explicit cancel reroute command. reroute命令取消 11. REINITIALIZED When a shard moves from started back to initializing, for example, with shadow replicas. 重新初始化 12. REALLOCATED_REPLICA A better replica location is identified and causes the existing replica allocation to be cancelled. 重新分配副本
POST _cluster/reroute #修复UNASSIGNED的分片shard【未成功】
{
"commands" : [{
"allocate" : {
"index" : "k8s-boamp-2019.05.31",
"shard" : 3,
"node" : "F1XF02QJTxaWXxvoZ88AaQ",
"allow_primary" : true
}
}]
}
#获取模板属性
GET _template/bbh-game
#修改模板属性
PUT _template/bbh-game
{
"index_patterns": ["bbh-game*"],
"order" : 0,
"settings": {
"number_of_shards": "3",
"number_of_replicas" : "1"
}
}
#修改分片副本数量
PUT _settings
{"number_of_replicas" : "1"}
一些事情一直在干,说不定以后就结果了呢
本文来自博客园,作者:chenjianwen,转载请注明原文链接:https://www.cnblogs.com/chenjw-note/articles/10955519.html