其他分享
首页 > 其他分享> > ElasticSearch入门(环境准备)

ElasticSearch入门(环境准备)

作者:互联网

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 时,会自动进行以下安全配置:

----------------------------------------------------------------------------------------------------------------------------------------------------------------
-> 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主页

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