Elasticsearch(二)- 索引-分片过滤器与延迟再分配

索引分片分配

目的: 索引的分片根据节点的一些属性来分配到不同的节点;

分片过滤器

设置规则:

  • index.routing.allocation.include.{attribute}
    Assign the index to a node whose {attribute} has at least one of the comma-separated values.
  • index.routing.allocation.require.{attribute}
    Assign the index to a node whose {attribute} has all of the comma-separated values.
  • index.routing.allocation.exclude.{attribute}
    Assign the index to a node whose {attribute} has none of the comma-separated values.

自定义属性:

node.attr.size: medium

设置示例:

curl -X PUT "localhost:9200/test/_settings?pretty" -H 'Content-Type: application/json' -d'
{
"index.routing.allocation.include.size": "big,medium"
}
'

以上设置将test索引的分片分配到设置了big,medium属性的节点.

自身属性:
_name
_host_ip
_publish_ip
_ip
_host
_id
_tier

使用示例:

curl -X PUT "localhost:9200/test/_settings?pretty" -H 'Content-Type: application/json' -d'
{
  "index.routing.allocation.include._ip": "192.168.2.*"
}
'

节点断开后, 延迟再分配

当一个节点离开集群, 主节点需要进行分片再分配, 步骤如下:
● 将副分片提升为主分片, 替换 不可用节点 上的所有主分片.
● 分配副分片, 替换不可用节点上丢失的副分片.
● 在剩余的节点上均匀的重新分配分片.

这种分片重新分配会给集群带来大量的额外负载, 假设有如下场景:

● 节点5失去了网络连接.
● master节点将节点5上的 主分片对应的副分片提升为主分片.
● master节点在可用的数据节点上重新分配副分片.
● 每个新的副分片都跨网络生成主分片的完整副本.
● 更多的分片被移动, 以重新平衡集群.
● 此时, 如果节点5 的网络恢复了.
● master节点需要重新分配分片来保证集群平衡.

可以通过index.unassigned.node_left.delayed_timeout 该参数来动态设置再分派的延迟时间, 默认1m.
示例:

curl -X PUT "localhost:9200/_all/_settings?pretty" -H 'Content-Type: application/json' -d'
{
  "settings": {
    "index.unassigned.node_left.delayed_timeout": "5m"
  }
}
'

设置分片恢复优先级

index.priority

示例:

curl -X PUT "localhost:9200/index_4/_settings?pretty" -H 'Content-Type: application/json' -d'
{
  "index.priority": 1
}
'

设置冷热数据层

● 内容层节点:处理诸如产品目录之类的内容的索引和查询负载。
● 热层节点:处理诸如日志或指标之类的时间序列数据的索引负载,并保存您最近,最常访问的数据。
● 暖层节点:保存的时间序列数据访问频率较低,并且很少需要更新。
● 冷层节点:保存时间序列数据,这些数据偶尔会被访问,并且通常不会更新。

在elasticsearch.yml中配置.

node.roles: ["data_hot", "data_content"]

默认将index.routing.allocation.include._tier_preference 设置为data_content;

索引操作限制

  • index.blocks.read_only: 设置为true , 表示索引元数据和索引可读; 否则为允许写入.
  • index.blocks.read_only_allow_delete: 除了read_only之外 , 允许删除索引.
  • index.blocks.read: 除了read_only之外 , 允许删除索引.
  • index.blocks.write: 除了read_only之外 , 允许删除索引.
  • index.blocks.metadata: 除了read_only之外 , 允许删除索引.

开启慢查询日志

{
  // 查询时间大于10s, 打印一个warn类型的日志
  "index.search.slowlog.threshold.query.warn": "10s",
  // 查询时间大于5m, 打印一个info级别的日志
  "index.search.slowlog.threshold.query.info": "5s",
  "index.search.slowlog.threshold.query.debug": "2s",
  "index.search.slowlog.threshold.query.trace": "500ms",
  "index.search.slowlog.threshold.fetch.warn": "1s",
  "index.search.slowlog.threshold.fetch.info": "800ms",
  "index.search.slowlog.threshold.fetch.debug": "500ms",
  "index.search.slowlog.threshold.fetch.trace": "200ms"
}

示例:

curl -X PUT "localhost:9200/my-index-000001/_settings?pretty" -H 'Content-Type: application/json' -d'
{
  "index.search.slowlog.threshold.query.warn": "10s",
  "index.search.slowlog.threshold.query.info": "5s",
  "index.search.slowlog.threshold.query.debug": "2s",
  "index.search.slowlog.threshold.query.trace": "500ms",
  "index.search.slowlog.threshold.fetch.warn": "1s",
  "index.search.slowlog.threshold.fetch.info": "800ms",
  "index.search.slowlog.threshold.fetch.debug": "500ms",
  "index.search.slowlog.threshold.fetch.trace": "200ms"
}
'

数据预加载

示例:

curl -X PUT "localhost:9200/my-index-000001?pretty" -H 'Content-Type: application/json' -d'
{
  "settings": {
    "index.store.preload": ["nvd", "dvd"]
  }
}
'

也可以在elasticsearch.yml中配置.

事务日志文件

es将操作日志记录到translog, 然后通过同步或者异步的方式持久化到磁盘.
● index.translog.sync_interval: 多长时间将translog同步到磁盘并提交一次, 默认5S.
● index.translog.durability: 有两种值: request 和 async;
○ request: 将translog持久化到磁盘之后返回.
○ async: 异步将translog持久化到磁盘.
● index.translog.flush_threshold_size: translog的最大值, 达到该值必须刷新到 Lucene.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一点博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值