ElasticSearch集羣搭建

需求

  1. 用docker搭建一個ElasticSearch一主一從的集羣,加一個elasticsearch-head查看集羣狀態

步驟

  1. 在參考了一堆博客後,我寫了個固定容器ip的docker-compose.yml
    es1.yml
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.ymljava

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.ymlnode

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版本,又會有新的問題,詳情看docker

    https://www.elastic.co/cn/blog/strict-content-type-checking-for-elasticsearch-rest-requestssegmentfault

參考博客
https://blog.csdn.net/u012915455/article/details/78952068
https://blog.csdn.net/wanghao_0206/article/details/79583325
http://www.javashuo.com/article/p-aduealvv-bh.html
https://blog.csdn.net/sinat_31908303/article/details/80496349
https://blog.csdn.net/moliyiran/article/details/53791515
http://www.javashuo.com/article/p-tgvigged-gw.htmlapp

相關文章
相關標籤/搜索