【问题标题】:Elasticsearch error: cluster_block_exception [FORBIDDEN/12/index read-only / allow delete (api)], flood stage disk watermark exceededElasticsearch 错误:cluster_block_exception [FORBIDDEN/12/index read-only / allow delete (api)], flood stage disk watermark 超出
【发布时间】:2018-11-09 14:07:15
【问题描述】:

当尝试像往常一样将文档发布到 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

【问题讨论】:

  • 当你提出这个问题时,我刚刚遇到了这个问题。 ES 讨论说释放内存

标签: elasticsearch


【解决方案1】:

当 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" 设置更改为其他设置。它可以设置为较低的百分比或绝对值。以下是如何从the docs 更改设置的示例:

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 命令来解锁索引,但之后它们不应再次进入只读模式。

【讨论】:

  • 嗨。但即使我的系统中有足够的可用空间,我也会收到此错误。还有其他原因可以报告此问题吗?
  • 我有同样的问题,即使我有 82.43% 的磁盘可用。我用 curl 命令修复它,但几天后我得到了同样的结果。
  • @SankalpaTimilsina 你得到答案了吗,我也面临同样的问题。
  • 使用 curl 命令curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number 可能会出现以下错误。这意味着您没有为 TLS 配置 Elasticsearch。所以只需使用 http
  • 确保在释放磁盘空间后重新启动弹性搜索。
【解决方案2】:

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

Elasticsearch::Transport::Transport::Errors::Forbidden: [403] {"error":{"root_cause":[{"type":"cluster_block_exception","re​​ason":"blocked by: [FORBIDDEN/12/index 只读/允许删除 (api)];"}],"type":"cluster_block_exception","re​​ason":"被阻止: [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}'

【讨论】:

  • 谢谢!我很沮丧。你发布的第二个 curl 命令对我有用!
  • 谢谢!它适用于我的本地环境!
  • 为我工作,用本地 docker 弹性容器碰到它。
【解决方案3】:
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/

【讨论】:

  • 我收到了一个{"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index [null] and no indices exist" 你的命令,知道吗?
  • 谢谢!我的磁盘空间不足。即使我释放了一些空间,问题仍然存在。这个命令解决了我的问题!
  • 这是现代 Elasticsearch 版本的正确解决方案。但是,它不适用于_all。我必须手动将其应用于每个索引。
  • @rubik 您能否提及您如何“手动将其应用于每个索引”?我是 Elasticsearch 的新手,面临 _all 不起作用的相同问题。
  • @rom 当然。只需将_all 替换为索引名称,然后对每个索引重复请求即可。
【解决方案4】:

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

  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. 更新低水位线至少50GB免费,高水位线至少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"}}}}}
    

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

【讨论】:

  • 你说的“第一个命令”是什么意思你只提到了两个命令,所以当你说“在这两个之后,也运行第一个”时我不完全理解你的意思。另外,不同的水印有什么用?低至 50GB 是什么意思? 20GB 高是什么意思?
【解决方案5】:

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

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

我还必须运行 Force Merge API 命令:

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

参考:Force Merge API

【讨论】:

    猜你喜欢
    • 2018-06-10
    • 1970-01-01
    • 2020-01-10
    • 2019-05-30
    • 2019-03-08
    • 1970-01-01
    • 2019-10-16
    • 2021-01-24
    • 1970-01-01
    相关资源
    最近更新 更多