前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ElasticSearch集群搭建

ElasticSearch集群搭建

作者头像
老梁
发布2019-09-10 17:03:28
6370
发布2019-09-10 17:03:28
举报
文章被收录于专栏:Java工程师成长之路

需求

  1. 用docker搭建一个ElasticSearch一主一从的集群,加一个elasticsearch-head查看集群状态

步骤

  1. 在参考了一堆博客后,我写了个固定容器ip的docker-compose.yml es1.yml
代码语言:javascript
复制
network.bind_host: 0.0.0.0
cluster.name: es_cluster
node.name: master
node.master: true
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
#network.host: 0.0.0.0
network.publish_host: 172.20.0.2
discovery.zen.minimum_master_nodes: 1

es2.yml

代码语言:javascript
复制
network.bind_host: 0.0.0.0
cluster.name: es_cluster
node.name: node2
node.master: false
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
#network.host: 0.0.0.0
network.publish_host: 172.20.0.3
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.unicast.hosts: es1

docker-compose.yml

代码语言:javascript
复制
version: '2'
services:
  elasticsearch-central: 
    image: elasticsearch:5.6.4
    container_name: es1
    volumes:
      - /root/mydocker/docker-es/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /root/mydocker/docker-es/data1:/usr/share/elasticsearch/data
    restart: always
    environment:
      - ES_CLUSTERNAME=elasticsearch
      - "ES_JAVA_OPTS=-Xmx50m -Xms50m"
    command: elasticsearch
    ports:
      - "9200:9200"
      - "9300:9300"
    networks:
      extnetwork:
        ipv4_address: 172.20.0.2
  elasticsearch-data: 
    image: elasticsearch:5.6.4
    container_name: es2
    volumes:
      - /root/mydocker/docker-es/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /root/mydocker/docker-es/data2:/usr/share/elasticsearch/data
    restart: always
    environment:
      - ES_CLUSTERNAME=elasticsearch
      - "ES_JAVA_OPTS=-Xmx50m -Xms50m"
    command: elasticsearch
    ports:
      - "9201:9200"
      - "9301:9300"
    links:
      - elasticsearch-central:elasticsearch
    networks:
      extnetwork:
        ipv4_address: 172.20.0.3
  elasticsearch-head:
    image: mobz/elasticsearch-head:5
    container_name: head
    volumes:
      - /root/mydocker/docker-es/head-conf/Gruntfile.js:/usr/src/app/Gruntfile.js
      - /root/mydocker/docker-es/head-conf/app.js:/usr/src/app/_site/app.js
    ports:
      - "9100:9100"
    links:
      - elasticsearch-central:elasticsearch
    networks:
      extnetwork:
        ipv4_address: 172.20.0.4
networks:
  extnetwork:
    ipam:
      config:
        - subnet: 172.20.0.0/16
          gateway: 172.20.0.1

遇到的问题

  1. Caused by: java.nio.file.AccessDeniedException 这类异常原因是文件夹权限问题,把data1,data2都设置上读写权限就可以
  2. 5.0版本默认容器jvm占用2G内存,若机器内存不足也会报错Cannot allocate memory,这个问题我在脚本已经解决了 "ES_JAVA_OPTS=-Xmx50m -Xms50m" 加上,因为我只是测试玩玩,不用于生产,所以只设置了50M
  3. sysctl.conf文件修改后最好运行下 /etc/sysctl.conf 立即生效
  4. 如果你用的是elasticsearch6.0版本,又会有新的问题,详情看 https://www.elastic.co/cn/blog/strict-content-type-checking-for-elasticsearch-rest-requests

参考博客 https://blog.csdn.net/u012915455/article/details/78952068 https://blog.csdn.net/wanghao_0206/article/details/79583325 https://blog.csdn.net/hechaojie_com/article/details/83625265 https://blog.csdn.net/sinat_31908303/article/details/80496349 https://blog.csdn.net/moliyiran/article/details/53791515 https://segmentfault.com/a/1190000014283157

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-11-07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 需求
  • 步骤
  • 遇到的问题
相关产品与服务
容器镜像服务
容器镜像服务(Tencent Container Registry,TCR)为您提供安全独享、高性能的容器镜像托管分发服务。您可同时在全球多个地域创建独享实例,以实现容器镜像的就近拉取,降低拉取时间,节约带宽成本。TCR 提供细颗粒度的权限管理及访问控制,保障您的数据安全。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档