ToB企服应用市场:ToB评测及商务社交产业平台

标题: Docker下elasticsearch8部署、扩容、基本操作实战(含kibana) [打印本页]

作者: 祗疼妳一个    时间: 2023-8-30 13:18
标题: Docker下elasticsearch8部署、扩容、基本操作实战(含kibana)
欢迎访问我的GitHub

这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos
本篇概览

环境信息

准备工作

部署es

  1. docker network create elastic
复制代码
  1. docker run \
  2. --name es01 \
  3. --net elastic \
  4. -p 9200:9200 \
  5. -e ES_JAVA_OPTS="-Xms1024m -Xmx1024m" \
  6. -idt elasticsearch:8.2.2
复制代码
  1. docker exec -it es01 /bin/bash
复制代码
  1. bin/elasticsearch-reset-password -u elastic
复制代码
  1. Password for the [elastic] user successfully reset.
  2. New value: 3_J35UWr2sIUkyxxxxxx
复制代码




部署和操作kibana

  1. docker run \
  2. --name kibana \
  3. --net elastic \
  4. -p 5601:5601 \
  5. -idt kibana:8.2.2
复制代码
  1. docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana
复制代码


  1. docker exec -it kibana bin/kibana-verification-code
复制代码



集群扩容

  1. docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node
复制代码
  1. docker run \
  2. -e ENROLLMENT_TOKEN="xxxxxx" \
  3. -e ES_JAVA_OPTS="-Xms1024m -Xmx1024m" \
  4. --name es02 \
  5. --net elastic \
  6. -idt elasticsearch:8.2.2
复制代码

实战es操作:命令行操作

  1. docker cp es01:/usr/share/elasticsearch/config/certs/http_ca.crt .
复制代码
  1. curl --cacert http_ca.crt -u elastic:xxxxxx https://localhost:9200
复制代码
  1. ❯ curl --cacert http_ca.crt -u elastic:xxxxxx https://localhost:9200
  2. {
  3.   "name" : "279acdab6c7f",
  4.   "cluster_name" : "docker-cluster",
  5.   "cluster_uuid" : "whfRDTzCQym_jwx2OrMgKg",
  6.   "version" : {
  7.     "number" : "8.2.2",
  8.     "build_flavor" : "default",
  9.     "build_type" : "docker",
  10.     "build_hash" : "9876968ef3c745186b94fdabd4483e01499224ef",
  11.     "build_date" : "2022-05-25T15:47:06.259735307Z",
  12.     "build_snapshot" : false,
  13.     "lucene_version" : "9.1.0",
  14.     "minimum_wire_compatibility_version" : "7.17.0",
  15.     "minimum_index_compatibility_version" : "7.0.0"
  16.   },
  17.   "tagline" : "You Know, for Search"
  18. }
复制代码
  1. curl -X PUT "https://localhost:9200/my-book?pretty" \
  2. --cacert http_ca.crt \
  3. -u elastic:xxxxxx \
  4. -H 'Content-Type: application/json' \
  5. -d'
  6. {
  7.   "settings": {
  8.     "number_of_shards": 1
  9.   },
  10.   "mappings": {
  11.     "properties": {
  12.                 "line_id": {
  13.                     "type": "long"
  14.                    },
  15.                 "line_number": {
  16.                      "type": "keyword"
  17.                 },
  18.                "play_name": {
  19.                     "type": "keyword"
  20.                },
  21.                "speaker": {
  22.                     "type": "keyword"
  23.                },
  24.                "speech_number": {
  25.                     "type": "long"
  26.                },
  27.                "text_entry": {
  28.                     "type": "text"
  29.                }
  30.           }
  31.   }
  32. }
  33. '
复制代码
  1. {
  2.   "acknowledged" : true,
  3.   "shards_acknowledged" : true,
  4.   "index" : "my-book"
  5. }
复制代码

  1. ❯ curl -X GET \
  2. https://localhost:9200/my-book\?pretty \
  3. --cacert http_ca.crt \
  4. -u elastic:m9ZRFl9wCIiVkLudRopy
  5. {
  6.   "my-book" : {
  7.     "aliases" : { },
  8.     "mappings" : {
  9.       "properties" : {
  10.         "line_id" : {
  11.           "type" : "long"
  12.         },
  13.         "line_number" : {
  14.           "type" : "keyword"
  15.         },
  16.         "play_name" : {
  17.           "type" : "keyword"
  18.         },
  19.         "speaker" : {
  20.           "type" : "keyword"
  21.         },
  22.         "speech_number" : {
  23.           "type" : "long"
  24.         },
  25.         "text_entry" : {
  26.           "type" : "text"
  27.         }
  28.       }
  29.     },
  30.     "settings" : {
  31.       "index" : {
  32.         "routing" : {
  33.           "allocation" : {
  34.             "include" : {
  35.               "_tier_preference" : "data_content"
  36.             }
  37.           }
  38.         },
  39.         "number_of_shards" : "1",
  40.         "provided_name" : "my-book",
  41.         "creation_date" : "1653811101586",
  42.         "number_of_replicas" : "1",
  43.         "uuid" : "zX8kWS_IQ-ymdI7vYLOjew",
  44.         "version" : {
  45.           "created" : "8020299"
  46.         }
  47.       }
  48.     }
  49.   }
  50. }
复制代码
  1. curl -H 'Content-Type: application/x-ndjson' \
  2. --cacert http_ca.crt \
  3. -u elastic:m9ZRFl9wCIiVkLudRopy \
  4. -s -XPOST https://localhost:9200/_bulk \
  5. --data-binary @shakespeare_only_one_type.json
复制代码
操作kibana




欢迎关注博客园:程序员欣宸

学习路上,你不孤单,欣宸原创一路相伴...

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4