Install ElasticSearch8.7 with Docker(include kibana & ElasticSearch-Head plugins)

创建网络-拉取镜像-启动es
docker network create elastic
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.7.1
docker run --name es-node01 --net elastic -p 9200:9200 -p 9300:9300 -t docker.elastic.co/elasticsearch/elasticsearch:8.7.1
第一次启动es时会生成elastic用户密码和kibana密码-在控制台,注意保存

eg:


━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ 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`):
  UkshFkxayFHiVZaisZzp

ℹ️  HTTP CA certificate SHA-256 fingerprint:
  7662d86bd72a75c868b279f04b8ac55ca03d05b7b67c83691c3427f41d64708e

ℹ️  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):
  eyJ2ZXIiOiI4LjcuMSIsImFkciI6WyIxNzIuMTguMC4yOjkyMDAiXSwiZmdyIjoiNzY2MmQ4NmJkNzJhNzVjODY4YjI3OWYwNGI4YWM1NWNhMDNkMDViN2I2N2M4MzY5MWMzNDI3ZjQxZDY0NzA4ZSIsImtleSI6ImZXZE1QSWdCTWJoenoyMHU5d01TOmdaTWxTalNrU2VhOHRZVWNKRV9QdmcifQ==

ℹ️ 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):
  eyJ2ZXIiOiI4LjcuMSIsImFkciI6WyIxNzIuMTguMC4yOjkyMDAiXSwiZmdyIjoiNzY2MmQ4NmJkNzJhNzVjODY4YjI3OWYwNGI4YWM1NWNhMDNkMDViN2I2N2M4MzY5MWMzNDI3ZjQxZDY0NzA4ZSIsImtleSI6ImUyZE1QSWdCTWJoenoyMHU5Z1A1OlpVd2xsdjlrUWRLaG9lOTlGUU9QVGcifQ==

  If you're running in Docker, copy the enrollment token and run:
  `docker run -e "ENROLLMENT_TOKEN=<token>" docker.elastic.co/elasticsearch/elasticsearch:8.7.1`
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

测试es 是否启动成功

访问 https:localhost:9200 用户名: elastic 密码: UkshFkxayFHiVZaisZzp

如下,表示启动成功

{
  "name" : "cc6f963c54d6",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "yPMHDO_WRbmITRhIJjtFZw",
  "version" : {
    "number" : "8.7.1",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "f229ed3f893a515d590d0f39b05f68913e2d9b53",
    "build_date" : "2023-04-27T04:33:42.127815583Z",
    "build_snapshot" : false,
    "lucene_version" : "9.5.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

安装kibana
拉取kibana 镜像-启动kibana (注意kibana版本要与elasticsearch保持一致)
docker pull docker.elastic.co/kibana/kibana:8.7.1
docker run --name kib-01 --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:8.7.1
  • 控制台会生成一个访问连接 点击访问
Go to http://0.0.0.0:5601/?code=724665 to get started.

访问: http://0.0.0.0:5601/?code=724665 (code 每次会变)

输入es启动时保存的token (• Run Kibana and click the configuration link in the terminal when Kibana starts.)

ℹ️  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):
  eyJ2ZXIiOiI4LjcuMSIsImFkciI6WyIxNzIuMTguMC4yOjkyMDAiXSwiZmdyIjoiNzY2MmQ4NmJkNzJhNzVjODY4YjI3OWYwNGI4YWM1NWNhMDNkMDViN2I2N2M4MzY5MWMzNDI3ZjQxZDY0NzA4ZSIsImtleSI6ImZXZE1QSWdCTWJoenoyMHU5d01TOmdaTWxTalNrU2VhOHRZVWNKRV9QdmcifQ==

输入用户名/密码(用户名: elastic 密码: UkshFkxayFHiVZaisZzp)
  • 导入测试数据 — 点击 try sample data - other sample data sets -> add data;

  • 查看数据-》 导航书签栏找到DashBoard - 就可以查看你刚刚导入的测试数据了

安装multi elasticsearch head 插件(谷歌商店)
/config/elasticsearch.yml 配置如下:

cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.cors.allow-headers: Authorization,X-Requested-With,Content-Type,Content-Length

#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically
# generated to configure Elasticsearch security features on 21-05-2023 03:13:20
#
# --------------------------------------------------------------------------------

# Enable security features
xpack.security.enabled: true

xpack.security.enrollment.enabled: true

# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
  enabled: true
  keystore.path: certs/http.p12

# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
  enabled: true
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12
# Create a new cluster with the current node only
# Additional nodes can still join the cluster later
cluster.initial_master_nodes: ["cc6f963c54d6"]

#----------------------- END SECURITY AUTO CONFIGURATION -------------------------
过程中常见错误以及解决方案
  • 修改配置文件,命令找不到
1. bash: vim: command not found

  • resolve
+ root 用户进入容器

docker exec -ti --user root {容器名}  /bin/bash

apt-get update 
apt-get install vim

  • 参考:

https://www.elastic.co/guide/en/kibana/current/docker.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章