工作随笔——elasticsearch数据冷热分离、数据冷备

工作随笔——elasticsearch数据冷热分离、数据冷备

概述:

  1. 适合日志类型的数据存储方案。即当日数据写入,历史数据只读。
  2. 节省部分硬件成本。热数据采用更好的硬件。

环境:

已有6个ES节点,使用docker-compose方式搭建。

  es1:master节点

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

  es2、es3、es4 热数据节点

# elasticsearch.ymlnode.name: "es2" # 提示:自行修改其他节点的名称cluster.name: "docker-cluster"network.host: 0.0.0.0node.master: falsenode.data: truediscovery.zen.ping.unicast.hosts: ["es1"]node.attr.box_type: "hot"  # 标识为热数据节点

  es5、es6 冷数据节点

# elasticsearch.ymlnode.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": 0         }}

提示:如果不想创建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" : "0",        "uuid" : "1q0SM1znRUKknJV6N8iJDQ",        "version" : {          "created" : "6060199"        }      }    }  }}

数据迁移:

PUT test_index/_settings{   "settings": {     "index.routing.allocation.require.box_type": "cool"  # 指定数据存放到冷数据节点   }}

ES会自动将 test_index 的数据迁移到冷数据节点上。

参考

https://elasticsearch.cn/article/6127

数据冷备:

参考: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进行数据恢复,所以一定要进行数据冷备。

免责声明:本网信息来自于互联网,目的在于传递更多信息,并不代表本网赞同其观点。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,并请自行核实相关内容。本站不承担此类作品侵权行为的直接责任及连带责任。如若本网有任何内容侵犯您的权益,请及时联系我们,本站将会在24小时内处理完毕。
相关文章
返回顶部