Elasticsearch 7.x修改/忘记密码

环境说明

  • JDK 8

  • CentOS 7

  • Elasticsearch 7.7.0单节点

前言

我们使用x-pack给Elasticsearch7.7.0设置密码,可参考Elasticsearch 7.x设置密码。但是我们难免会遇到两个问题:

  1. 设置的密码太过简单,安全性不足;
  2. 忘记了已经设置的密码,导致服务无法连接。

所以我们需要对Elasticsearch服务修改/重置密码。

修改前提

  1. 使用普通用户权限对Elasticsearch进行操作;
  2. 我们在Elasticsearch 7.x设置密码文章中Elastic用户设置的密码为:123456

修改步骤

已知ES原密码,只需进行修改

  1. 目前采用curl方式:

    curl -XPOST -u elastic "127.0.0.1:9200/_security/user/elastic/_password" -H 'Content-Type: application/json' -d'{"password" : "elastic123456"}'
    
    • 其中elastic123456为修改后的密码;
  2. 控制台需要键入原来的密码进行验证Enter host password for user 'elastic':

  3. 输入原来的密码:123456:

  4. 验证及完整打印:

    [kaysen@localhost elasticsearch-7.7.0]$ curl -XPOST -u elastic "127.0.0.1:9200/_security/user/elastic/_password" -H 'Content-Type: application/json' -d'{"password" : "elastic123456"}'
    Enter host password for user 'elastic':
    {}[kaysen@localhost elasticsearch-7.7.0]$ curl -u elastic:elastic123456 http://127.0.0.1:9200
    {
      "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"
    }
    

忘记密码,需要进行重置

  1. 修改配置文件config/elasticsearch.yml,注释掉支持x-pack的xpack.security.enabled: true配置,保存退出;

    # ---------------------------------- Various -----------------------------------
    #
    # Require explicit names when deleting indices:
    #
    #action.destructive_requires_name: true
    #
    #xpack.security.enabled: true
    
  2. 重启Elasticsearch进程(先kill掉):

    ./bin/elasticsearch -d
    
  3. 启动成功后,使用curl查看当前Elasticsearch的索引:

    curl -XGET "127.0.0.1:9200/_cat/indices" -H 'Content-Type: application/json'
    
  4. 控制台打印,多了一个.security-7的索引:

    [kaysen@localhost elasticsearch-7.7.0]$ curl -XGET "127.0.0.1:9200/_cat/indices" -H 'Content-Type: application/json'
    green open .security-7 J7VZVkwGT0um4GyH3nptnQ 1 0 6 0 20.5kb 20.5kb
    
  5. 删除.security-7的索引

    curl -XDELETE 127.0.0.1:9200/.security-7
    
  6. 有如下打印,表示已成功删除:

    {"acknowledged":true}
    
  7. 重置密码,请参考文章Elasticsearch 7.x设置密码进行设置。

你可能感兴趣的:(Elasticsearch,elasticsearch,大数据,搜索引擎)