未创建每日索引

Daily index not created

在我的 8G RAM(1955m 到 JVM)和 es v 7.4 的单个测试服务器上,我有 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 'UNASSIGNED'

.
.
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个分片作为分片限制,这样我就永远不会遇到这个提到的分片问题吗?

谢谢,

你有很多未分配的分片(可能是因为你只有一个节点,所有索引的replicas=1),所以很容易把它们全部去掉,同时去掉错误,通过 运行 以下命令

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

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

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