采用docker-compose搭建Elasticsearch集群

Posted niewx5201314

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了采用docker-compose搭建Elasticsearch集群相关的知识,希望对你有一定的参考价值。

首先安装docker-compose

在主节点创建一个目录es,并创建docker-compose.yaml,主节点yaml文件如下

version: ‘2‘

services:

  elasticsearch:

    image: docker.elastic.co/elasticsearch/elasticsearch:6.6.2

    privileged: true

    environment:

      - cluster.name=docker-cluster

      - xpack.security.enabled=false

      - bootstrap.memory_lock=true

      - node.master=true

      - node.data=true                # store data on master

      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"  #根据机器实际来分配

      - "discovery.zen.ping.unicast.hosts=192.168.30.30"    # put your master_ip here! make sure `telnet MASTER_IP 9300` is oK

      - "transport.host=0.0.0.0"

      - "network.host=0.0.0.0"

      - node.name=esmaster

    ulimits:

      memlock:

        soft: -1

        hard: -1

      nofile:

        soft: 65536

        hard: 65536

    cap_add:

      - IPC_LOCK

    volumes:

      - /data/elasticsearch-service/data:/usr/share/elasticsearch/data

    ports:

      - 9208:9200

      - 9308:9300

network_mode: "host"

执行命令docker-compose up -d启动es,一般会报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144],可以通过sudo sysctl -w vm.max_map_count=262144设置下值

 

node节点上同样操作创建es目录,创建docker-compose.yamlnode节点yaml文件如下

version: ‘2.2‘

services:

  elasticsearch:

    image: docker.elastic.co/elasticsearch/elasticsearch:6.6.2

    privileged: true

    environment:

      - cluster.name=docker-cluster

      - xpack.security.enabled=false

      - bootstrap.memory_lock=true

      - node.master=false

      - node.data=true

      - "ES_JAVA_OPTS=-Xms12g -Xmx12g"

      - "discovery.zen.ping.unicast.hosts=192.168.30.30"    # put your master_ip here! make sure `telnet MASTER_IP 9300` is oK

    ulimits:

      memlock:

        soft: -1

        hard: -1

      nofile:

        soft: 65536

        hard: 65536

    cap_add:

      - IPC_LOCK

    volumes:

      - /data/elasticsearch-service/data:/usr/share/elasticsearch/data

    ports:

      - 9208:9200

      - 9308:9300

network_mode: "host"

 

执行命令docker-compose up -d启动es,一般会报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144],可以通过sudo sysctl -w vm.max_map_count=262144设置下值

 

执行完成后可以去master节点采用

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

1568794538 08:15:38  docker-cluster green           3         3      0   0    0    0        0             0                  -                100.0%

以上是关于采用docker-compose搭建Elasticsearch集群的主要内容,如果未能解决你的问题,请参考以下文章

基于docker-compose的 ELK5.5.1+logback 日志系统搭建

AWS Elastic Beanstalk 不支持 docker-compose.yml 吗?

使用 docker-compose 的 Elastic Beanstalk Docker 私有注册表

AWS Elastic Beanstalk 与 AMI2 和 docker-compose.yml

如何在 AWS Elastic Container Service 中使用现有的 docker-compose.yml 文件?

mysql集群搭建docker-compose方案