资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Elasticsearch运维实战常用命令有哪些

今天就跟大家聊聊有关Elasticsearch运维实战常用命令有哪些,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

目前创新互联已为上1000+的企业提供了网站建设、域名、虚拟空间、网站托管、服务器托管、企业网站设计、鱼台网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

1、集群状态非绿排查清单

 

1.1 集群状态的含义

  • 红色:至少一个主分片未分配成功;
  • 黄色:至少一个副本分片未分配成功;
  • 绿色:全部主&副本都分配成功。
 

1.2 排查实战

 

1.2.1 查看集群状态

GET _cluster/health
 

返回状态举例:"status" : "red", 红色,至少一个主分片未分配成功。

 

1.2.2 到底哪个节点出现了红色或者黄色问题呢?

GET _cluster/health?level=indices
 

如下的方式,更明快直接

GET /_cat/indices?v&health=yellow
GET /_cat/indices?v&health=red
 

找到对应的索引。

 

1.2.3 到底索引的哪个分片出现了红色或者黄色问题呢?

GET _cluster/health?level=shards
   

1.2.4 到底什么原因导致了集群变成红色或者黄色呢?

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分片与节点过滤类型不一致 到此,找到了根本原因,也就知道了对应解决方案。

 

1.3 扩展思考:类似 "current_state" : "unassigned",——未分配 还有哪些?

实战:

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.
   

2、节点间分片移动

适用场景:手动移动分配分片。将启动的分片从一个节点移动到另一节点。

POST /_cluster/reroute
{
  "commands": [
    {
      "move": {
        "index": "indexname",
        "shard": 1,
        "from_node": "nodename",
        "to_node": "nodename"
      }
    }
  ]

   

3、集群节点优雅下线

适用场景:保证集群颜色绿色的前提下,将某个节点优雅下线。

PUT /_cluster/settings
{
  "transient": {
    "cluster.routing.allocation.exclude._ip": "122.5.3.55"
  }
}
   

4、强制刷新

适用场景:刷新索引是确保当前仅存储在事务日志中的所有数据也永久存储在Lucene索引中。

POST /_flush
 

注意:这和 7.6 版本之前的同步刷新(未来8版本+会废弃同步刷新)一致。

POST /_flush/synced
   

5、更改并发分片的数量以平衡集群

适用场景:

控制在集群范围内允许多少并发分片重新平衡。默认值为2。

PUT /_cluster/settings
{
  "transient": {
    "cluster.routing.allocation.cluster_concurrent_rebalance": 2
  }
}
   

6、更改每个节点同时恢复的分片数量

适用场景:

如果节点已从集群断开连接,则其所有分片将都变为未分配状态。经过一定的延迟后,分片将分配到其他位置。每个节点要恢复的并发分片数由该设置确定。

PUT /_cluster/settings
{
  "transient": {
    "cluster.routing.allocation.node_concurrent_recoveries": 6
  }
}
   

7、调整恢复速度

适用场景:

为了避免集群过载,Elasticsearch限制了分配给恢复的速度。你可以仔细更改该设置,以使其恢复更快。

如果此值调的太高,则正在进行的恢复可能会消耗过多的带宽和其他资源,这可能会使集群不稳定。

PUT /_cluster/settings
{
  "transient": {
    "indices.recovery.max_bytes_per_sec": "80mb"
  }
}
   

8、清除节点上的缓存

适用场景:如果节点达到较高的JVM值,则可以在节点级别上调用该API 以使 Elasticsearch 清理缓存。

这会降低性能,但可以使你摆脱OOM(内存不足)的困扰。

POST /_cache/clear
   

9、调整断路器

适用场景:为了避免在Elasticsearch中进入OOM,可以调整断路器上的设置。这将限制搜索内存,并丢弃所有估计消耗比所需级别更多的内存的搜索。

注意:这是一个非常精密的设置,你需要仔细校准。

PUT /_cluster/settings
{
  "persistent": {
    "indices.breaker.total.limit": "40%"
  }
}
   

10、集群迁移

适用场景:集群数据迁移、索引数据迁移等。

 

方案一、 针对索引部分或者全部数据,reindex

Elasticsearch运维实战常用命令有哪些

POST _reindex
{
  "source": {
    "index": "my-index-000001"
  },
  "dest": {
    "index": "my-new-index-000001"
  }
}
   

方案二:借助第三方工具迁移索引或者集群

  • elasticdump
  • elasticsearch-migration

工具本质:scroll + bulk 实现。

 

11、集群数据备份和恢复

适用场景:高可用业务场景,定期增量、全量数据备份,以备应急不时之需。

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运维实战常用命令有哪些有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。


当前名称:Elasticsearch运维实战常用命令有哪些
标题URL:http://cdkjz.cn/article/ijcpjp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220