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
  },}}
......
相关推荐
2501_925435521 小时前
如何关闭 Windows Defender 病毒和威胁防护(临时或永久)
windows
前端若水1 小时前
Windows 系统安装pyenv
windows
Elastic 中国社区官方博客1 小时前
Elastic 开源社区行为准则
大数据·elasticsearch·搜索引擎·信息可视化·全文检索
AxureMost1 小时前
免费商用级虚拟机,26H1 版本实测
windows
皓月盈江1 小时前
Linux Ubuntu系统如何编辑Docker容器内的文件
linux·ubuntu·docker·容器·靶场·vulhub·编辑docker内文件
魔极客1 小时前
1panel面板安装ollama的详细过程
docker·1panel·ollama
椰汁菠萝2 小时前
[特殊字符] Nginx UI:Docker 部署与完全使用指南
nginx·ui·docker
csdn小瓯2 小时前
CI/CD流水线搭建:GitHub Actions + Docker + Railway自动化部署实战
ci/cd·docker·github
不能隔夜的咖喱3 小时前
黑马ai大模型笔记(自用,比较粗糙)
linux·windows·python
jio本小子3 小时前
Windows 安装 Java17 + Maven + MySQL 开发环境教程,全程安装到 D 盘
windows·mysql·maven