Elasticsearch如何设置密码
warning:
这篇文章距离上次修改已过436天,其中的内容可能已经有所变动。
在Elasticsearch中设置密码通常涉及配置elasticsearch.yml文件以启用基本认证,并配置用户和角色。以下是设置密码的步骤:
在Elasticsearch的配置文件
elasticsearch.yml中启用基本认证:xpack.security.enabled: true xpack.license.self_generated.type: basic启动Elasticsearch服务并初始化安全设置:
bin/elasticsearch-setup-passwords interactive这个命令会提示你为内置用户(如
elastic,kibana,logstash_system等)设置密码。选择interactive模式后按照提示设置密码。- 重新启动Elasticsearch服务以应用配置。
- 使用
elastic用户和你设置的密码连接Elasticsearch。
如果你需要创建自定义用户并分配密码,可以使用Elasticsearch的REST API:
# 创建用户
curl -X POST "localhost:9200/_security/user/custom_user?pretty" -H 'Content-Type: application/json' -d'
{
"password" : "custom_password",
"roles" : [ "superuser" ],
"full_name" : "Custom User",
"email" : "custom_user@example.com"
}'
# 更新用户密码
curl -X POST "localhost:9200/_security/user/custom_user/_password?pretty" -H 'Content-Type: application/json' -d'
{
"password" : "new_custom_password"
}'请确保你的Elasticsearch版本支持X-Pack安全功能,并且在生产环境中应该使用更安全的方式来管理密码和安全设置,例如使用Elasticsearch keystore或与LDAP/Active Directory集成。
评论已关闭