elasticsearch的默认用户和密码是什么?

问题描述 投票:0回答:13

我已经使用 Docker 安装了 Elastic

docker run -p 9200:9200 \
           -p 9300:9300 \
           -e "discovery.type=single-node" \ 
           docker.elastic.co/elasticsearch/elasticsearch:5.6.2

但是

curl localhost:9200
失败并出现身份验证错误:

{
  "error": {
    "root_cause": [
      {
        "type": "security_exception",
        "reason": "missing authentication token for REST request [/]",
        "header": {
          "WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
        }
      }
    ],
    "type": "security_exception",
    "reason": "missing authentication token for REST request [/]",
    "header": {
      "WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
    }
  },
  "status": 401
}

Elasticsearch 的默认用户名/密码组合是什么?

docker authentication elasticsearch credentials
13个回答
94
投票

默认为

user: elastic
password: changeme

所以:

$ curl -u elastic:changeme localhost:9200
{
  "name" : "5aEHJ-Y",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "3FmaYN7rS56oBTqWOyxmKA",
  "version" : {
    "number" : "5.6.2",
    "build_hash" : "57e20f3",
    "build_date" : "2017-09-23T13:16:45.703Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.1"
  },
  "tagline" : "You Know, for Search"
}

了解有关更改默认值的更多信息。


24
投票

设置Elastic Search的用户名和密码:(ES版本:7.5.2)(Ubuntu 18.04)

第1步:首先在elasticsearch.yml文件中启用xpackmonitoring

root@flax:/etc/elasticsearch# vim elasticsearch.yml

Add the following line to the end of file:
    xpack.security.enabled: true

File Contents:
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /var/lib/elasticsearch
#
# Path to log files:
#
path.logs: /var/log/elasticsearch
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
network.host: 127.0.0.1
http.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
xpack.security.enabled: true

第2步: 转到 /usr/share/elasticsearch 文件夹:

root@flax:/usr/share/elasticsearch# systemctl start elasticsearch

root@flax:/usr/share/elasticsearch# ./bin/elasticsearch-setup-passwords interactive

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]: 
Passwords do not match.
Try again.
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]

root@flax:/usr/share/elasticsearch# systemctl restart elasticsearch

root@flax:/usr/share/elasticsearch# systemctl restart elasticsearch.service

15
投票

请注意ElasticSearch的版本。 在 7.2 参数 ELASTIC_PASSWORD 有效。

docker run -p 9200:9200 \
           -p 9300:9300 \
           -e "discovery.type=single-node" \ 
           -e "ELASTIC_PASSWORD=my_own_password" \

但是这一行也应该添加到elasticsearch.yml中:

xpack.security.enabled: true

默认情况下,它不存在。

安全设置列表


12
投票

如果您在elasticsearch 7.7版本中使用

xpack.security.enabled: true
启用了基本的x-pack安全性(在撰写本答案时),它将不会像旧版本中那样具有默认密码(
changeme
) x 包。

安全入门官方文档

中所述

X-Pack 安全性提供了一个内置的弹性超级用户,您可以使用 开始设置。该弹性用户具有完全访问权限 集群,包括所有索引和数据,所以弹性用户会这样做 默认没有设置密码。

所以你需要更改

elastic
的密码,如果你想在安装后更改,请按照交互模式中内置用户设置密码指南

这需要您从elasticsearch bin文件夹运行以下命令。

bin/elasticsearch-setup-passwords interactive

7
投票

设置用户名和密码

ssh到系统,停止elasticsearch和kibana服务,然后运行以下命令

sudo nano /etc/elasticsearch/elasticsearch.yml

更新此文件,通过添加以下行启用安全性

xpack.security.enabled: true 

更改密码

执行以下步骤更改密码

步骤1:

 cd /usr/share/elasticsearch/

第2步:

sudo bin/elasticsearch-setup-passwords auto

auto - 使用随机生成的密码 交互 - 使用密码 由用户输入

sudo bin/elasticsearch-setup-passwords interactive

您可以在“交互”模式下运行该命令,这会提示您 输入elastic、kibana_system、logstash_system的新密码, beats_system、apm_system 和 remote_monitoring_user 用户:

以上命令可以帮助您设置密码

启动Elasticsearch

  1. 通过运行systemctl命令启动Elasticsearch服务:

    sudo systemctl启动elasticsearch.service

系统启动服务可能需要一些时间。成功的话不会有任何输出。

  1. 启用 Elasticsearch 在启动时启动:

    sudo systemctl启用elasticsearch.service

启动并启用 Kibana

  1. 启动Kibana服务:

    sudo systemctl启动kibana

服务启动成功则无任何输出。

  1. 接下来,配置 Kibana 在启动时启动:

    sudo systemctl 启用 kibana


5
投票

\elasticsearch-8.2.2\config\elasticsearch.yml

中添加以下两行
# Enable security features
xpack.security.enabled: true
xpack.security.enrollment.enabled: true

然后重新启动服务器对我有用,它将密码打印到控制台上,并使用 -u 作为用户名


2
投票

在 Elasticsearch 版本 6.x 中 - 您可以使用 ELASTIC_PASSWORD 环境变量为 elastic 用户指定初始密码。

docker run -p 9200:9200 \
           -p 9300:9300 \
           -e "discovery.type=single-node" \ 
           -e "ELASTIC_PASSWORD=my_own_password" \
           docker.elastic.co/elasticsearch/elasticsearch:6.5.4

来源:https://www.elastic.co/guide/en/elasticsearch/reference/6.x/configuring-tls-docker.html


2
投票

对于 ES 8.4.3,我们可以像下面这样重置弹性搜索密码

sudo docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic


2
投票

我运行的是我使用的8.8.0版本,当你第一次尝试运行时, 它在日志中显示密码和用户名,当你运行它时,在cmd中搜索如下数据,它几乎是最新行(我在Windows中运行它):

 Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):

如果你第一次没有看到,只需删除弹性文件夹并再次提取,我就是这样做的。这是最简单的方法。


1
投票

在命令提示符中转到弹性文件夹:

C:\Users\username>cd C:\your_elastic_folder\bin

执行

elasticsearch-setup-passwords interactive

并设置您的密码。之后你就可以登录你的http://localhost:9200/


0
投票

我在最新版本的elasticsearch 中也遇到了类似的问题。当我安装elasticsearch 7.14.0时它起作用了!如果您感兴趣,我有一个 YouTube 视频:https://www.youtube.com/watch?v=mqgYebLacYI.


0
投票

对于8.4.3版本,您需要执行以下步骤:

  1. 更新配置lasticsearch.yml以添加

    xpack.security.enabled: true

  2. 如果收到此类错误消息,请运行此命令来创建密钥库:

    “错误:Elasticsearch 密钥库文件丢失”

    奔跑

    bin/elasticsearch-keystore create -p

  3. 启动弹性搜索:

    bin/elasticsearch

  4. 更新密码

    bin/elasticsearch-setup-passwords interactive

Note: The 'elasticsearch-setup-passwords' tool has been deprecated. This command will be removed in a future release.
******************************************************************************

Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,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]



0
投票

您可以在yaml文件中配置它

  containers:
  - name: elasticsearch
    image: elasticsearch:8.7.1
    ports:
    - containerPort: 9200
    env:
    - name: discovery.type
      value: single-node
    - name: ELASTIC_USERNAME
      value : guest
    - name : ELASTIC_PASSWORD
      value : guest
© www.soinside.com 2019 - 2024. All rights reserved.