返回

Elasticsearch集群开启账户密码安全配置自相矛盾的坑

后端

Elasticsearch 安全配置问题排查与解决方案

问题

在配置 Elasticsearch 集群的安全配置时,遇到了如下错误信息:

[2023-03-08T15:59:48,659][INFO ][o.e.c.s.SecurityPlugin] [qa-es-01] Security status changed to [initialized], config={path.home=/usr/share/elasticsearch, path.conf=/usr/share/elasticsearch/config, transport.profiles.default.bind_host=0.0.0.0, transport.profiles.default.publish_host=qa-es-01, transport.profiles.default.port=9300, transport.profiles.default.tcp_compression=true, transport.profiles.default.tcp_no_delay=true, transport.profiles.default.tcp_send_buffer_size=65535, transport.profiles.default.tcp_receive_buffer_size=65535, http.port=9200, http.cors.enabled=true, http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization, _csrf, Accept, Origin, Cookie, correlationId,requestId, timestamp, id, errorMessage, clusterId, scanId, scrollId, _shards, _source, version, size, from, sort, query, rest_total_hits, aggs, pipelines, highlighting, expand_wildcards, ignore_unavailable, allow_no_indices, ignore_throttled, expand_wildcard, lenient, pretty, human, error_trace, ccs, timeout, if_seq_no, if_primary_term, op_type, ingest.disable_type_validation, _source_include, _source_exclude, request, filter_path, _*,  *,   *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,  *,】

错误信息表明 Elasticsearch 安全状态已更改为“已初始化”,但配置中似乎存在冲突或错误。

原因分析

造成此问题的原因可能是以下之一:

  • 冲突的配置:elasticsearch.yml 配置文件中,存在与安全配置冲突的设置。
  • 缺少必填字段: 某些必需的安全字段可能未正确配置或已省略。
  • 无效证书: 用于加密通信或认证的证书可能无效或损坏。
  • 文件权限问题: 用于存储证书或密钥的文件的权限可能已配置不正确,导致 Elasticsearch 无法访问。
  • 密码错误: 在配置安全时输入的密码可能不正确。

解决方法

为了解决此问题,请执行以下步骤:

  1. 检查配置: 仔细检查 elasticsearch.yml 配置文件,确保没有与安全配置冲突的设置。确保已正确配置以下字段:

    • xpack.security.enabled:设置为 true 以启用安全。
    • xpack.security.transport.ssl.enabled:设置为 true 以启用传输层安全性 (TLS)。
    • xpack.security.http.ssl.enabled:设置为 true 以启用 HTTP TLS。