es集群状态yellow排查

问题背景

项目中全文检索接口响应时间超30s,排查接口逻辑,耗时主要花在es查询上,故对es集群进行排查。把接口请求生成的dsl拿去kibana中执行,发现响应时间确实太长,于是开始排查es健康问题

通过es命令对集群情况进行分析,得到以下结果:

1.集群健康状况为yellow,存在大量副本分片未分配情况;

{
  "cluster_name" : "cdb*",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : ***,
  "number_of_data_nodes" : ***,
  "active_primary_shards" : ***,
  "active_shards" : ***,
  "relocating_shards" : ***,
  "initializing_shards" : ***,
  "unassigned_shards" : 214, // ~注意看这里
  "delayed_unassigned_shards" : ***,
  "number_of_pending_tasks" : ***,
  "number_of_in_flight_fetch" : ***,
  "task_max_waiting_in_queue_millis" : ***
}

2.某个节点因位置原因导致连接不上,集群触发分片恢复;(1.把所有丢失的副本分片重新分配到集群其他健康节点中2.rebalancing操作)

{
	"unassigned_info": {
		"reason": "NODE_LEFT",
		"at": "2020-11-20T03:12:16",
		"details": "node_left ***",
		"last_allocation_status": "no_attempt"
	}
}

3.分片恢复并发数(源节点并发数和目标节点并发数)使用的默认设置,导致分片恢复并发拉满,恢复速度过慢 ;

(cluster.routing.allocation.node_concurrent_incoming_recoveries=2、cluster.routing.allocation.node_concurrent_outgoing_recoveries=2)

问题描述:
{
	"node_id": "***",
	"node_name": "mastersha",
	"transport_address": "***",
	"node_decision": "throttled",
	"deciders": [{
		"decider": "throttling",
		"decision": "THROTTLE",
		"explanation": "reached the limit of incoming shard recoveries [2], cluster setting [cluster.routing.allocation.node_concurrent_incoming_recoveries=2] (can also be set via [cluster.routing.allocation.node_concurrent_recoveries])"
	}]
}

{
	"node_id": "***",
	"node_name": "master",
	"transport_address": ***,
	"node_decision": "no",
	"store": {
		"matching_sync_id": true
	},
	"deciders": [{
			"decider": "same_shard",
			"decision": "NO",
			"explanation": "the shard cannot be allocated to the same node on which a copy of the shard already exists [[index_execution][2], node[***], [P], s[STARTED], a[id=***]]"
		},
		{
			"decider": "throttling",
			"decision": "THROTTLE",
			"explanation": "reached the limit of outgoing shard recoveries [2] on the node [***] which holds the primary, cluster setting [cluster.routing.allocation.node_concurrent_outgoing_recoveries=2] (can also be set via [cluster.routing.allocation.node_concurrent_recoveries])"
		}
	]
}

 注:

 ES性能分析用到的一些DSL命令:

GET _cat/health
GET _cluster/health
GET _cat/nodes
GET _cluster/health?level=indices
GET _cluster/health?level=shards
GET _cluster/allocation/explain
GET _cat/indices
GET _cluster/state

### Elasticsearch 集群状态不稳定的解决方案 当 Elasticsearch 集群状态不稳定时,可能涉及多个方面的原因。以下是针对该问题的分析和解决方法: #### 1. **检查集群健康状态** 通过 REST API 查询集群的健康状态可以帮助快速定位问题所在。可以运行以下命令来获取集群的整体健康状况: ```bash GET /_cluster/health?pretty=true ``` 此命令返回的结果中包含了 `status` 字段,其值可能是 `green`, `yellow` 或者 `red`。如果状态为 `red` 或 `yellow`,说明存在潜在问题[^1]。 #### 2. **确认 Master 节点选举正常** Elasticsearch 使用 Zen Discovery 进行服务发现和主节点选举。如果当前节点未能成功加入到主节点,则可能导致集群状态不稳定。可以通过查看日志文件中的错误消息进一步排查原因。确保网络连通性和配置一致性是解决问题的关键之一[^3]。 #### 3. **调整分片分配策略** 如果某些分片未被正确分配给数据节点,也可能引起集群状态波动。执行如下命令强制重新分配分片可能会有所帮助: ```json POST /_cluster/reroute { "commands": [ { "allocate_stale_primary": { "index": "<your_index_name>", "shard": <shard_id>, "node": "<target_node>" } } ] } ``` 另外,在多副本环境中设置合理的副本数量也很重要。例如减少不必要的副本来降低资源消耗并提高稳定性: ```json PUT /<your_index>/_settings { "number_of_replicas": 0 } ``` 之后可以根据实际需求再逐步增加副本数。 #### 4. **优化热温架构设计** 对于大规模生产环境下的 Elasticsearch 集群来说,采用热温架构能够有效提升整体性能与可靠性。具体做法包括区分不同类型的工作负载至不同类型的物理设备上——比如让频繁更新的数据驻留在高性能 SSD 支持下的 hot nodes 上;而对于那些不再变化的历史存档类资料则迁移到成本更低但速度较慢 HDD 构成 warm nodes 中去处理[^4]。 #### 5. **重启服务恢复异常情况** 有时候简单的重启操作就可以修复一些临时性的故障。按照标准流程停止然后再启动整个 ElasticSearch 实例链路即可尝试恢复正常运作模式: ```bash systemctl stop elasticsearch sleep 5 #等待几秒钟确保完全关闭 systemctl start elasticsearch ``` 或者直接重载守护进程加载最新修改过的配置参数表项而无需终止程序本身运行过程: ```bash systemctl daemon-reload systemctl reload elasticsearch ``` 最后别忘了验证一下新的设定生效与否以及是否解决了之前遇到的问题[^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

馥影

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

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

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

打赏作者

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

抵扣说明:

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

余额充值