ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ElasticSearch入门(环境准备)

2022-07-10 01:32:08  阅读:276  来源: 互联网

标签:00 入门 elastic 环境 Kibana token elasticsearch ElasticSearch docker


ElasticSearch入门

使用 Docker 安装 Elasticsearch

  1. 拉取 Elasticsearch Docker 镜像
docker pull elasticsearch:8.3.2
  1. 创建docker网络
docker network create elastic

## 查看docker网络
docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
83d43e14bbf3   bridge    bridge    local
9ea9b7c276a2   elastic   bridge    local
fbe0d6656c86   host      host      local
322f0edb4c2c   none      null      local
  1. 使用 Docker 启动单节点集群
docker run --name es01 --net elastic -p 9200:9200 -p 9300:9300 -it elasticsearch:8.3.2

注意:初期启动时会自动生成下列信息,保存好,后面会用到。

如果您在 Docker 容器中启动单节点 Elasticsearch 集群,则会自动为您启用和配置安全性。首次启动 Elasticsearch 时,会自动进行以下安全配置:

  • 为传输层和 HTTP 层生成 证书和密钥。
  • 传输层安全 (TLS) 配置设置被写入 elasticsearch.yml.
  • elastic用户生成密码。
  • 为 Kibana 生成一个注册令牌。
----------------------------------------------------------------------------------------------------------------------------------------------------------------
-> Elasticsearch security features have been automatically configured!
-> Authentication is enabled and cluster connections are encrypted.

->  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  KMPApi+4XA***UAvWp

->  HTTP CA certificate SHA-256 fingerprint:
  90***56d***91e5a3c1d1190b******41b955f51e3e7c4998d3

->  Configure Kibana to use this cluster:
* Run Kibana and click the configuration link in the terminal when Kibana starts.
* Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
  e********iI4LjMuMiIsImFkciI6WyIxNzIuMTguMC4yOjkyMDAiXSwiZmdyIjoiOTA4ZjRmNTZkMjhjZDRkYWZmMjkxZTVhM2MxZDExOTBiMWZjNTY4ZTkzMWY0MWI5NTVmNTFlM2U3YzQ5OThkMyIsImtleSI6IkdVSEY0NEVCZjFSVDlTRHpSeGFoOjlJbGhnbmlDUVJHNlJWN2c5T0ZXS3cifQ==

-> Configure other nodes to join this cluster:
* Copy the following enrollment token and start new Elasticsearch nodes with `bin/elasticsearch --enrollment-token <token>` (valid for the next 30 minutes):
  e*********************************6WyIxNzIuMTguMC4yOjkyMDAiXSwiZmdyIjoiOTA4ZjRmNTZkMjhjZDRkYWZmMjkxZTVhM2MxZDExOTBiMWZjNTY4ZTkzMWY0MWI5NTVmNTFlM2U3YzQ5OThkMyIsImtleSI6IkYwSEY0NEVCZjFSVDlTRHpSeGFlOm9iOXU0bzNiUW1TVkJDenY0WUtPdmcifQ==

  If you're running in Docker, copy the enrollment token and run:
  `docker run -e "ENROLLMENT_TOKEN=<token>" docker.elastic.co/elasticsearch/elasticsearch:8.3.2`
----------------------------------------------------------------------------------------------------------------------------------------------------------------
  1. 下载证明书
docker cp es01:/usr/share/elasticsearch/config/certs/http_ca.crt .
  1. 访问elasticsearch
curl --cacert http_ca.crt -u elastic https://localhost:9200
Enter host password for user 'elastic':
## 输入密码(第三步取得)
## 显示下面信息表示成功启动
{
  "name" : "9a*******",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "58ez*********lhuQ",
  "version" : {
    "number" : "8.3.2",
    "build_type" : "docker",
    "build_hash" : "8b0b1f2****************4fd",
    "build_date" : "2022-07-06T15:15:15.901688194Z",
    "build_snapshot" : false,
    "lucene_version" : "9.2.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}
  • 重置密码方法
docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-reset-password
  • 安全性

从 Elasticsearch 8.0 开始,默认启用安全性。启用安全性后,Elastic Stack 安全功能需要对传输网络层进行 TLS 加密,否则您的集群将无法启动。

使用 Docker 安装 Kibana编辑

  1. 拉取kibana镜像
docker pull docker.elastic.co/kibana/kibana:8.3.2
  1. 启动kibanan
docker run --name kib-01 --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:8.3.2

当您启动 Kibana 时,一个唯一的链接会输出到您的终端。

[2022-07-09T16:56:25.376+00:00][INFO ][plugins-service] Plugin "cloudSecurityPosture" is disabled.
[2022-07-09T16:56:25.432+00:00][INFO ][http.server.Preboot] http server running at http://0.0.0.0:5601
[2022-07-09T16:56:25.455+00:00][INFO ][plugins-system.preboot] Setting up [1] plugins: [interactiveSetup]
[2022-07-09T16:56:25.457+00:00][INFO ][preboot] "interactiveSetup" plugin is holding setup: Validating Elasticsearch connection configuration…
[2022-07-09T16:56:25.472+00:00][INFO ][root] Holding setup until preboot stage is completed.


i Kibana has not been configured.

Go to http://0.0.0.0:5601/?code=018502 to get started.

  1. 在浏览器中输入上面表示的网址【http://0.0.0.0:5601/?code=018502】

  2. 输入token情报

  3. 输入密码,即可进入kibana主页

  • 如果token过期的话, 通过下面命令可以发行新的token
docker exec -it es-node01 /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana

标签:00,入门,elastic,环境,Kibana,token,elasticsearch,ElasticSearch,docker
来源: https://www.cnblogs.com/hanchuge/p/16462394.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有