【问题标题】:Daily index not created未创建每日索引
【发布时间】:2021-10-08 21:27:39
【问题描述】:

在具有 es v 7.4 的 8G RAM(1955m 到 JVM)的单个测试服务器上,我有 12 个应用程序索引 + 少数系统索引,例如 (.monitoring-es-7-2021.08.02, .monitoring-logstash-7 -2021.08.02, .monitoring-kibana-7-2021.08.02) 每天创建。所以平均而言,我可以看到每天 es 创建 15 个索引。

今天我可以看到只创建了两个索引。

curl -slient -u elastic:xxxxx 'http://127.0.0.1:9200/_cat/indices?v' -u elastic |  grep '2021.08.03'
Enter host password for user 'elastic':
yellow open   metricbeat-7.4.0-2021.08.03                KMJbbJMHQ22EM5Hfw   1   1     110657            0     73.9mb         73.9mb
green  open   .monitoring-kibana-7-2021.08.03            98iEmlw8GAm2rj-xw   1   0          3            0      1.1mb          1.1mb

我认为上面的原因如下,

在查看es日志时,发现

[2021-08-03T12:14:15,394][WARN ][o.e.x.m.e.l.LocalExporter] [elasticsearch_1] unexpected error while indexing monitoring document org.elasticsearch.xpack.monitoring.exporter.ExportException: org.elasticsearch.common.ValidationException: Validation Failed: 1: this action would add [1] total shards, but this cluster currently has [1000]/[1000] maximum shards open;

应用程序索引和filebeat索引的logstash日志

[2021-08-03T05:18:05,246][WARN ][logstash.outputs.elasticsearch][main] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"ping_server-2021.08.03", :_type=>"_doc", :routing=>nil}, #LogStash::Event:0x44b98479], :response=>{"index"=>{"_index"=>"ping_server-2021.08.03", "_type"=>"_doc", "_id"=>nil, "status"=>400, "error"=>{"type"=>"validation_exception", "reason"=>"Validation Failed: 1: this action would add [2] total shards, but this cluster currently has [1000]/[1000] maximum shards open;"}}}}

[2021-08-03T05:17:38,230][WARN ][logstash.outputs.elasticsearch][main] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"filebeat-7.4.0-2021.08.03", :_type=>"_doc", :routing=>nil}, #LogStash::Event:0x1e2c70a8], :response=>{"index"=>{"_index"=>"filebeat-7.4.0-2021.08.03", "_type"=>"_doc", "_id"=>nil, "status"=>400, "error"=>{"type"=>"validation_exception", "reason"=>"Validation Failed: 1: this action would add [2] total shards, but this cluster currently has [1000]/[1000] maximum shards open;"}}}}

将活动和未分配的分片总数增加到 1000

"active_primary_shards" : 512,
  "active_shards" : 512,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 488,
  "delayed_unassigned_shards" : 0,
  "active_shards_percent_as_number" : 51.2

如果我检查以下命令,我会看到所有未分配的分片都是副本分片

curl -slient -XGET -u elastic:xxxx http://localhost:9200/_cat/shards | grep '未签名'

.
.
dev_app_server-2021.07.10           0 r UNASSIGNED                            
apm-7.4.0-span-000028               0 r UNASSIGNED                                                      
ping_server-2021.07.02              0 r UNASSIGNED                            
api_app_server-2021.07.17           0 r UNASSIGNED                            
consent_app_server-2021.07.15       0 r UNASSIGNED

问。那么现在,我可以安全地删除未分配的分片以释放一些分片作为其单节点集群吗?

问。我可以将设置从分配 2 个分片(1 个主分片和 1 个副本)更改为 1 个主分片作为每个在线索引的单个服务器吗?

问。如果我必须保留一年的指数,下面的计算是否正确?

每天 15 个索引,一个主分片 * 365 天 = 5475 个总分片(或者说 6000 个四舍五入)

问。我可以为这个节点设置 6000 个分片作为分片限制,这样我就永远不会遇到提到的分片问题吗?

谢谢,

【问题讨论】:

    标签: elasticsearch logstash filebeat


    【解决方案1】:

    您有很多未分配的分片(可能是因为您有一个节点并且所有索引的副本数=1),因此很容易摆脱所有这些分片并同时消除错误,通过运行以下命令

    PUT _all/_settings
    {
      "index.number_of_replicas": 0
    } 
    

    关于索引的计数,如果这些索引保持较小(即每个小于 10GB),您可能不必每天创建一个索引。因此,默认的 1000 个分片数量就足够了,您无需进行任何更改。

    您应该简单地利用 Index Lifecycle Management 来控制您的索引大小,而不是创建太多的小索引。

    【讨论】:

    • 嗨@Val,谢谢。我正在阅读 v7.4 的 ILM 文档。因此要验证 ILM 是否真的会减少数量。碎片,将在上面考虑,例如假设每个索引每天创建 1G,对于我来说要保留 365 天的数据,一个索引将是 1G * 365 = 365G/yr,现在如果我创建策略以在 50G 之后翻转索引,所以 365G/50G = 7 ,是不是意味着这个索引一年只需要7个分片?它是否正确?类似的说,如果我们创建策略在 30 天后翻转索引,所以 365/30 = 12,是否意味着一个索引一年只有 12 个分片?
    • 以上假设对于两种情况都是正确的,即rollover after 50Grollover after 30 days?
    • 感谢您提供一些数字。如果您每天创建 1G 的数据,我将创建每月索引,即 30 天或 30G 后的翻转(以先到者为准)。例如,如果每个索引有 2 个主分片(每个约 15G),那么全年最多有 24 个主分片,这是完全可以接受的。以这种方式进行将使您远远低于每个集群 1000 个分片的限制。
    • 嗨@Val,谢谢您的回复。是以上设置更改编号。副本数为 0 是永久的吗?应用此设置后,新索引将只有 1 个主副本吗?如何检查应用于每天创建的每个新索引的设置(特别是分片)(可能称为index template
    • 是的,如果您要使用 ILM,则无论如何都需要创建一个索引模板。在该模板中,您需要将副本设置为 0(因为您有一个节点,因此副本无用),将主副本设置为 1 或 2(最好)。如果您设置了它,您将永远不必再担心它,除非您的每日交易量增加,在这种情况下,您可能只需将主分片计数增加 1 并再过一年快乐:-)跨度>
    猜你喜欢
    • 2018-07-15
    • 1970-01-01
    • 2018-06-25
    • 1970-01-01
    • 1970-01-01
    • 2020-10-02
    • 2023-03-15
    • 1970-01-01
    相关资源
    最近更新 更多