集群索引中可能由多个分片构成,并且每个分片可以拥有多个副本,将一个单独的索引分为多个分片,可以处理不能在单一服务器上运行的
大型索引.
由于每个分片有多个副本,通过副本分配到多个服务器,可以提高查询的负载能力.
为了进行分片和副本操作,需要确定将这些分片和副本放到集群节点的哪个位置,需要确定把每个分片和副本分配到哪台服务器/节点上.

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

Elasticsearch分片&副本分配的更多相关文章

  1. 【控制分片分配】控制Elasticsearch分片和副本的分配

    ES集群中索引可能由多个分片构成,并且每个分片可以拥有多个副本.通过将一个单独的索引分为多个分片,我们可以处理不能在一个单一的服务器上面运行的大型索引,简单的说就是索引的大小过大,导致效率问题.不能运 ...

  2. elasticsearch问题解决之分片副本UNASSIGNED

    在上一篇文章中,我记录了在windows下同一台机器上搭建es集群的步骤,第二天在向集群中创建索引的时候,出现了分片副本未分配的情况(UNASSIGNED). 虽然并不影响数据的插入和查询,但是有问题 ...

  3. Elasticsearch 学习之 分片未分配原因

    分片未分配的原因主要有: 1)INDEX_CREATED:由于创建索引的API导致未分配.2)CLUSTER_RECOVERED :由于完全集群恢复导致未分配.3)INDEX_REOPENED :由于 ...

  4. Elasticsearch分片优化

    原文地址:https://qbox.io/blog/optimizing-elasticsearch-how-many-shards-per-index 大多数ElasticSearch用户在创建索引 ...

  5. Elasticsearch 分片集群原理、搭建、与SpringBoot整合

    单机es可以用,没毛病,但是有一点我们需要去注意,就是高可用是需要关注的,一般我们可以把es搭建成集群,2台以上就能成为es集群了.集群不仅可以实现高可用,也能实现海量数据存储的横向扩展. 新的阅读体 ...

  6. mongodb 3.4 集群搭建:分片+副本集

    mongodb是最常用的nodql数据库,在数据库排名中已经上升到了前六.这篇文章介绍如何搭建高可用的mongodb(分片+副本)集群. 在搭建集群之前,需要首先了解几个概念:路由,分片.副本集.配置 ...

  7. mongodb 3.6 集群搭建:分片+副本集

    mongodb是最常用的nosql数据库,在数据库排名中已经上升到了前六.这篇文章介绍如何搭建高可用的mongodb(分片+副本)集群. 在搭建集群之前,需要首先了解几个概念:路由,分片.副本集.配置 ...

  8. mongodb3.6集群搭建:分片+副本集

    mongodb是最常用的noSql数据库,在数据库排名中已经上升到了前五.这篇文章介绍如何搭建高可用的mongodb(分片+副本)集群. 在搭建集群之前,需要首先了解几个概念:路由,分片.副本集.配置 ...

  9. MongoDB在单机上搭建分片副本集群(windows)

    ------------------------------1.安装MongoDB...... ------------------------------2.准备好文件夹 --config:配置文件 ...

随机推荐

  1. 洛谷P1637 三元上升子序列

    P1637 三元上升子序列 48通过 225提交 题目提供者该用户不存在 标签云端 难度提高+/省选- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 为什么超时啊 a的数据比较 ...

  2. 洛谷P2002 消息扩散

    题目背景 本场比赛第一题,给个简单的吧,这 100 分先拿着. 题目描述 有n个城市,中间有单向道路连接,消息会沿着道路扩散,现在给出n个城市及其之间的道路,问至少需要在几个城市发布消息才能让这所有n ...

  3. bzoj1511 [POI2006]OKR-Periods of Words kmp+乱搞

    1511: [POI2006]OKR-Periods of Words Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 351  Solved: 220[S ...

  4. crontab 自动执行脚本

    crontab -e ================>自动执行某脚本!!!!!!! 1001 ls 1002 cd /home/wwwroot/default/ 1003 ls 1004 cr ...

  5. 「Linux」centos7安装mysql

    1.yum仓库下载MySQL:sudo yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch. ...

  6. 二型错误和功效(Type II Errors and Test Power)

    sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005269003&am ...

  7. Bash to check SSL cert expired

    Code like this, You can send out a email to notice $ cat urls.txt www.baidu.com $ cat cert_chk.sh #! ...

  8. SDK代码记录

    zynq中SDK相关API的学习.记录常用函数 /*************************************************************************** ...

  9. What are the advantages of different classification algorithms?

    What are the advantages of different classification algorithms? For instance, if we have large train ...

  10. 你知道吗?Java开发的10位牛人

    James Gosling 1983年,Gosling获得了加州大学的计算机科学学士学位.1990年,他获得了卡内基梅隆大学的计算机科学博士学位,师从Bob Sproull.在攻读博士期间,他自己开发 ...