首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

使用 start-local 脚本在本地运行 Elasticsearch

  • 25-02-22 03:01
  • 3874
  • 12876
blog.csdn.net

警告:请勿将这些说明用于生产部署

本页上的说明仅适用于本地开发。请勿将此配置用于生产部署,因为它不安全。请参阅部署选项以获取生产部署选项列表。

使用 start-local 脚本在 Docker 中快速设置 Elasticsearch 和 Kibana 以进行本地开发或测试。

此设置附带一个月的试用许可证,其中包括所有 Elastic 功能。试用期过后,许可证将恢复为免费和开放 - Basic。有关更多信息,请参阅 Elastic 订阅。

更多阅读:Elasticsearch:如何在 Docker 上运行 Elasticsearch 8.x 进行本地开发

先决条件

  • 如果你尚未安装 Docker,请下载并安装适用于你的操作系统的Docker Desktop。
  • 如果你使用的是 Microsoft Windows,请安装适用于 Linux 的 Windows 子系统 (WSL)。

运行 start-local

start-local 脚本可以在地址进行下载 GitHub - elastic/start-local: Try Elasticsearch and Kibana locally。要在本地设置 Elasticsearch 和 Kibana,请运行 start-local 脚本。

curl -fsSL https://elastic.co/start-local | sh

此脚本创建一个 elastic-start-local 文件夹,其中包含:

  • docker-compose.yml:Elasticsearch 和 Kibana 的 Docker Compose 配置
  • .env:环境设置,包括 Elasticsearch 密码
  • start.sh 和 stop.sh:用于启动和停止 Elasticsearch 和 Kibana 的脚本
  • uninstall.sh:用于卸载 Elasticsearch 和 Kibana 的脚本
  1. $ pwd
  2. /Users/liuxg/data/start-local
  3. $ curl -fsSL https://elastic.co/start-local | sh
  4. ______ _ _ _
  5. | ____| | | | (_)
  6. | |__ | | __ _ ___| |_ _ ___
  7. | __| | |/ _` / __| __| |/ __|
  8. | |____| | (_| \__ \ |_| | (__
  9. |______|_|\__,_|___/\__|_|\___|
  10. -------------------------------------------------
  11. ? Run Elasticsearch and Kibana for local testing
  12. -------------------------------------------------
  13. ℹ️ Do not use this script in a production environment
  14. ⌛️ Setting up Elasticsearch and Kibana v8.15.3...
  15. - Generated random passwords
  16. - Created the elastic-start-local folder containing the files:
  17. - .env, with settings
  18. - docker-compose.yml, for Docker services
  19. - start/stop/uninstall commands
  20. - Running docker compose up --wait
  21. [+] Running 24/24
  22. ✔ kibana 13 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿] 0B/0B Pulled 62.0s
  23. ✔ 23987c61699b Pull complete 5.6s
  24. ✔ 8915ba981ca3 Pull complete 4.0s
  25. ✔ 4c8b24782cfe Pull complete 33.1s
  26. ✔ 807b2cadbcb1 Pull complete 5.3s
  27. ✔ aea2eb4e3b10 Pull complete 9.4s
  28. ✔ ab757075fe94 Pull complete 7.1s
  29. ✔ 4ca545ee6d5d Pull complete 8.5s
  30. ✔ 7e3665e2de31 Pull complete 9.8s
  31. ✔ c3055b6e09f0 Pull complete 10.9s
  32. ✔ ec8a64bd5a5f Pull complete 11.1s
  33. ✔ dfd6d27a36fe Pull complete 12.5s
  34. ✔ 17173b4bfc67 Pull complete 13.3s
  35. ✔ 2b1cd59a6503 Pull complete 14.1s
  36. ✔ kibana_settings 8 layers [⣿⣿⣿⣿⣿⣿⣿⣿] 0B/0B Pulled 66.3s
  37. ✔ 4253e52d2237 Pull complete 16.8s
  38. ✔ e436db77a937 Pull complete 15.4s
  39. ✔ 0f431d485a97 Pull complete 57.7s
  40. ✔ 8673bfa492b1 Pull complete 18.4s
  41. ✔ fab125f6f236 Pull complete 19.8s
  42. ✔ 43ad26ccf7ea Pull complete 21.8s
  43. ✔ fb6208a6757b Pull complete 23.1s
  44. ✔ 500133bff266 Pull complete 24.9s
  45. ✔ elasticsearch Pulled 66.3s
  46. [+] Building 0.0s (0/0) docker:desktop-linux
  47. [+] Running 6/6
  48. ✔ Network elastic-start-local_default Created 0.0s
  49. ✔ Volume "elastic-start-local_dev-elasticsearch" Created 0.0s
  50. ✔ Volume "elastic-start-local_dev-kibana" Cre... 0.0s
  51. ✔ Container es-local-dev Healthy 2.1s
  52. ✔ Container kibana_settings Exited 0.1s
  53. ✔ Container kibana-local-dev Healthy 0.0s
  54. ? Congrats, Elasticsearch and Kibana are installed and running in Docker!
  55. ? Open your browser at http://localhost:5601
  56. Username: elastic
  57. Password: wuRd1MYj
  58. ? Elasticsearch API endpoint: http://localhost:9200
  59. ? API key: MDBQWUpKTUJDMldQM2xRTVlqM1A6N2FyUE9WRVpSSFc4d25QNWZTYThMQQ==
  60. Learn more at https://github.com/elastic/start-local

我们首先查看一下生成的文件:

  1. $ pwd
  2. /Users/liuxg/data/start-local
  3. $ ls
  4. elastic-start-local

它创建了一个叫做 elastic-start-local 的目录。我们进入该目录进行查看:

  1. $ cd elastic-start-local/
  2. $ ls -al
  3. total 40
  4. drwxr-xr-x 7 liuxg staff 224 Nov 13 17:24 .
  5. drwxr-xr-x 3 liuxg staff 96 Nov 13 17:24 ..
  6. -rw-r--r-- 1 liuxg staff 419 Nov 13 17:26 .env
  7. -rw-r--r-- 1 liuxg staff 2434 Nov 13 17:24 docker-compose.yml
  8. -rwxr-xr-x 1 liuxg staff 1450 Nov 13 17:24 start.sh
  9. -rwxr-xr-x 1 liuxg staff 189 Nov 13 17:24 stop.sh
  10. -rwxr-xr-x 1 liuxg staff 1099 Nov 13 17:24 uninstall.sh

从上面,我们可以看到所生成的文件。我们来查看一下 .env 的文件:

.env

  1. ES_LOCAL_VERSION=8.15.3
  2. ES_LOCAL_CONTAINER_NAME=es-local-dev
  3. ES_LOCAL_PASSWORD=wuRd1MYj
  4. ES_LOCAL_URL=http://localhost:9200
  5. ES_LOCAL_PORT=9200
  6. ES_LOCAL_HEAP_INIT=128m
  7. ES_LOCAL_HEAP_MAX=2g
  8. KIBANA_LOCAL_CONTAINER_NAME=kibana-local-dev
  9. KIBANA_LOCAL_PORT=5601
  10. KIBANA_LOCAL_PASSWORD=N6IOHrSA
  11. KIBANA_ENCRYPTION_KEY=V2Q2IKYiH5YgXgeXuokzBuuZ1wuB7ygE
  12. ES_LOCAL_API_KEY=MDBQWUpKTUJDMldQM2xRTVlqM1A6N2FyUE9WRVpSSFc4d25QNWZTYThMQQ==

从上面的配置中,我们可以看出来,修改 ES_LOCAL_VERSION 可以改变 Elasticsearch 及 Kibana 的版本。在上面,我们也可以看到它配置的密码 ES_LOCAL_PASSWORD。

我们使用如下的命令来进行查看:

  1. $ docker ps
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. 4b50f85bddd3 docker.elastic.co/kibana/kibana:8.15.3 "/bin/tini -- /usr/l…" 7 minutes ago Up 7 minutes (healthy) 127.0.0.1:5601->5601/tcp kibana-local-dev
  4. a89056d65008 docker.elastic.co/elasticsearch/elasticsearch:8.15.3 "/bin/tini -- /usr/l…" 7 minutes ago Up 7 minutes (healthy) 127.0.0.1:9200->9200/tcp, 9300/tcp es-local-dev

我们可以看到有两个容器正在运行中。

我们在浏览器中打开 http://localhost:9200:

我们也可以使用如下的命令来进行查看:

  1. $ curl -u elastic:wuRd1MYj http://localhost:9200
  2. {
  3. "name" : "a89056d65008",
  4. "cluster_name" : "docker-cluster",
  5. "cluster_uuid" : "T4kEFaxvTkC8R9j4wW4A3w",
  6. "version" : {
  7. "number" : "8.15.3",
  8. "build_flavor" : "default",
  9. "build_type" : "docker",
  10. "build_hash" : "f97532e680b555c3a05e73a74c28afb666923018",
  11. "build_date" : "2024-10-09T22:08:00.328917561Z",
  12. "build_snapshot" : false,
  13. "lucene_version" : "9.11.1",
  14. "minimum_wire_compatibility_version" : "7.17.0",
  15. "minimum_index_compatibility_version" : "7.0.0"
  16. },
  17. "tagline" : "You Know, for Search"
  18. }

我们也可以在浏览器中打入地址 http://localhost:5601:

我们成功地进入到 Kibana 的界面了。

警告:HTTPS 已禁用,并且对 Elasticsearch 使用基本身份验证。此配置仅用于本地测试。出于安全考虑,Elasticsearch 和 Kibana 只能通过 localhost 访问。

API keys

生成 Elasticsearch 的 API 密钥并将其作为 ES_LOCAL_API_KEY 存储在 .env 文件中。使用此密钥通过 Elastic SDK 或 REST API 连接到 Elasticsearch。

在 elastic-start-local 文件夹中使用 curl 检查与 Elasticsearch 的连接:

  1. source .env
  2. curl $ES_LOCAL_URL -H "Authorization: ApiKey ${ES_LOCAL_API_KEY}"
  1. $ source .env
  2. $ curl $ES_LOCAL_URL -H "Authorization: ApiKey ${ES_LOCAL_API_KEY}"
  3. {
  4. "name" : "a89056d65008",
  5. "cluster_name" : "docker-cluster",
  6. "cluster_uuid" : "T4kEFaxvTkC8R9j4wW4A3w",
  7. "version" : {
  8. "number" : "8.15.3",
  9. "build_flavor" : "default",
  10. "build_type" : "docker",
  11. "build_hash" : "f97532e680b555c3a05e73a74c28afb666923018",
  12. "build_date" : "2024-10-09T22:08:00.328917561Z",
  13. "build_snapshot" : false,
  14. "lucene_version" : "9.11.1",
  15. "minimum_wire_compatibility_version" : "7.17.0",
  16. "minimum_index_compatibility_version" : "7.0.0"
  17. },
  18. "tagline" : "You Know, for Search"
  19. }

启动及停止服务

你可以使用 elastic-start-local 文件夹中提供的 start 和 stop 命令。

要停止 Elasticsearch 和 Kibana Docker 服务,请使用 stop 命令:

  1. cd elastic-start-local
  2. ./stop.sh
  1. $ pwd
  2. /Users/liuxg/data/start-local/elastic-start-local
  3. $ ls
  4. docker-compose.yml start.sh stop.sh uninstall.sh
  5. $ ./stop.sh
  6. [+] Stopping 3/3
  7. ✔ Container kibana-local-dev Stopped 0.2s
  8. ✔ Container kibana_settings Stopped 0.0s
  9. ✔ Container es-local-dev Stopped 2.6s
  10. $ docker ps
  11. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

要启动 Elasticsearch 和 Kibana Docker 服务,请使用 start 命令:

  1. cd elastic-start-local
  2. ./start.sh
  1. $ pwd
  2. /Users/liuxg/data/start-local/elastic-start-local
  3. $ ls
  4. docker-compose.yml start.sh stop.sh uninstall.sh
  5. $ ./start.sh
  6. [+] Building 0.0s (0/0) docker:desktop-linux
  7. [+] Running 3/3
  8. ✔ Container es-local-dev Healthy 0.0s
  9. ✔ Container kibana_settings Exited 0.0s
  10. ✔ Container kibana-local-dev Healthy 0.0s
  11. $ docker ps
  12. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  13. 4b50f85bddd3 docker.elastic.co/kibana/kibana:8.15.3 "/bin/tini -- /usr/l…" 19 minutes ago Up 23 seconds (healthy) 127.0.0.1:5601->5601/tcp kibana-local-dev
  14. a89056d65008 docker.elastic.co/elasticsearch/elasticsearch:8.15.3 "/bin/tini -- /usr/l…" 19 minutes ago Up 34 seconds (healthy) 127.0.0.1:9200->9200/tcp, 9300/tcp es-local-dev

从上面,我们可以看到容器已经被成功运行。

如果你需要配置 HTTPS,你需要阅读文章 “如何在 Linux,MacOS 及 Windows 上进行安装 Elasticsearch”。

Elastic搜索
微信公众号
Elastic 是专注搜索的公司。Elasticsearch
注:本文转载自blog.csdn.net的Elastic 中国社区官方博客的文章"https://elasticstack.blog.csdn.net/article/details/143747798"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top