Use Docker to build Es cluster

Use Docker to build Es cluster

Refer to official documentation

Note: Set the startup size of the Docker Engine to 4 GB if one or two of the three nodes fail to start

StackOverflow Same problem link: link

Docker Compose

Docker compose: compose can be simply known as a yamL configuration file through which you can set the configuration of multiple services to run, my own understand it is regarded as a Docker script, multiple Docker container startup into a file.

So let's take two examples, the compose example
Service building
version: '3'
services:
  Specify the service name
  db:
    # specify the mirror used by the service
    image: Mysql: 5.7
    # specify the container name
    container_name: mysql
    # specify the port on which the service runs
    ports:
      - 3306: 3306
    # specify the files to be mounted in the container
    volumes:
      - /mydata/mysql/log:/var/log/mysql
      - /mydata/mysql/data:/var/lib/mysql
      - /mydata/mysql/conf:/etc/mysql
    Specify the container's environment variables
    environment:
      - MYSQL_ROOT_PASSWORD=root
  Specify the service name
  mall-tiny-docker-compose:
    # specify the mirror used by the service
    image: Mall - tiny/mall - tiny - docker - compose: 0.0.1 - the SNAPSHOT
    # specify the container name
    container_name: mall-tiny-docker-compose
    # specify the port on which the service runs
    ports:
      - 8080: 8080
    # specify the files to be mounted in the container
    volumes:
      - /etc/localtime:/etc/localtime
      - /mydata/app/mall-tiny-docker-compose/logs:/var/logs


Copy the code
Es Cluster Construction
version: '2.2'
services:
  es01:
    image: Docker. Elastic. Co/elasticsearch/elasticsearch: 7.12.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
      Set the vm memory
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      System memory usage is unlimited
      memlock:
        soft: - 1
        hard: - 1
    volumes:
      - data01:/usr/share/elasticsearch/data
    ports:
      - 9200: 9200
    networks:
      - elastic
  es02:
    image: Docker. Elastic. Co/elasticsearch/elasticsearch: 7.12.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:
      - data02:/usr/share/elasticsearch/data
    networks:
      - elastic
  es03:
    image: Docker. Elastic. Co/elasticsearch/elasticsearch: 7.12.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:
      - data03:/usr/share/elasticsearch/data
    networks:
      - elastic

volumes:
  data01:
    driver: local
  data02:
    driver: local
  data03:
    driver: local

networks:
  elastic:
    driver: bridge
    
Copy the code

Next, you just need to run docker-compose up in the project directory to see docker start building the image and starting the service

Use docker-compose up -d if you need to start in backend daemon mode

Docker-compose Down to stop a running container

Docker-compose build rebuilds the container

Docker-compose ps views the container state mapping port

Use curl or enter the url in your browser to check whether the link is successful

Docker container IK word segmentation plugin installed

There are two ways to install plug-ins that need to go inside the container: First, use the Docker desktop application to go inside the container

The second uses the command line to get inside the container.

Docker ps command to view the running container. 2. Docker exec it dockerId /bin/bash Go to the inside of the container and use bashCopy the code

Github IK ik ik ik ik ik ik ik ik Note that the version number of the IK word should be matched with the ES version number. If I use the IK plugin, the version number is V7.10.0.

./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.10.0/elasticsearch-analysis-ik-7.10.0.zip
Copy the code

Reference blog:

Use Docker to quickly deploy Elasticsearch clusters

Deploy multiple ElasticSearch nodes on a single server

Docker-compose Get started with Docker Compose