iT邦幫忙

第 12 屆 iT 邦幫忙鐵人賽

DAY 4
0
Elastic Stack on Cloud

Python&Elasticsearch 入門系列 第 4

IT鐵人第4天 建立第一個Elasticsearch叢集

這篇將教大家如何用docker建立自己的Elasticsearch叢集
關於docker的一些基本用法在篇不會多做解釋,可能需要大家自己去google
容器至少需要4GB的RAM。Windows和Mac用戶必須將其Docker虛擬機配置為具有默認的2GB以上的RAM:
https://ithelp.ithome.com.tw/upload/images/20200903/201299764n5TcAc7j8.png
Linux用戶則要用root權限執行

sysctl -w vm.max_map_count=262144

sudo vim /etc/sysctl.conf
加入vm.max_map_count=262144

1.建立一個docker-compose.yml

version: '2.2'
services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0 #後面可以調整版本,這邊用7.9.0做示範
    container_name: es01
    environment:
      - node.name=es01
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es02,es03
      - cluster.initial_master_nodes=es01
      - bootstrap.memory_lock=true
      - "http.cors.allow-origin=*"
      - "http.cors.enabled=true"
      - "discovery.zen.minimum_master_nodes=2"
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m" #這邊可以調整要分配多少heap給ES,最好不要超過本機RAM的一半
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200 #設定port,預設是9200
    networks:
      - elastic
  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.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
      - "http.cors.allow-origin=*"
      - "http.cors.enabled=true"
      - "discovery.zen.minimum_master_nodes=2"
      - "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.9.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
      - "http.cors.allow-origin=*"
      - "http.cors.enabled=true"
      - "discovery.zen.minimum_master_nodes=2"
      - "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

想了解更多可以參考官方文件或者Github
https://www.elastic.co/guide/en/elastic-stack-get-started/current/get-started-docker.html
https://github.com/deviantony/docker-elk
https://github.com/elastic/stack-docker
之後網址打上http://127.0.0.1:9200/
看到下面圖片的內容就是成功了
https://ithelp.ithome.com.tw/upload/images/20200903/20129976hK7sQJxEOv.png
或者下這行指令檢查

curl http://localhost:9200/_cat/nodes

上一篇
IT鐵人第3天 Elasticsearch簡單介紹
下一篇
IT鐵人第5天 建立圖形介面elasticsearch-head、Kibana
系列文
Python&Elasticsearch 入門30

尚未有邦友留言

立即登入留言