您好,登录后才能下订单哦!
今天就跟大家聊聊有关Elasticsearch运维实战常用命令有哪些,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
GET _cluster/health
返回状态举例:"status" : "red", 红色,至少一个主分片未分配成功。
GET _cluster/health?level=indices
如下的方式,更明快直接
GET /_cat/indices?v&health=yellow
GET /_cat/indices?v&health=red
找到对应的索引。
GET _cluster/health?level=shards
GET _cluster/allocation/explain
返回核心信息解读举例:
"current_state" : "unassigned",——未分配
"unassigned_info" : {
"reason" : "INDEX_CREATED",——原因,索引创建阶段
"at" : "2020-01-29T07:32:39.041Z",
"last_allocation_status" : "no"
},
"explanation" : """node does not match index setting [index.routing.allocation.require] filters [box_type:"hot"]"""
}
根本原因,shard分片与节点过滤类型不一致 到此,找到了根本原因,也就知道了对应解决方案。
实战:
GET _cat/shards?h=index,shard,prirep,state,unassigned.reason
官网:https://www.elastic.co/guide/en/elasticsearch/reference/7.2/cat-shards.html
未分配状态及原因解读:
(1)INDEX_CREATED
Unassigned as a result of an API creation of an index.
(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.
(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
{
"commands": [
{
"move": {
"index": "indexname",
"shard": 1,
"from_node": "nodename",
"to_node": "nodename"
}
}
]
}
适用场景:保证集群颜色绿色的前提下,将某个节点优雅下线。
PUT /_cluster/settings
{
"transient": {
"cluster.routing.allocation.exclude._ip": "122.5.3.55"
}
}
适用场景:刷新索引是确保当前仅存储在事务日志中的所有数据也永久存储在Lucene索引中。
POST /_flush
注意:这和 7.6 版本之前的同步刷新(未来8版本+会废弃同步刷新)一致。
POST /_flush/synced
适用场景:
控制在集群范围内允许多少并发分片重新平衡。默认值为2。
PUT /_cluster/settings
{
"transient": {
"cluster.routing.allocation.cluster_concurrent_rebalance": 2
}
}
适用场景:
如果节点已从集群断开连接,则其所有分片将都变为未分配状态。经过一定的延迟后,分片将分配到其他位置。每个节点要恢复的并发分片数由该设置确定。
PUT /_cluster/settings
{
"transient": {
"cluster.routing.allocation.node_concurrent_recoveries": 6
}
}
适用场景:
为了避免集群过载,Elasticsearch限制了分配给恢复的速度。你可以仔细更改该设置,以使其恢复更快。
如果此值调的太高,则正在进行的恢复可能会消耗过多的带宽和其他资源,这可能会使集群不稳定。
PUT /_cluster/settings
{
"transient": {
"indices.recovery.max_bytes_per_sec": "80mb"
}
}
适用场景:如果节点达到较高的JVM值,则可以在节点级别上调用该API 以使 Elasticsearch 清理缓存。
这会降低性能,但可以使你摆脱OOM(内存不足)的困扰。
POST /_cache/clear
适用场景:为了避免在Elasticsearch中进入OOM,可以调整断路器上的设置。这将限制搜索内存,并丢弃所有估计消耗比所需级别更多的内存的搜索。
注意:这是一个非常精密的设置,你需要仔细校准。
PUT /_cluster/settings
{
"persistent": {
"indices.breaker.total.limit": "40%"
}
}
适用场景:集群数据迁移、索引数据迁移等。
POST _reindex
{
"source": {
"index": "my-index-000001"
},
"dest": {
"index": "my-new-index-000001"
}
}
工具本质:scroll + bulk 实现。
适用场景:高可用业务场景,定期增量、全量数据备份,以备应急不时之需。
PUT /_snapshot/my_backup/snapshot_hamlet_index?wait_for_completion=true
{
"indices": "hamlet_*",
"ignore_unavailable": true,
"include_global_state": false,
"metadata": {
"taken_by": "mingyi",
"taken_because": "backup before upgrading"
}
}
POST /_snapshot/my_backup/snapshot_hamlet_index/_restore
看完上述内容,你们对Elasticsearch运维实战常用命令有哪些有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。