[esuser@KJFXGL bin]$ curl -H "Content-Type:application/json" -XPOST -u elastic 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password' -d '{"password":"zy@es14583763!"}' Enter host password for user 'elastic': {"error":{"root_cause":[{"type":"exception","reason":"Security must be explicitly enabled when using a [basic] license. Enable security by setting [xpack.security.enabled] to [true] in the elasticsearch.yml file and restart the node."}],"type":"exception","reason":"Security must be explicitly enabled when using a [basic] license. Enable security by setting [xpack.security.enabled] to [true] in the elasticsearch.yml file and restart the node."},"status":500}[esuser@KJFXGL bin]$ curl -H "Content-Type:application/json" -XPOST -u elastic 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password' -d '{"password":"z
时间: 2025-09-09 13:08:19 AIGC 浏览: 4
### 解决方案
当 `xpack.security.enabled` 被设置为 `false` 时,Elasticsearch 的安全性功能会被禁用,这包括用户身份验证和访问控制等功能[^1]。如果希望启用这些安全功能并设置用户密码,则需要修改 `elasticsearch.yml` 配置文件中的相关参数。
以下是具体的配置方法:
#### 修改 `elasticsearch.yml`
在 `elasticsearch.yml` 文件中添加或更新以下配置项:
```yaml
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.key: /path/to/your/private/key.pem
xpack.security.http.ssl.certificate: /path/to/your/certificate.crt
xpack.security.http.ssl.verification_mode: certificate
```
- **`xpack.security.enabled: true`**: 启用 X-Pack 安全模块的功能[^3]。
- **`xpack.security.enrollment.enabled: true`**: 允许通过内置流程创建初始用户和密码。
- **`xpack.security.transport.ssl.enabled: true`** 和 **`xpack.security.http.ssl.enabled: true`**: 启用传输层和 HTTP 层的 SSL/TLS 加密[^4]。
- **`xpack.security.http.ssl.key`** 和 **`xpack.security.http.ssl.certificate`**: 指定私钥和证书的位置。
- **`xpack.security.http.ssl.verification_mode`**: 设置为 `certificate` 或其他适合的模式以增强安全性。
完成上述更改后保存文件。
#### 重启 Elasticsearch 服务
运行以下命令以重启 Elasticsearch 服务,使新的配置生效:
```bash
sudo systemctl restart elasticsearch.service
```
或者,在某些环境中可能需要使用以下命令:
```bash
bin/elasticsearch-restart
```
#### 初始化用户密码
启动完成后,可以通过以下命令初始化内置用户的密码:
```bash
./bin/elasticsearch-setup-passwords interactive
```
该命令将以交互方式提示你为内置用户(如 `elastic`, `kibana_system` 等)设置新密码。
---
### 注意事项
1. 如果之前设置了 `xpack.security.enabled: false` 并尝试直接切换到 `true`,可能会遇到未知设置或其他错误消息。此时应检查是否有废弃的旧版配置选项存在,例如 `[node.master]` 已被移除的情况[^2]。
2. 在生产环境中强烈建议始终启用安全性功能,并配合 SSL/TLS 提供额外保护[^4]。
---
###
阅读全文
相关推荐



















