Elasticsearch 7.x设置密码访问

Elasticsearch在7.0.0之后免费使用x-pack,也为了系统业务数据安全,所以我们使用x-pack对Elasticsearch进行密码设置。

设置密码前注意事项

  1. Elasticsearch需要提前启动一次,否则会出现以下Error:

    ERROR: Elasticsearch keystore file is missing [/kaysen/daemon/elasticsearch-7.7.0/config/elasticsearch.keystore]
    
  2. Elasticsearch必须处于启动状态,否则会出现以下Error:

    Connection failure to: http://127.0.0.1:9200/_security/_authenticate?pretty failed: Connection refused (Connection refused) 
    ERROR: Failed to connect to elasticsearch at http://127.0.0.1:9200/_security/_authenticate?pretty. Is the URL correct and elasticsearch running?
    
  3. 密码生成的两种方式:

    1. auto:各用户自动生成密码;
    2. interactive:手动设置密码。
  4. 以下操作操作都是使用普通用户权限进行操作。

配置x-pack步骤

  1. 进入elasticsearch目录,执行以下命令:
    ./bin/elasticsearch-setup-passwords interactive
    
  2. 会出现以下错误信息:
    Unexpected response code [500] from calling GET http://127.0.0.1:9200/_security/_authenticate?pretty  
    It doesn't look like the X-Pack security feature is enabled on this Elasticsearch node.
    Please check if you have enabled X-Pack security in your elasticsearch.yml configuration file.
    
  3. 我们需要配置文件中开启x-pack验证,修改config/elasticsearch.yml配置文件,在尾部添加以下内容,然后重启elasticsearch:
    xpack.security.enabled: true
    
    ./bin/elasticsearch -d
    
  4. 重复第1步,为elasticapm_systemkibanalogstash_systembeats_systemremote_monitoring_user设置密码,这里我设置了统一密码:123456,具体操作:
    ./bin/elasticsearch-setup-passwords interactive
    
    future versions of Elasticsearch will require Java 11; your Java version from [/kaysen/tools/java/jre] does not meet this requirement
    Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
    You will be prompted to enter passwords as the process progresses.
    Please confirm that you would like to continue [y/N]y
    
    
    Enter password for [elastic]: 
    Reenter password for [elastic]: 
    Enter password for [apm_system]: 
    Reenter password for [apm_system]: 
    Enter password for [kibana]: 
    Reenter password for [kibana]: 
    Enter password for [logstash_system]: 
    Reenter password for [logstash_system]: 
    Enter password for [beats_system]: 
    Reenter password for [beats_system]: 
    Enter password for [remote_monitoring_user]: 
    Reenter password for [remote_monitoring_user]: 
    Changed password for user [apm_system]
    Changed password for user [kibana]
    Changed password for user [logstash_system]
    Changed password for user [beats_system]
    Changed password for user [remote_monitoring_user]
    Changed password for user [elastic]
    
  5. 先不加用户密码进行访问:curl 127.0.0.1:9200
    {
      "error": {
        "root_cause": [
          {
            "type": "security_exception",
            "reason": "missing authentication credentials for REST request [/]",
            "header": {
              "WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
            }
          }
        ],
        "type": "security_exception",
        "reason": "missing authentication credentials for REST request [/]",
        "header": {
          "WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
        }
      },
      "status": 401
    }
    

CURL密码访问Elasticsearch

curl -u elastic:123456 127.0.0.1:9200
# 或者
curl -u elastic 127.0.0.1:9200
Enter host password for user 'elastic': 123456

成功打印:

{
  "name" : "localhost.localdomain",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "MZlO8UPyS52AuuCrFwABvQ",
  "version" : {
    "number" : "7.7.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "81a1e9eda8e6183f5237786246f6dced26a10eaf",
    "build_date" : "2020-05-12T02:01:37.602180Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Elasticsearch是一个开源的分布式搜索和分析引擎,它提供了强大的全文搜索功能和实时数据分析能力。Elasticsearch中,密码是用于保护集群和数据的安全性的重要组成部分。 Elasticsearch密码可以通过以下几种方式进行设置和管理: 1. 内置用户认证:Elasticsearch提供了内置的用户认证功能,可以通过配置用户名和密码来限制对集群的访问。可以使用内置的超级用户账号(如"elastic")来创建和管理其他用户账号,并为每个账号分配相应的角色和权限。 2. 安全插件:Elasticsearch还提供了一些安全插件,如X-Pack Security插件,它提供了更加细粒度的访问控制和安全功能,包括基于角色的访问控制、SSL/TLS加密通信、审计日志等。 3. 第三方认证和授权:除了内置的用户认证功能外,Elasticsearch还支持与第三方认证和授权系统集成,如LDAP、Active Directory等,以便更好地与企业现有的身份验证系统进行整合。 需要注意的是,为了确保Elasticsearch集群的安全性,建议采取以下措施: 1. 使用强密码设置复杂且不易猜测的密码,包括字母、数字和特殊字符的组合,以增加密码安全性。 2. 定期更换密码:定期更换密码可以降低密码泄露的风险,建议每隔一段时间更换一次密码。 3. 限制访问权限:根据实际需求,为每个用户分配适当的角色和权限,限制其对集群和数据的访问权限。 4. 加密通信:启用SSL/TLS加密通信,确保数据在传输过程中的安全性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值