Elasticsearch運(yùn)維實(shí)戰(zhàn)常用命令有哪些

今天就跟大家聊聊有關(guān)Elasticsearch運(yùn)維實(shí)戰(zhàn)常用命令有哪些,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

目前創(chuàng)新互聯(lián)已為上1000+的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、網(wǎng)站托管、服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計(jì)、魚臺網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

1、集群狀態(tài)非綠排查清單

 

1.1 集群狀態(tài)的含義

  • 紅色:至少一個主分片未分配成功;
  • 黃色:至少一個副本分片未分配成功;
  • 綠色:全部主&副本都分配成功。
 

1.2 排查實(shí)戰(zhàn)

 

1.2.1 查看集群狀態(tài)

GET _cluster/health
 

返回狀態(tài)舉例:"status" : "red", 紅色,至少一個主分片未分配成功。

 

1.2.2 到底哪個節(jié)點(diǎn)出現(xiàn)了紅色或者黃色問題呢?

GET _cluster/health?level=indices
 

如下的方式,更明快直接

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

找到對應(yīng)的索引。

 

1.2.3 到底索引的哪個分片出現(xiàn)了紅色或者黃色問題呢?

GET _cluster/health?level=shards
   

1.2.4 到底什么原因?qū)е铝思鹤兂杉t色或者黃色呢?

GET _cluster/allocation/explain
 

返回核心信息解讀舉例:

"current_state" : "unassigned",——未分配
  "unassigned_info" : {
    "reason" : "INDEX_CREATED",——原因,索引創(chuàng)建階段
    "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分片與節(jié)點(diǎn)過濾類型不一致 到此,找到了根本原因,也就知道了對應(yīng)解決方案。

 

1.3 擴(kuò)展思考:類似 "current_state" : "unassigned",——未分配 還有哪些?

實(shí)戰(zhàn):

GET _cat/shards?h=index,shard,prirep,state,unassigned.reason
 

官網(wǎng):https://www.elastic.co/guide/en/elasticsearch/reference/7.2/cat-shards.html

未分配狀態(tài)及原因解讀:

(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、節(jié)點(diǎn)間分片移動

適用場景:手動移動分配分片。將啟動的分片從一個節(jié)點(diǎn)移動到另一節(jié)點(diǎn)。

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

   

3、集群節(jié)點(diǎn)優(yōu)雅下線

適用場景:保證集群顏色綠色的前提下,將某個節(jié)點(diǎn)優(yōu)雅下線。

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

4、強(qiáng)制刷新

適用場景:刷新索引是確保當(dāng)前僅存儲在事務(wù)日志中的所有數(shù)據(jù)也永久存儲在Lucene索引中。

POST /_flush
 

注意:這和 7.6 版本之前的同步刷新(未來8版本+會廢棄同步刷新)一致。

POST /_flush/synced
   

5、更改并發(fā)分片的數(shù)量以平衡集群

適用場景:

控制在集群范圍內(nèi)允許多少并發(fā)分片重新平衡。默認(rèn)值為2。

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

6、更改每個節(jié)點(diǎn)同時恢復(fù)的分片數(shù)量

適用場景:

如果節(jié)點(diǎn)已從集群斷開連接,則其所有分片將都變?yōu)槲捶峙錉顟B(tài)。經(jīng)過一定的延遲后,分片將分配到其他位置。每個節(jié)點(diǎn)要恢復(fù)的并發(fā)分片數(shù)由該設(shè)置確定。

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

7、調(diào)整恢復(fù)速度

適用場景:

為了避免集群過載,Elasticsearch限制了分配給恢復(fù)的速度。你可以仔細(xì)更改該設(shè)置,以使其恢復(fù)更快。

如果此值調(diào)的太高,則正在進(jìn)行的恢復(fù)可能會消耗過多的帶寬和其他資源,這可能會使集群不穩(wěn)定。

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

8、清除節(jié)點(diǎn)上的緩存

適用場景:如果節(jié)點(diǎn)達(dá)到較高的JVM值,則可以在節(jié)點(diǎn)級別上調(diào)用該API 以使 Elasticsearch 清理緩存。

這會降低性能,但可以使你擺脫OOM(內(nèi)存不足)的困擾。

POST /_cache/clear
   

9、調(diào)整斷路器

適用場景:為了避免在Elasticsearch中進(jìn)入OOM,可以調(diào)整斷路器上的設(shè)置。這將限制搜索內(nèi)存,并丟棄所有估計(jì)消耗比所需級別更多的內(nèi)存的搜索。

注意:這是一個非常精密的設(shè)置,你需要仔細(xì)校準(zhǔn)。

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

10、集群遷移

適用場景:集群數(shù)據(jù)遷移、索引數(shù)據(jù)遷移等。

 

方案一、 針對索引部分或者全部數(shù)據(jù),reindex

Elasticsearch運(yùn)維實(shí)戰(zhàn)常用命令有哪些

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

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

  • elasticdump
  • elasticsearch-migration

工具本質(zhì):scroll + bulk 實(shí)現(xiàn)。

 

11、集群數(shù)據(jù)備份和恢復(fù)

適用場景:高可用業(yè)務(wù)場景,定期增量、全量數(shù)據(jù)備份,以備應(yīng)急不時之需。

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
   

看完上述內(nèi)容,你們對Elasticsearch運(yùn)維實(shí)戰(zhàn)常用命令有哪些有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

文章名稱:Elasticsearch運(yùn)維實(shí)戰(zhàn)常用命令有哪些
文章起源:http://www.muchs.cn/article28/ijcpjp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、商城網(wǎng)站、網(wǎng)站導(dǎo)航、標(biāo)簽優(yōu)化、虛擬主機(jī)、響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)