elasticsearch數據冷熱分離、數據冷備


環境:

6個es節點 冷熱配置

es1 master節點

# elasticsearch.yml
node.name: "es1"
cluster.name: "docker-cluster"
network.host: 0.0.0.0
node.master: true
node.data: false

es2、es3、es4 熱數據節點

# elasticsearch.yml
node.name: "es2" # 提示:自行修改其他節點的名稱
cluster.name: "docker-cluster"
network.host: 0.0.0.0
node.master: false
node.data: true
discovery.zen.ping.unicast.hosts: ["es1"]
node.attr.box_type: "hot"  # 標識為熱數據節點

es5、es6 冷數據節點

# elasticsearch.yml
node.name: "es5-cool" # 提示:自行修改其他節點的名稱
cluster.name: "docker-cluster" 
network.host: 0.0.0.0 
node.master: false 
node.data: true 
discovery.zen.ping.unicast.hosts: ["es1"] 
node.attr.box_type: "cool" # 標識為熱數據節點

思路:

  1. 創建index模板,指定"index.routing.allocation.require.box_type"為"hot"。新建立的index默認放置在熱數據節點中存儲。
  2. 修改index中"index.routing.allocation.require.box_type"為"cool",讓ES自動遷移數據到冷數據節點中存儲。

創建index模板:

PUT /_template/hot_template
{
    "index_patterns" : "*", # 匹配所有的索引
    "order" : 0, # 多個模板同時匹配,以order順序倒排,order越大,優先級越高
    "settings" : {
        "number_of_shards" : 2, 
        "index.routing.allocation.require.box_type": "hot", # 指定默認為熱數據節點
        "number_of_replicas": 1     
    }
}

提示:如果不想創建index模板,可以在創建index時在setting中指定 "index.routing.allocation.require.box_type": "hot" 配置,效果相同。

創建測試index:

POST /test_index/test
{
  "test": "test"
}

查看測試index的settings信息:

GET test_index/_settings
回顯如下:
{
  "test_index" : {
    "settings" : {
      "index" : {
        "routing" : {
          "allocation" : {
            "require" : {
              "box_type" : "hot" # 默認index模板匹配成功,數據存放在熱數據節點
            }
          }
        },
        "number_of_shards" : "2",
        "provided_name" : "test_index",
        "creation_date" : "1553160622469",
        "number_of_replicas" : "1",
        "uuid" : "1q0SM1znRUKknJV6N8iJDQ",
        "version" : {
          "created" : "6060199"
        }
      }
    }
  }
}

數據遷移:

PUT test_index/_settings
{
   "settings": {
     "index.routing.allocation.require.box_type": "cool"  # 指定數據存放到冷數據節點
   }
}

 ES會自動將 test_index 的數據遷移到冷數據節點上。

提示:更新索引標記的任務可以放到定時任務中去實現。

 

1. 有x台機器tag設置為hot
2. 有y台機器tag設置為cool
3. hot集群中只存最近兩天的.
4. 有一個定時任務每天將前一天的索引標記為cool
5. es看到有新的標記就會將這個索引遷移到冷集群中, 這都是es自動完成的

參考:

https://elasticsearch.cn/article/6127

https://elasticsearch.cn/question/283

數據冷備:

參考:https://www.elastic.co/guide/cn/elasticsearch/guide/current/backing-up-your-cluster.html

PUT _snapshot/my_backup  # my_backup 備份的名稱
{
    "type": "fs", 
    "settings": {
        "location": "/mount/backups/my_backup" 
    }
}

ES一旦數據被刪除無法通過translog進行數據恢復,所以一定要進行數據冷備。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM