设为首页 收藏本站
查看: 4628|回复: 0

[经验分享] Elasticsearch分片&副本分配

[复制链接]

尚未签到

发表于 2019-1-29 09:11:22 | 显示全部楼层 |阅读模式
  集群索引中可能由多个分片构成,并且每个分片可以拥有多个副本,将一个单独的索引分为多个分片,可以处理不能在单一服务器上运行的
  大型索引.
  由于每个分片有多个副本,通过副本分配到多个服务器,可以提高查询的负载能力.
  为了进行分片和副本操作,需要确定将这些分片和副本放到集群节点的哪个位置,需要确定把每个分片和副本分配到哪台服务器/节点上.
  1.索引创建&指定节点参数:
  $curl -XPOST 'http://localhost:9200/filebeate-ali-hk-fd-tss1'
  $curl -XPUT 'http://localhost:9200/filebeat-ali-hk-fd-tss1/_settings' -d '{
  "index.routing.allocation.include.zone":"ali-hk-ops-elk1"
  }'
  将索引指定存放在elk1的节点上
  $curl -XPUT 'http://localhost:9200/filebeat-ali-hk-fd-tss1/settings' -d '{
  "index.routing.allocation.include._ip":"ip_addr1,ip_addr2"
  }'
  根据ip地址指定索引的分配节点
  2.排除索引分配的节点:
  $curl -XPOST 'http://localhost:9200/filebeat-ali-hk-fd-tss2'
  $curl -XPUT 'http://localhost:9200/filebeat-ali-hk-fd-tss2/_setting' -d '{
  "index.routing.allocation.exclude.zone":"ali-hk-ops-elk2"
  }'
  $curl -XPUT 'http://localhost:9200/filebeat-ali-hk-fd-tss2/_setting' -d '{
  "index.routing.allocation.exclude._ip":"ip_addr1,ip_addr2"
  }'
  根据ip地址排除索引分配的节点
  3.每个节点上分片和副本数量的控制:
  对一个索引指定每个节点上的最大分片数量:
  $curl -XPUT 'http://localhost:9200/filebeat-ali-hk-fd-tss1/_settings' -d '{
  "index.routing.allocation.total_shards_per_node":1
  }'
  如果配置不当,导致主分片无法分配的话,集群就会处于red状态.
  4.手动移动分片和副本:
  移动分片:
  $curl -XPOST 'http://localhost:9200/_cluster/reroute' -d '{
  "commands":[{
  "move":{
  "index":"filebeat-ali-hk-fd-tss1",
  "shard":1,
  "from_node":"ali-hk-ops-elk1",
  "to_node":"ali-hk-ops-elk2"
  }
  }]
  }'
  取消分片:
  $curl -XPOST 'http://localhost:9200/_cluster/reroute' -d '{
  "commands":[{
  "cancel":{
  "index":"filebeat-ali-hk-fd-tss1",
  "shard":1,
  "node":"ali-hk-ops-elk1"
  }
  }]
  }'
  分配分片:
  $curl -XPOST 'http://localhost:9200/_cluster/reroute' -d '{
  "commands":[{
  "allocate":{
  "index":"filebeat-ali-hk-fd-tss1",
  "shard":1,
  "node":"ali-hk-ops-elk1"
  }
  }]
  }'
  将某个未分配的索引手动分配到某个节点上.
  $curl -XPOST 'http://localhost:9200/_cluster/reroute' -d '{
  "commands":[
  {
  "move":{
  "index":"filebeat-ali-hk-fd-tss1",
  "shard":1,
  "from_node":"ali-hk-ops-elk1",
  "to_node":"ali-hk-ops-elk2"
  }
  },
  {
  "cancel":{
  "index":"filebeat-ali-hk-fd-tss1",
  "shard":1,
  "node":"ali-hk-ops-elk1"
  }
  },
  {
  "allocate":{
  "index":"filebeat-ali-hk-fd-tss1",
  "shard":1,
  "node":"ali-hk-ops-elk1"
  }
  }]
  }'
  5.关于unassigned shards的问题解决:
  1)出现大量的unassigned shards
  2)集群的状态为:red

  集群状态:red-->存在不可用的主分片
  A:fix unassigned shards:
  查看所有分片的状态:
  $curl -XGET 'http://localhost:9200/_cat/shards'
  查询所有unassigned的分片:
  $curl -XGET 'http://localhost:9200/_cat/shards' | grep UNASSIGNED
  B:查询得到master节点的唯一标识:
  $curl -XGET 'http://localhost:9200/_nodes/process?pretty=true'
  C:执行route对unassigned的索引进行手动分片:
  for index in $(curl -XGET 'http://localhost:9200/_cat/shards' | grep UNASSIGNED |awk '{print $1}'|sort |uniq):do
  for shards in $(curl -XGET 'http://localhost:9200/_cat/shards' | grep UNASSIGNED | grep $index | awk '{print $2}'|sort|uniq):do
  curl XPOST 'http://localhost:9200/_cluster/reroute'-d '{
  "commands":[
  {
  "allocate":{
  "index":$index,
  "shards":$shards,
  "node":"ali-k-ops-elk1",
  "allow_primary":"true"
  }
  }
  ]
  }'
  done
  done
  本文出自https://www.cnblogs.com/kasumi/p/6530535.html
elasticsearch-索引分片和副本设置
索引设置
  你可以通过修改配置来自定义索引行为,详细配置参照 {ref}/index-modules.html[索引模块]
  Tip
Elasticsearch 提供了优化好的默认配置。 除非你理解这些配置的作用并且知道为什么要去修改,否则不要随意修改。  下面是两个 最重要的设置:

  •   number_of_shards
  •   每个索引的主分片数,默认值是 5 。这个配置在索引创建后不能修改。
  •   number_of_replicas
  •   每个主分片的副本数,默认值是 1 。对于活动的索引库,这个配置可以随时修改。
  例如,我们可以创建只有 一个主分片,没有副本的小索引:
PUT /my_temp_index  
{    "settings": {        "number_of_shards" :   1,        "number_of_replicas" : 0
  
    }
  
}
  然后,我们可以用 update-index-settings API 动态修改副本数:
PUT /my_temp_index/_settings  
{    "number_of_replicas": 1}
  本文出自https://blog.csdn.net/chuan442616909/article/details/55212251



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-668985-1-1.html 上篇帖子: ELKStack篇(1)——ElasticSearch篇 下篇帖子: Elasticsearch 合理内存分配
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表