Windows系统下使用docker安装elasticsearch和kibana

windows环境搭建专栏🔗点击跳转

Windows系统下使用docker安装elasticsearch和kibana

文章目录

能使用这篇文章的前提是你的window电脑已经安装了docker,若没有docker,请参考我的一篇文章《Windows使用wsl2安装docker教程》,把docker安装一下。若已经有了docker,请往下看。如果你下载的时候感觉拉取镜像很慢,可以参考我这一篇文章《Windows给docker设置阿里源》,把你的docker换成阿里镜像,就会拉取地快一点。

本文将用一个dockers-compose.yaml同时安装elasticsearch和kibana的7版本服务。

现在,打开cmd让我们开始吧!

1.新建文件夹

bash 复制代码
mkdir D:\App\docker\elasticsearch

2.新建elasticsearch.yml

bash 复制代码
mkdir D:\App\docker\elasticsearch\elasticsearch\config
bash 复制代码
vim D:\App\docker\elasticsearch\elasticsearch\config\elasticsearch.yml

内容如下

yaml 复制代码
cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.cors.allow-origin: "*"
http.cors.enabled: true
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

3.新建kibana.yml

bash 复制代码
mkdir D:\App\docker\elasticsearch\kibana\config
bash 复制代码
vim D:\App\docker\elasticsearch\kibana\config\kibana.yml

内容如下

yaml 复制代码
#
# ** THIS IS AN AUTO-GENERATED FILE **
#

# Default Kibana configuration for docker target
server.host: "0.0.0.0"
server.shutdownTimeout: "5s"
elasticsearch.hosts: [ "http://elasticsearch:9200" ]
monitoring.ui.container.elasticsearch.enabled: true
i18n.locale: "zh-CN"

4.创建docker-compose.yaml

bash 复制代码
cd D:\App\docker\elasticsearch
bash 复制代码
vim docker-compose.yaml

为防止格式错乱可以用粘贴模式粘贴

bash 复制代码
:set paste

docker-compose.yaml内容如下

yaml 复制代码
version: '3.8'
services:
  elasticsearch:
    container_name: elasticsearch
    image: elasticsearch:7.17.1
    ports:
      - 9200:9200
      # 将宿主机的 9200 端口映射到容器的 9200 端口,用于访问 Elasticsearch HTTP API
      - 9300:9300
      # 将宿主机的 9300 端口映射到容器的 9300 端口,用于 Elasticsearch 节点之间的通信
    restart: no
    environment:
      - discovery.type=single-node
      # 设置 Elasticsearch 的发现类型为单节点
      - ES_JAVA_OPTS=-Xms1024m -Xmx1024m
      # 设置 Elasticsearch 的 Java 虚拟机选项,分配 256MB 堆内存
    volumes:
      - ./elasticsearch/logs:/usr/share/elasticsearch/logs
      # 挂载日志目录
      - ./elasticsearch/data:/usr/share/elasticsearch/data
      # 挂载数据目录
      - ./elasticsearch/plugins:/usr/share/elasticsearch/plugins
      # 挂载插件目录
      - ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      # 挂载配置文件
  kibana:
    container_name: kibana
    restart: no
    image: kibana:7.17.1
    ports:
      - 5601:5601
      # 将宿主机的 5601 端口映射到容器的 5601 端口,用于访问 Kibana Web 界面
    depends_on:
      - elasticsearch
      # 定义依赖关系,表示 Kibana 服务依赖于 Elasticsearch 服务
    volumes:
      - ./kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml
      # 挂载配置

5.启动

bash 复制代码
docker compose up -d

6.验证

6.1 elasticsearch

访问http://localhost:9200/

获得如下内容,证明es正常。

json 复制代码
{
  "name" : "9081ec6ae5f7",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "UlpEtChjRaGeWb2l9aWWyA",
  "version" : {
    "number" : "7.17.1",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "e5acb99f822233d62d6444ce45a4543dc1c8059a",
    "build_date" : "2022-02-23T22:20:54.153567231Z",
    "build_snapshot" : false,
    "lucene_version" : "8.11.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

6.2 kibana

访问http://localhost:5601/app/dev_tools#/console

执行

json 复制代码
GET _search
{
  "query": {
    "match_all": {}
  }
}

获得如下数据,证明kibana成功连接elasticsearch,并且成功启动。

json 复制代码
#! Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.17/security-minimal-setup.html to enable security.
#! this request accesses system indices: [.apm-agent-configuration, .apm-custom-link, .kibana_7.17.1_001, .kibana_task_manager_7.17.1_001, .tasks], but in a future major version, direct access to system indices will be prevented by default
{
  "took" : 8,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },}}
......
相关推荐
资源大佬星 课it9 小时前
重学C++ ,重构你的C++知识体系
vue.js·docker·django
Elasticsearch9 小时前
AI 整合:为什么平台将胜出,而产品组合将瓦解
elasticsearch
七牛开发者10 小时前
为什么 Go 很适合 AI 辅助开发?
数据库·人工智能·python·elasticsearch·log4j
Aphelios38010 小时前
一次锁内网络IO引发的Tomcat线程池“饿死”事故
java·开发语言·spring boot·elasticsearch·tomcat·网络io阻塞·线程池耗尽
用户9385156350712 小时前
Docker + Nginx + Node.js:从“我的电脑能跑,你的电脑跑不了”到一键部署
后端·nginx·docker
笨鸟先飞,勤能补拙13 小时前
从预测到决策:人工智能与机器学习的系统方法、工程闭环与现实边界
大数据·人工智能·windows·python·机器学习·密码学
程序员-李俞13 小时前
Mistral OCR 4真正改变的不是“识字”:文档AI正在变成Agent的数据入口
人工智能·windows·ai作画·aigc·ocr·ai编程·ai写作
C++ 老炮儿的技术栈15 小时前
Qt5.9.1 Windows 完整开发环境搭建流程
开发语言·c++·windows·qt·编辑器·代码化
笨鸟先飞,勤能补拙15 小时前
AI与深度学习:从原理到应用
人工智能·windows·vscode·深度学习·机器学习·网络安全·github
bkspiderx16 小时前
从零开始:VS Code搭建C/C++开发环境全指南(Windows/macOS/Linux)
c语言·c++·windows·vs code·c/c++开发环境