docker-compose 部署 elasticsearch 集群

目录结构

├── config                       配置目录
│   ├── es.yml                   es配置文件
│   ├── es1.yml                  es1配置文件
│   ├── es2.yml                  es2配置文件
└── docker-compose.yml           docker-compose配置文件

docker-compose.yml

version: "2"
services:
  es:
    image: elasticsearch:5.6-alpine
    container_name: es
    environment:
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - "9200:9200"
      - "9300:9300"
    volumes:
      - ./config/es.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
    networks:
      - net-es
  es1:
    image: elasticsearch:5.6-alpine
    container_name: es1
    environment:
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - "9201:9200"
      - "9301:9300"
    volumes:
      - ./config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
    networks:
      - net-es
  es2:
    image: elasticsearch:5.6-alpine
    container_name: es2
    environment:
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - "9202:9200"
      - "9302:9300"
    volumes:
      - ./config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
    networks:
      - net-es
networks:
  net-es:


es.yml

cluster.name: my-test
node.name: es
node.master: true
node.data: true

network.host: es
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"

discovery.zen.ping.unicast.hosts: ["es:9300", "es1:9300", "es2:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s

bootstrap.memory_lock: true
action.destructive_requires_name: true



es1.yml

cluster.name: my-test
node.name: es1
node.master: true
node.data: true

network.host: es1
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"

discovery.zen.ping.unicast.hosts: ["es:9300", "es1:9300", "es2:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s

bootstrap.memory_lock: true
action.destructive_requires_name: true



es2.yml

cluster.name: my-test
node.name: es2
node.master: false
node.data: true

network.host: es2
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"

discovery.zen.ping.unicast.hosts: ["es:9300", "es1:9300", "es2:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s

bootstrap.memory_lock: true
action.destructive_requires_name: true



使用


安装 docker 和 docker-compose


执行命令 docker-compose up -d


打开 chrome 浏览器的插件 ElasticSearch Head, 效果如下图 

这里写图片描述

本例子选择了 es 和 es1 为 master 
若想方便看日志, 也可将 logs 挂载出来, 例如在 docker-compose.yml 中 es 的 volumes 加上 
- ./logs/es/:/usr/share/elasticsearch/logs/:rw 
同理 data 挂载出来可加上 
- ./data/es/:/usr/share/elasticsearch/data/:rw

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值