殁舞

导航

 

elasticsearch入门一-介绍

看完本章将了解以下几点:

  • elasticsearch集群docker方式在windows系统部署
  • chrome插件ElasticSearch Head安装

环境

Elasticsearch支持在linux、windows、macOS上运行。在此学习阶段演示使用windows10专业版1909DockerDesktop Version 2.3.0.3(无脑安装即可)搭建es集群

步骤

安装DockerDesktop

  • 下载DockerDesktop stable版
  • 无脑安装
  • 设置不开机启动
    • 右键 → settings → General → Start Docker Desktop when you log in
  • 设置内存
    • 右键 → settings → Resources → Memory:4.00 GB
  • 没FQ设置加速器
  • 重启DockerDesktop

下载es镜像

  • 下载es镜像7.7.0
docker pull elasticsearch:7.7.0
  • 查看es镜像
C:\Users\Administrator>docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
elasticsearch        7.7.0               7ec4f35ab452        3 weeks ago         757MB
nginx                alpine              89ec9da68213        5 weeks ago         19.9MB

docker任务编排

  • 创建编排文件docker-compose.yml,内容如下:
version: '2.2'
services:
  es01:
    image: elasticsearch:7.7.0
    container_name: es01
    environment:
      - node.name=es01
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es02,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
    # 修改为自定义目录
      - /E/docker/es/data01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - elastic
  es02:
    image: elasticsearch:7.7.0
    container_name: es02
    environment:
      - node.name=es02
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
        # 修改为自定义目录
      - /E/docker/es/data02:/usr/share/elasticsearch/data
    networks:
      - elastic
  es03:
    image: elasticsearch:7.7.0
    container_name: es03
    environment:
      - node.name=es03
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01,es02
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
        # 修改为自定义目录
      - /E/docker/es/data03:/usr/share/elasticsearch/data
    networks:
      - elastic

networks:
  elastic:
    driver: bridge

运行es

  • 进入编排文件docker-compose.yml所在目录下执行,大概45s左右
docker-compose up

查看效果

C:\Users\Administrator>curl http://localhost:9200/_cat/health?v
epoch      timestamp cluster           status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1591259538 08:32:18  es-docker-cluster green           3         3      0   0    0    0        0             0                  -                100.0%

C:\Users\Administrator>curl http://localhost:9200
{
  "name" : "es01",
  "cluster_name" : "es-docker-cluster",
  "cluster_uuid" : "4cOAF9dtT8Kdrr20IjaCDA",
  "version" : {
    "number" : "7.7.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "81a1e9eda8e6183f5237786246f6dced26a10eaf",
    "build_date" : "2020-05-12T02:01:37.602180Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

辅助工具

遇到的问题

任务编排中数据卷路径格式问题

  • 异常信息:Mount denied: XXXXis not a valid Windows path

  • 解决方案:路径中的\更换为/

es集群启动失败

  • 异常信息: exited with code 137

  • 解决方案: 增加Docker Desktop内存分配

posted on 2020-06-04 15:21  殁舞  阅读(382)  评论(0编辑  收藏  举报