美文网首页
wls2+docker+elasticsearch集群搭建

wls2+docker+elasticsearch集群搭建

作者: DimonHo | 来源:发表于2020-12-24 21:02 被阅读0次

    wls的安装方法请移步 工具善其事,必先利其器,WIN10 配置wsl2的开发环境

    安装 docker-compose

    1. 首先确认是否安装了docker-compose
      1.1 看是否安装了docker-compose命令
    image.png

    1.2 如果没安装,执行下面的命令安装

    sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    
    image.png

    1.3 给脚本添加可执行权限

    sudo chmod +x /usr/local/bin/docker-compose
    
    1. 创建 docker-compose.yml 文件
      2.1 创建文件
    vi docker-compose.yml
    

    2.2 在 docker-compose.yml 中添加如下内容

    version: '2.2'
    services:
      es01:
        image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
        container_name: es01
        entrypoint: ["sh", "/apps/docker-entrypoint-es-plugins.sh"]
        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
          - http.cors.enabled=true
          - http.cors.allow-origin=*
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - data01:/usr/share/elasticsearch/data
          - /apps:/apps
        ports:
          - 9200:9200
        networks:
          - elastic
      es02:
        image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
        container_name: es02
        entrypoint: ["sh", "/apps/docker-entrypoint-es-plugins.sh"]
        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
          - http.cors.enabled=true
          - http.cors.allow-origin=*
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - data02:/usr/share/elasticsearch/data
          - /apps:/apps
        networks:
          - elastic
      es03:
        image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
        container_name: es03
        entrypoint: ["sh", "/apps/docker-entrypoint-es-plugins.sh"]
        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
          - http.cors.enabled=true
          - http.cors.allow-origin=*
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - data03:/usr/share/elasticsearch/data
          - /apps:/apps
        networks:
          - elastic
      kibana:
        image: docker.elastic.co/kibana/kibana:7.10.1
        container_name: kibana
        ports:
          - 5601:5601
        volumes:
          - ./kibana/config/:/usr/local/kibana/config/
        environment:
          ELASTICSEARCH_HOSTS: http://es01:9200
          I18N_LOCALE: zh-CN
        links:
          - es01
          - es02
          - es03
        networks:
          - elastic
    volumes:
      data01:
        driver: local
      data02:
        driver: local
      data03:
        driver: local
    
    networks:
      elastic:
        driver: bridge
    

    上面的脚本在启动es集群的同时,还会去安装分词器插件,关键代码:entrypoint: ["sh", "/apps/docker-entrypoint-es-plugins.sh"],它指定了脚本路径的位置,注意这个路径是指容器中的路径,我把这个路径映射到了宿主服务器的相同目录下,即/apps,所以我们在宿主服务器的/apps目录下新建 docker-entrypoint-es-plugins.sh 脚本,这里我在脚本中安装了中文分词器,脚本内容如下:

    #!/bin/bash
    # setting up prerequisites
    
    bin/elasticsearch-plugin install --batch https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.10.1/elasticsearch-analysis-ik-7.10.1.zip
    exec /usr/local/bin/docker-entrypoint.sh elasticsearch
    
    1. docker-compose启动elasticsearch集群
    docker-compose up
    

    如果要后台启动,就在该命令后面添加参数-d


    FAQ:

    • 如果看到下面的错误日志
    image.png
    • 解决办法
      在宿主机打开 /etc/sysctl.conf 文件
    sudo vim /etc/sysctl.conf
    

    在文件中添加或修改如下内容

    vm.max_map_count = 262144
    
    image.png

    再执行

    sysctl -p
    

    制作自己的elasticsearch docker image

    1. pull基础镜像
    docker pull docker.elastic.co/elasticsearch/elasticsearch:7.10.1
    
    1. 创建 Dockerfile,最好在一个空目录下创建,我这里放在 /apps 目录下
    #---------------------------------------------------------------------
    
    # 使用基础镜像elasticsearch:7.10.1
    FROM docker.elastic.co/elasticsearch/elasticsearch:7.10.1
    
    # 指定镜像创建者信息
    MAINTAINER vampirehgg <<A href="mailto:vampirehgg@qq.com@qq.com">vampirehgg@qq.com>
    
    # 下载IK分词器
    RUN bin/elasticsearch-plugin install --batch https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.10.1/elasticsearch-analysis-ik-7.10.1.zip
    
    #---------------------------------------------------------------------
    
    
    1. login docker hub
    docker login --username=vampirehgg
    
    1. build 镜像
    docker build -t vampirehgg/elasticsearch:7.10.1 /apps
    
    1. push镜像到docker hub
    docker push vampirehgg/elasticsearch
    

    相关文章

      网友评论

          本文标题:wls2+docker+elasticsearch集群搭建

          本文链接:https://www.haomeiwen.com/subject/yclvnktx.html