Coding人生小筆記

用 Docker 架設 Elasticsearch + Kibana

用 Docker 架設 Elasticsearch + Kibana

========================

github直接下載也可以

========================

1.新增兩個檔案

檔名為docker-compose.yml

version: '2.2'
services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.14.1
    restart: on-failure
    container_name: es01
    environment:
      - node.name=es01
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es02
      - cluster.initial_master_nodes=es01,es02
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - elastic
  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.14.1
    container_name: es02
    depends_on:
      - "es01"
    restart: on-failure
    environment:
      - node.name=es02
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01
      - cluster.initial_master_nodes=es01,es02
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data02:/usr/share/elasticsearch/data
    ports:
      - 9201:9200
    networks:
      - elastic
  kibana:
    image: docker.elastic.co/kibana/kibana:7.14.1
    container_name: kibana
    depends_on:
      - "es02"
    restart: on-failure
    volumes:
      - ./kibana.yml:/usr/share/kibana/config/kibana.yml
    networks:
      - elastic
    ports:
      - 5601:5601

volumes:
  data01:
    driver: local
  data02:
    driver: local

networks:
  elastic:
    driver: bridge

檔名為kibana.yml

server.name: kibana
server.host: 0.0.0.0
elasticsearch.hosts: ["http://es01:9200", "http://es02:9200"]
monitoring.enabled: true

2.輸入指令:

docker-compose up

image

等待架設~~~~

3.錯誤解決:

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

先要切換到root;

然後可以執行以下命令,設置 vm.max_map_count ,但是重啟後又會恢復為預設值。

sysctl -w vm.max_map_count=262144

持久性的做法是在 /etc/sysctl.conf 文件中修改 vm.max_map_count 參數

echo "vm.max_map_count=262144" > /etc/sysctl.conf
sysctl -p

3.開啟瀏覽器:

PS.如果剛開始會出現error

image

等它跑一下後, image

瀏覽器網址輸入:

http://<IP位址>:9200/

或是

http://localhost:9200/

出現以下這個畫面就是Elasticsearch伺服器啟動了~

image

瀏覽器網址再輸入:

http://<IP位址>:5601/

或是

http://localhost:5601/

就可以進入到Kibana圖形化介面囉~~

image