es动态分配分片_常见elasticsearch问题处理方法

1、集群状态查看

通过这两个界面可以看出

1.1如果heap红色,会导致界面查询比较慢. 通常是打开了比较多的索引, 可以在企业版的日志策略中打开自动关闭索 引的功能, 通常是打开7天的索引, 可以根据具体内存情况多打开几天,比如10天或者15天, 不能太多.

1.2.如果cpu和load红色, 会导致界面查询慢, 写入也慢, 对采集器的影响尤其明显, 采集器的日志中会出现超时或者bulk reject错误. 可能原因如下:

a)当天或当前正在大量写入的event索引的分片分布不均,某个节点上分布了比较多的分片,导致该节点压力很大

b)磁盘写入速度太低

c)分片在恢复或者rebalance

d)cpu核数少

e)主机上同时部署了其他消耗cpu资源较多的应用

1.3.如果磁盘使用率达到85%可能导致, 索引分片不能分配到此节点, 导致其他节点压力变大, 集群性能下降

1.4.可以看出节点列表是否缺少节点, 如果少节点, 可能存在下面两种情况:

a)节点进程死掉, 没启动成功

b)集群发生脑裂, 一个大集群变成了多个小集群

5.节点列表里面实心星号的节点是当前的master节点, 需要看ES日志时首先看此节点的日志, 不能发现问题再看其他节点的日志.

2、查看集群参数配置

curl http://localhost:9200/_cluster/settings?pretty

或者直接在浏览器中访问此url

3、防止集群脑裂

设置3个Master Eligible节点:node.master: true

至少看见2个Master Eligible才可组建集群:discovery.zen.minimum_master_nodes:2

配置文件位置/opt/hansight/enterprise/elasticsearch/config/elasticsearch.yml

4、强制event索引分片平均分配到各个节点

比如event索引共6个数据节点, 12个分片1个副本共24个分片, 可以设置每个节点最大分片数为5或者4, 设置为5是为了允许一个节点死掉后还能够正常分配.

a)在event模板中添加"index.routing.allocation.total_shards_per_node":5参数

b)在已有索引上进行设置(可选, 如果集群rebalance开关打开这可能引起分片自动平衡)

curl -XPUT 172.16.106.66:9200/event*/_settings -d '{"index.routing.allocation.total_shards_per_node":5}'

5、ES分片分配不下去

kopf插件显示有未分配的分片但是未显示有多少个分片正在分配,这时说明ES没有在做分片分配操作

通过下面命令查看触发分片分配的原因

curl -XGET localhost:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason| grep UNASSIGNED

查看分片分配不下去的原因

5.X版本可以通过命令查看

curl -XGET localhost:9200/_cluster/allocation/explain?pretty

下图是执行结果, 关注红框框起来的部分即可, 红框中的ip是问题ES节点

2.3.5版本es只能在es的日志中查看分配不下去的原因。

解决办法:

通过下面方式看能否触发分片分配

5.1、点击kopf界面上的锁按钮关闭/打开分片分配或者通过下面命令关闭分片分配再打开,看看能否触发分片开始分配

curl -XPUT http://127.0.0.1:9200/_cluster/settings -d '{"transient" : {"cluster.routing.allocation.enable" : "none"}}'

curl -XPUT http://127.0.0.1:9200/_cluster/settings -d '{"transient" : {"cluster.routing.allocation.enable" : "all"}}'

5.2、(5.6版本ES)使用reroute命令,看看能否触发分片开始分配

curl -XPOST localhost:9200/_cluster/reroute?retry_failed=false

cluster.routing.allocation.total_shards_per_node 集群级别-每个节点最多分配几个分片

index.routing.allocation.total_shards_per_node 索引级别-每个节点最多分配几个分片

cluster.routing.allocation.disk.threshold_enabled 默认true,表示分片分配参考磁盘空间使用率

cluster.routing.allocation.disk.watermark.low 默认85% 表示磁盘使用率超过85%时不再向节点分配新分片(如果集群只有一个节点还是可以分配的)

cluster.routing.allocation.disk.watermark.high 默认90% 表示磁盘使用率超过90%时ES会尝试将分片转移到其他节点

Shard Allocation Filtering参数:

cluster.routing.allocation.include

cluster.routing.allocation.require

cluster.routing.allocation.exclude

index.routing.allocation.include

index.routing.allocation.require

index.routing.allocation.exclude

5.4、如果确认分片数据已损坏或已丢失可以使用强制分配命令将分片分配下去

强制分配分片(会导致数据丢失,慎用)

ES版本号2.3

curl -XPOST 'localhost:9200/_cluster/reroute' -d '

{ "commands" : [ { "allocate" : { "index" : "event_test", "shard" : 0, "node": "node123", "allow_primary": "true" } }] }'

ES版本号5.6版本往上

分配副本分片

curl -XPOST 'localhost:9200/_cluster/reroute' -d '

{

"commands" : [

{

"allocate_replica" : {"index" : "event_test", "shard" : 5, "node" : "node-5"}

}

]

}'

从副本生成一个主分片

curl -XPOST 'localhost:9200/_cluster/reroute' -d '

{

"commands" : [

{

"allocate_stale_primary" : {"index" : "event_test", "shard" : 5, "node" : "node-5", "accept_data_loss":true}

}

]

}'

分配一个空的主分片

curl -XPOST 'localhost:9200/_cluster/reroute' -d '

{

"commands" : [

{

"allocate_empty_primary" : {"index" : "event_test", "shard" : 4, "node" : "node-5", "accept_data_loss":true}

}

]

}'

6、提高分片恢复速度

curl -XPUT localhost:9200/_cluster/settings -d '

{

"persistent" : {

"cluster.routing.allocation.node_concurrent_recoveries": 4,

"indices.recovery.max_bytes_per_sec" : "400mb"

}

}

'

7、做大量分片迁移时提高分片自动平衡的并发数

curl -XPUT localhost:9200/_cluster/settings -d '

{

"persistent" : {

"cluster.routing.allocation.cluster_concurrent_rebalance": 10

}

}

'

8、查看节点bulk reject情况

5.x版本 curl 'localhost:9200/_cat/thread_pool/bulk?v'

2.x版本 curl 'localhost:9200/_cat/thread_pool?v&h=ip,bulk.*'

reject多的节点最可能是磁盘速度或者cpu不够用的节点

9、调整分片分配磁盘参数提高磁盘空间利用率

关闭分片分配磁盘参数

curl -XPUT 'localhost:9200/_cluster/settings' -d '{"persistent": {"cluster.routing.allocation.disk.threshold_enabled":false}}'

或者根据磁盘空间大小和每天日志量调整阀值设置(按空间大小或百分比设置)

curl -XPUT 'localhost:9200/_cluster/settings?pretty' -d '{"persistent": {"cluster.routing.allocation.disk.threshold_enabled":true}}'

curl -XPUT 'localhost:9200/_cluster/settings?pretty' -d '{"persistent": {"cluster.routing.allocation.disk.watermark.low": "500g"}}'

curl -XPUT 'localhost:9200/_cluster/settings?pretty' -d '{"persistent": {"cluster.routing.allocation.disk.watermark.high": "100g"}}'

或者

curl -XPUT 'localhost:9200/_cluster/settings?pretty' -d '{"persistent": {"cluster.routing.allocation.disk.threshold_enabled":true}}'

curl -XPUT 'localhost:9200/_cluster/settings?pretty' -d '{"persistent": {"cluster.routing.allocation.disk.watermark.low": "95%"}}'

curl -XPUT 'localhost:9200/_cluster/settings?pretty' -d '{"persistent": {"cluster.routing.allocation.disk.watermark.high": "98%"}}'

10、设置索引数据刷入file-system-cache的频率为60秒,提高写入性能

新版本此参数已经默认60秒了,3.7版本默认1秒

index settings api针对已存在索引有效,在event的模版中设置此参数对新创建的索引有效。

curl -XPUT 'localhost:9200/event*/_settings' -d '{"index.refresh_interval" : "60s"}'

11、设置索引分片不分配到问题节点

设置event索引不分配到node_205节点(index.routing.allocation.exclude._name)

在event的模版中设置此参数对新创建的索引有效。

下面命令对已创建的索引进行设置,索引名称支持通配符.

curl -XPUT 'localhost:9200/event_20181218/_settings' -d '{"index.routing.allocation.exclude._name": "node_205"}'

设置之后node_205节点上的分片会自动迁移到其他节点(已关闭的索引不会迁移).

设置集群中所有索引都不分配到node_205节点

curl -XPUT 'localhost:9200/_cluster/settings' -d '{"persistent":{"cluster.routing.allocation.exclude._name": "node_205"}}'

设置之后node_205节点上的分片会自动迁移到其他节点

注意: 2.3.5版本的es需要开着自动平衡功能分片才会自动迁移, 5.6.8版本的es开不开自动平衡都会自动迁移.

12、单机部署多实例时避免主/副分片分在同一个主机

curl -XPUT 'localhost:9200/_cluster/settings' -d '{"persistent": {"cluster.routing.allocation.same_shard.host":true}}'

13、集群总是自动平衡时可以关闭自动平衡功能

关闭:

curl -XPUT http://localhost:9200/_cluster/settings?pretty -d '{

"transient" : {

"cluster.routing.rebalance.enable" : "none"

}

}'

打开:

curl -XPUT http://localhost:9200/_cluster/settings?pretty -d '{

"transient" : {

"cluster.routing.rebalance.enable" : "all"

}

}'

14、人工迁移分片

curl -XPOST 'http://localhost:9200/_cluster/reroute' -d '{

"commands": [

{

"move": {

"index": "event_20181019",

"shard": 1,

"from_node": "node119",

"to_node": "node96"

}

}

]

}'

15、集群中磁盘空间不平均导致分片都分配到大空间节点上,集群性能下降问题解决

比如:节点A和B磁盘空间20T,节点C磁盘空间10T, 一段时间之后分片不会分配到节点C上,导致节点A和节点B压力增大,不满足性能要求, 可通过将节点C上最早的索引分片迁移到A和B上来释放节点C的磁盘空间.

具体操作为:

在最早的5天的索引上执行下面命令,然后打开索引(之前的索引可能已关闭),将索引分片从小空间节点上转移到大空间节点上. 转移完成后关闭这5天的索引. 注意不要一次打开太多索引, 可能导致集群死掉.

curl -XPUT 'localhost:9200/event_20181218/_settings' -d '{"index.routing.allocation.exclude._name": "node_205"}'

如果分片没有自动平衡走,请检查是否打开了自动平衡功能.

16、快速的关闭/打开/删除索引

删除索引

curl -XDELETE 'localhost:9200/索引名字'

关闭索引

curl -XPOST 'localhost:9200/索引名字/_close'

打开索引

curl -XPOST 'localhost:9200/索引名字/_open'

17、ES启动失败

ES的运行用户是elasticsearch不是root,所以从根目录到ES的安装目录和数据目录都需要对elasticsearch用户开放权限

比如安装目录是/opt/hansight/enterprise, 数据目录是/data01那么这4个目录都要授权rx权限给elasticsearch用户, 其下的elasticsearch目录及子目录/文件的归属用户要是elasticsearch用户

来源:51CTO

作者:qq5e5f48e3af387

链接:https://blog.51cto.com/14743302/2483019

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值