AI产品经理学习路线图全在这!从入门到实战,直接抄作业!
2026/6/10 12:54:15
最近发现我们的日志系统没有新的数据,排查日志发现报错:
你遇到的这个提示cluster currently has maximum normal shards open是 Elasticsearch 集群的一个核心告警,意思是你的 ES 集群已经达到了普通分片(normal shards)的最大打开数量限制,无法再创建新的分片。
这个限制主要来自两个层面:
cluster.max_shards_per_node(默认值通常是 1000),表示每个节点允许的最大分片数(主分片+副本分片)。当集群中所有节点的分片数总和达到这个阈值时,就会触发该告警。如果是分片数达到集群阈值导致的问题,可以先临时调高分片上限:
# 适用于 ES 无密码认证的情况curl-XPUT"http://<ES节点IP>:<端口>/_cluster/settings"-H"Content-Type: application/json"-d'{ "persistent": { "cluster.max_shards_per_node": 2000 } }'# 若 ES 开启了账号密码认证(添加 -u 用户名:密码)curl-XPUT"http://<ES节点IP>:<端口>/_cluster/settings"-u"elastic:你的密码"-H"Content-Type: application/json"-d'{ "persistent": { "cluster.max_shards_per_node": 2000 } }'分片过多本身是 ES 集群的“性能杀手”,调整上限只是临时方案,核心是优化分片规划:
# 删除单个索引curl-XDELETE"http://<ES节点IP>:<端口>/old_index_name"-H"Content-Type: application/json"# 按通配符删除(谨慎!)curl-XDELETE"http://<ES节点IP>:<端口>/test_*"-H"Content-Type: application/json"# 带认证的删除curl-XDELETE"http://<ES节点IP>:<端口>/old_index_name"-u"elastic:你的密码"-H"Content-Type: application/json"# 基础版(无认证)curl-XPOST"http://<ES节点IP>:<端口>/_reindex"-H"Content-Type: application/json"-d'{ "source": { "index": ["small_index_1", "small_index_2"] }, "dest": { "index": "merged_large_index" } }'# 带认证的 reindexcurl-XPOST"http://<ES节点IP>:<端口>/_reindex"-u"elastic:你的密码"-H"Content-Type: application/json"-d'{ "source": { "index": ["small_index_1", "small_index_2"] }, "dest": { "index": "merged_large_index" } }'如果调整分片上限后仍报错,需检查服务器文件描述符:
# 查看 ES 进程的文件描述符限制cat/proc/$(ps-ef|grepelasticsearch|grep-vgrep|awk'{print$2}')/limits|grep"Open Files"# 临时调高文件描述符(需 root 权限)ulimit-n65535# 永久修改(编辑 /etc/security/limits.conf)echo"* soft nofile 65535">>/etc/security/limits.confecho"* hard nofile 65535">>/etc/security/limits.conf修改后需重启 Elasticsearch 生效。
执行以下命令检查集群状态和分片数,确认问题解决:
# 查看集群健康状态curl-XGET"http://<ES节点IP>:<端口>/_cluster/health?pretty"-H"Content-Type: application/json"# 查看所有索引的分片数(格式化输出,更易读)curl-XGET"http://<ES节点IP>:<端口>/_cat/shards?v"-H"Content-Type: application/json"# 查看集群分片上限配置curl-XGET"http://<ES节点IP>:<端口>/_cluster/settings?flat_settings=true&pretty"-H"Content-Type: application/json"|grep"max_shards_per_node"# 带认证的验证命令(以查看集群健康为例)curl-XGET"http://<ES节点IP>:<端口>/_cluster/health?pretty"-u"elastic:你的密码"-H"Content-Type: application/json"cluster.max_shards_per_node配置;关键点:不要盲目调高分片上限,分片过多会导致集群性能下降(比如频繁的分片重分配、内存占用过高),优化分片规划才是根本。