Elasticsearch 错误:cluster_block_exception [FORBIDDEN/12/index 只读/允许删除 (api)],洪水阶段磁盘水位线超出

问题描述 投票:0回答:8

当尝试正常将文档发布到 Elasticsearch 时,我收到此错误:

cluster_block_exception [FORBIDDEN/12/index read-only / allow delete (api)];

我还在 Elasticsearch 日志上看到此消息:

flood stage disk watermark [95%] exceeded ... all indices on this node will marked read-only
elasticsearch
8个回答
519
投票

当 Elasticsearch 认为磁盘空间不足,因此将自身置于只读模式时,就会发生这种情况。

默认情况下,Elasticsearch 的决定基于可用磁盘空间的百分比,因此在大磁盘上,即使您有许多 GB 的可用空间,也可能会发生这种情况。

洪水阶段水印默认为 95%,因此在 1TB 驱动器上,您至少需要 50GB 的可用空间,否则 Elasticsearch 会将自身置于只读模式。

有关洪水阶段水印的文档,请参阅 https://www.elastic.co/guide/en/elasticsearch/reference/6.2/disk-allocator.html

正确的解决方案取决于上下文 - 例如生产环境与开发环境。

解决方案1:释放磁盘空间

释放足够的磁盘空间,使磁盘空间超过 5% 即可解决此问题。一旦有足够的可用磁盘,Elasticsearch 不会自动退出只读模式,您必须执行以下操作来解锁索引:

$ curl -XPUT -H "Content-Type: application/json" https://[YOUR_ELASTICSEARCH_ENDPOINT]:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'

解决方案2:更改洪水阶段水印设置

"cluster.routing.allocation.disk.watermark.flood_stage"
设置更改为其他内容。它可以设置为较低的百分比或绝对值。以下是如何从文档更改设置的示例:

PUT _cluster/settings
{
  "transient": {
    "cluster.routing.allocation.disk.watermark.low": "100gb",
    "cluster.routing.allocation.disk.watermark.high": "50gb",
    "cluster.routing.allocation.disk.watermark.flood_stage": "10gb",
    "cluster.info.update.interval": "1m"
  }
}

再次强调,完成此操作后,您必须使用上面的curl命令来解锁索引,但之后它们不应再次进入只读模式。


242
投票

默认情况下,当可用磁盘空间少于 5% 时,安装的 Elasticsearch 会进入只读模式。如果您看到类似以下错误:

Elasticsearch::传输::传输::错误::禁止:[403] {“错误”:{“root_cause”:[{“类型”:“cluster_block_exception”,“原因”:“已阻止 by: [FORBIDDEN/12/index 只读/允许删除 (api)];"}],"type":"cluster_block_exception","reason":"阻止者: [FORBIDDEN/12/index 只读/允许删除 (api)];"},"status":403}

或者在 /usr/local/var/log/elasticsearch.log 中,您可以看到类似以下内容的日志:

超过洪水阶段磁盘水位线 [95%] [nCxquc7PTxKvs6hLkfonvg][nCxquc7][/usr/local/var/lib/elasticsearch/nodes/0] 免费:15.3gb[4.1%],该节点上的所有索引将被标记为只读

然后您可以通过运行以下命令来修复它:

curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }'
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'

64
投票
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'

来自

https://techoverflow.net/2019/04/17/how-to-fix-elasticsearch-forbidden-12-index-read-only-allow-delete-api/


43
投票

当您的计算机磁盘空间不足时,通常会出现此错误。 避免此错误消息应遵循的步骤

  1. 重置索引上的只读索引块:

    $ curl -X PUT -H "Content-Type: application/json" http://127.0.0.1:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
    
    Response
    ${"acknowledged":true}
    
  2. 更新低水位线至至少50G可用空间,高水位线至至少20G可用空间,洪泛阶段水位线至10G可用空间,每分钟更新一次集群信息

     Request
     $curl -X PUT "http://127.0.0.1:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d' { "transient": { "cluster.routing.allocation.disk.watermark.low": "50gb", "cluster.routing.allocation.disk.watermark.high": "20gb", "cluster.routing.allocation.disk.watermark.flood_stage": "10gb", "cluster.info.update.interval": "1m"}}'
    
      Response
      ${
       "acknowledged" : true,
       "persistent" : { },
       "transient" : {
       "cluster" : {
       "routing" : {
       "allocation" : {
       "disk" : {
         "watermark" : {
           "low" : "50gb",
           "flood_stage" : "10gb",
           "high" : "20gb"
         }
       }
     }
    }, 
    "info" : {"update" : {"interval" : "1m"}}}}}
    

运行这两个命令后,必须再次运行第一个命令,以免索引再次进入只读模式


10
投票

仅使用以下命令更改设置在我的环境中不起作用:

curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'

我还必须运行强制合并 API 命令:

curl -X POST "localhost:9200/my-index-000001/_forcemerge?pretty"

参考:强制合并API


2
投票

即使计算机存储恢复到 95% 以上,问题仍然存在。

短期解决方案是将 kibana 限制提高到 95% 以上。此解决方案仅适用于 Windows。

a. Create a json file with following parameters


{
  "persistent": {
    "cluster.routing.allocation.disk.watermark.low": "90%",
    "cluster.routing.allocation.disk.watermark.high": "95%",
    "cluster.routing.allocation.disk.watermark.flood_stage": "97%"
  }
}

b.Name it anything ,e.g : json.txt

c.Type following command in command prompt

>curl -X PUT "localhost:9200/_cluster/settings?pretty" -H "Content-Type: application/json" -d @json.txt

d.Following output is received.

{
  "acknowledged" : true,
  "persistent" : {
    "cluster" : {
      "routing" : {
        "allocation" : {
          "disk" : {
            "watermark" : {
              "low" : "90%",
              "flood_stage" : "97%",
              "high" : "95%"
            }
          }
        }
      }
    }
  },
  "transient" : { }
}

e.Create another json file with following parameter


{
  "index.blocks.read_only_allow_delete": null
}

f.Name it anything ,e.g : json1.txt

g.Type following command in command prompt

>curl -X PUT "localhost:9200/*/_settings?expand_wildcards=all" -H "Content-Type: application/json" -d @json1.txt

h.You should get following output

{"acknowledged":true}

i.Restart ELK stack/Kibana and the issue should be resolved.

1
投票

来自 ELK 团队的精彩指南:

https://www.elastic.co/guide/en/elasticsearch/reference/master/disk-usage-exceeded.html

它对我来说对 ELK 7.x 有用


0
投票

我遇到了同样的问题,但我无法使用

curl
甚至使用
Dev Tools
调用 API。

所以我对每个索引手动进行了更改:

  1. 前往管理
  2. 前往指数管理
  3. 启用包括汇总索引包括系统索引
  4. 使用
    编辑设置
    将每个索引
    read_only_allow_delete
    配置从
    true
    更改为 null
© www.soinside.com 2019 - 2024. All rights reserved.