ElasticSearch 運維

ES 集群升級或維護

  1. 當把 elasticsearch 版本從 2.0.0 升級到 2.1.1 的時候,客戶端完全不可用,接口變化了,因此在升級的時候,需要客戶端也升級

  2. 重啟整個 elasticsearch 集群之前,需要把副本關閉掉,然后在集群其中成功之后,再開啟副本功能

  3. 重啟單個 data 節點需要做以下操作,但是這個只針對冷索引

    • 暫停數據寫入程序

    • 關閉集群shard allocation

    • 手動執行POST /_flush/synced

    • 重啟節點

    • 重新開啟集群shard allocation

    • 等待recovery完成,集群health status變成green

    • 重新開啟數據寫入程序

  4. 刪除磁盤上的數據的話,會引起 shard 數據變成默認值,因為只有在初始化的時候才會設置,所以刪除后,手工進行初始化即可

    • 停止所有的 ES 節點

    • 停止客戶端的數據寫入

    • 啟動所有的 ES 節點

    • 初始化 shard 數

    • 啟動客戶端的數據寫入

      // 手動初始化 template
      
      http://ip/_plugin/kopf/#!/indexTemplates
      
      "template": "trace*",
        "settings": {
          "index": {
            "number_of_shards": "3",
            "number_of_replicas": "1"
          }
        },
        "mappings": {
          "test": {
            "_source": {
              "includes": [
                "traceId"
              ]
            },
            "properties": {
              "traceId": {
                "type": "string"
              },
              "binaryAnnotations": {
                "search_analyzer": "linieAnalzyer",
                "analyzer": "linieAnalzyer",
                "index": "analyzed",
                "type": "string"
              },
              "app": {
                "index": "not_analyzed",
                "type": "string"
              },
              "duration": {
                "type": "long"
              },
              "suc": {
                "type": "string"
              },
              "bizAnnotations": {
                "index": "not_analyzed",
                "type": "string"
              },
              "host": {
                "index": "not_analyzed",
                "type": "string"
              },
              "id": {
                "type": "string"
              },
              "serviceId": {
                "index": "not_analyzed",
                "type": "string"
              },
              "spanName": {
                "type": "string"
              },
              "timestamp": {
                "type": "long"
              }
            }
          }
        },
        "aliases": {
      
        }
  5. 停止 data 節點,shard 分配時間恢復,集群數據量大概是 1.26TB

    • 停止1個節點,恢復時間大概是20分鐘

    • 停止2個節點,恢復時間大概是55分鐘

    • 停止3個節點,恢復時間大概是100分鐘

    • 停止5個節點,恢復時間大概是120分鐘

ElasticSearch 使用經驗

  1. ES_HEAP_SIZE 使用不要超過物理內存的一半,最好不要超過 30.5 G

  2. 設置 vm.swappiness = 1

  3. 在 elasticsearch.yml 中設置 bootstrap.mlockall: true

  4. 官方推薦垃圾回收算法針對 ES 應該設置 CMS

  5. search 的 theadpool 推薦設置為 cores * 3,其他線程池推薦和 cores 數量相等

  6. disk I/O 的線程是有 Lucene 處理的,而不是 ES

  7. 設置 vm.max_map_count=262144 用于 mmapped files 的虛擬內存

  8. 修改配置請使用 API,API,API,而不是修改配置,修改 API 有兩種方式,一種臨時的,一種持久的,臨時的修改當節點下次重啟的時候會失效,永久的當下次重啟的時候會覆蓋靜態配置

    curl -XPUT ip:9200/_cluster/settings -d
    '{
        "transient": {
            "logger.discover": "DEBUG" 
        }
        "persistent": {
            "discovery.zen.minimum_master_nodes": 2
        }
    }'
  9. 設置 slowlog 的閥值有利于定位問題,可以設置 queries, fetches, indexing 的 slowlog

  10. 如果你的集群是偏重于 indexing,而對 search 的性能要求不是毫秒級別的返回,可以做些設置做平衡。

11. Bulk size 比 documents 數量重要,比如 5-15 MB 每個 bulk

12. 磁盤,首選 SSD,沒有 SSD 的話,可以使用RAID0

13. path.data 配置多個路徑

14. 避免 segment merging ,當發生的時候, ES 會自動 throttle index 請求到單個線程,當你使用 SSD 的時候,默認的限制 20MB/s 太小了,可以設置成 100-200MB/s

15. 如果在做一個大的 bulk import,可以設置 index.number_of_replicas:0,等到插入完成的時候,再進行 replicas

16. 在升級或者做其他維護需要重啟服務器的時候,請保持 ES master 節點是可用的,然后一臺臺重啟 data 節點,最好是可以通過 api 先禁止 shard 分配,如果可以停止 indexing 新數據最好(但是這是不可能的)

  • 執行命令禁止 allocation

    PUT /_cluster/settings
    {
        "transient": {
            "cluster.routing.allocation.enable": "none" 
        }
    }
  • 使用 shutdown api 停止一個節點

    POST /_cluster/nodes/_local/_shutdown
  • 執行升級或者維護

  • 重啟節點,確認加入了集群

  • 啟動 shard allocation

    PUT /_cluster/settings
    {
        "transient": {
            "cluster.routing.allocation.enable": "all" 
        }
    }
  • 其他節點重復1到5步驟

17. 使用 snapshot API 備份,建議備份到 HDFS 中,然后使用 _restore API 來恢復備份。

18. 通過設置 action.disable_delete_all_indices: true. 來禁止通過 API 刪除所有索引

19. indices.fielddata.cache.size: 25% ,在 datanode 設置 indices.cluster.send_refresh_mapping: false

20. cluster.routing.allocation.cluster_concurrent_rebalance:2 最好設置低一些,這樣不會影響索引

21. cluster.routing.allocation.disk.threshold_enabled:true
cluster.routing.allocation.disk.watermark.low:.97
cluster.routing.allocation.disk.watermark.high:.99
22. 恢復: cluster.routing.allocation.node_concurrent_recoveries:4
cluster.routing.allocation.node_initial_primaries_recoveries:18
indices.recovery.concurrent_streams: 4
indices.recovery.max_bytes_per_sec: 40mb

23. 避免數據丟失和 _bulk 的重試 threadpool.bulk.queue_size: 3000

監控

  1. zabbix 監控 - https://github.com/ejimz/Elasticsearch-zabbix

  2. 插件監控 - https://github.com/AIsaac08/bigdesk

  3. 需要監控的 10 個數據 - http://radar.oreilly.com/2015/04/10-elasticsearch-metrics-to-watch.html

目前使用的是插件監控方式,主要是以下三個插件

  • bigdesk

  • kopf

  • head

這些里面 kopf 目前最好用,bigdesk 從 es 1.x 版本后就不更新了,所以目前 2.x 版本的部分圖表無法出來

來自: http://segmentfault.com/a/1190000004325032

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!