docker-compose快速构建ELK本地测试环境

2022-05-13 09:40:38 浏览数 (1)

注意: 这里构建的ELK,全部节点都在一台机器上,仅用于学习使用!

参考自官方文档 ​​https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#_linux ​​

官方文档上,比较严谨,加了很多的health_check,并开启了ssl和xpack之类的安全机制。

我们本地做实验,为了快速实验,把这些安全机制也关闭了。如果需要开启的话,参考官方的docker-compose.yml再改改即可。

这里演示的是3节点、5节点版的配置。 单节点只要在3节点的基础上做些删减即可。

3节点版

我这里实例放至在 /usr/local/elk/3_es/

代码语言:javascript复制
cd /usr/local/elk/3_es/
mkdir -pv esdata01 esdata02  esdata03  kibanadata
chmod 777 -R  ./
代码语言:javascript复制
$ cat .env
# Version of Elastic products
STACK_VERSION=8.2.0

# Set the cluster name
CLUSTER_NAME=docker-cluster

# Set to 'basic' or 'trial' to automatically start the 30-day trial
LICENSE=basic
#LICENSE=trial

# Port to expose Elasticsearch HTTP API to the host
ES_PORT=9200

# Port to expose Kibana to the host
KIBANA_PORT=5601

# Increase or decrease based on the available host memory (in bytes)
MEM_LIMIT=1073741824

# Project namespace (defaults to the current folder name if not set)
#COMPOSE_PROJECT_NAME=myproject
代码语言:javascript复制
$ cat docker-compose.yml
version: "2.2"

services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
    restart: always    
    volumes:
      - ./esdata01:/usr/share/elasticsearch/data
    ports:
      - ${ES_PORT}:9200
    environment:
      - node.name=es01
      - cluster.name=${CLUSTER_NAME}
      - cluster.initial_master_nodes=es01,es02,es03
      - discovery.seed_hosts=es02,es03
      - bootstrap.memory_lock=true
      - xpack.security.enabled=false
      - xpack.security.http.ssl.enabled=false
      - xpack.security.transport.ssl.enabled=false
      - xpack.license.self_generated.type=${LICENSE}
    mem_limit: ${MEM_LIMIT}
    ulimits:
      memlock:
        soft: -1
        hard: -1

  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
    restart: always    
    volumes:
      - ./esdata02:/usr/share/elasticsearch/data
    environment:
      - node.name=es02
      - cluster.name=${CLUSTER_NAME}
      - cluster.initial_master_nodes=es01,es02,es03
      - discovery.seed_hosts=es01,es03
      - bootstrap.memory_lock=true
      - xpack.security.enabled=false
      - xpack.security.http.ssl.enabled=false
      - xpack.security.transport.ssl.enabled=false
      - xpack.license.self_generated.type=${LICENSE}
    mem_limit: ${MEM_LIMIT}
    ulimits:
      memlock:
        soft: -1
        hard: -1

  es03:
    depends_on:
      - es02
    image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
    restart: always  
    volumes:
      - ./esdata03:/usr/share/elasticsearch/data
    environment:
      - node.name=es03
      - cluster.name=${CLUSTER_NAME}
      - cluster.initial_master_nodes=es01,es02,es03
      - discovery.seed_hosts=es01,es02
      - bootstrap.memory_lock=true
      - xpack.security.enabled=false
      - xpack.security.http.ssl.enabled=false
      - xpack.security.transport.ssl.enabled=false
      - xpack.license.self_generated.type=${LICENSE}
    mem_limit: ${MEM_LIMIT}
    ulimits:
      memlock:
        soft: -1
        hard: -1

  kibana:
    image: docker.elastic.co/kibana/kibana:${STACK_VERSION}
    restart: always
    volumes:
      - ./kibanadata:/usr/share/kibana/data
    ports:
      - ${KIBANA_PORT}:5601
    environment:
      - SERVERNAME=kibana
      - ELASTICSEARCH_HOSTS=http://es01:9200
    mem_limit: ${MEM_LIMIT}
代码语言:javascript复制
启动
# docker-compose up -d

停止
# docker-compose down -v

5节点(冷热分离)

5节点,是方便做些 ILM 实验,一般生产环境都是为了降低成本做了冷热分离的。

比3节点唯一多的就是 node.attr.temperature 这个配置项。

我这里实例放至在 /usr/local/elk/5_es/

cd /usr/local/elk/5_es/

mkdir -pv esdata01 esdata02  esdata03 esdata04 esdata05 kibanadata

chmod 777 -R  ./

代码语言:javascript复制
$ cat .env

# Version of Elastic products
STACK_VERSION=8.2.0

# Set the cluster name
CLUSTER_NAME=docker-cluster

# Set to 'basic' or 'trial' to automatically start the 30-day trial
LICENSE=basic
#LICENSE=trial

# Port to expose Elasticsearch HTTP API to the host
ES_PORT=9200

# Port to expose Kibana to the host
KIBANA_PORT=5601

# Increase or decrease based on the available host memory (in bytes)
MEM_LIMIT=1073741824

# Project namespace (defaults to the current folder name if not set)
#COMPOSE_PROJECT_NAME=myproject
代码语言:javascript复制
$ cat docker-compose.yml
version: "2.2"

services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
    restart: always
    volumes:
      - ./esdata01:/usr/share/elasticsearch/data
    ports:
      - ${ES_PORT}:9200
    environment:
      - node.name=es01
      - cluster.name=${CLUSTER_NAME}
      - cluster.initial_master_nodes=es01,es02,es03,es04,es05
      - discovery.seed_hosts=es02,es03
      - bootstrap.memory_lock=true
      - node.attr.temperature=hot
      - xpack.security.enabled=false
      - xpack.security.http.ssl.enabled=false
      - xpack.security.transport.ssl.enabled=false
      - xpack.license.self_generated.type=${LICENSE}
    mem_limit: ${MEM_LIMIT}
    ulimits:
      memlock:
        soft: -1
        hard: -1

  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
    restart: always
    volumes:
      - ./esdata02:/usr/share/elasticsearch/data
    environment:
      - node.name=es02
      - cluster.name=${CLUSTER_NAME}
      - cluster.initial_master_nodes=es01,es02,es03,es04,es05
      - discovery.seed_hosts=es01,es03
      - bootstrap.memory_lock=true
      - node.attr.temperature=hot
      - xpack.security.enabled=false
      - xpack.security.http.ssl.enabled=false
      - xpack.security.transport.ssl.enabled=false
      - xpack.license.self_generated.type=${LICENSE}
    mem_limit: ${MEM_LIMIT}
    ulimits:
      memlock:
        soft: -1
        hard: -1

  es03:
    depends_on:
      - es02
    image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
    restart: always
    volumes:
      - ./esdata03:/usr/share/elasticsearch/data
    environment:
      - node.name=es03
      - cluster.name=${CLUSTER_NAME}
      - cluster.initial_master_nodes=es01,es02,es03,es04,es05
      - discovery.seed_hosts=es01,es02
      - bootstrap.memory_lock=true
      - node.attr.temperature=hot
      - xpack.security.enabled=false
      - xpack.security.http.ssl.enabled=false
      - xpack.security.transport.ssl.enabled=false
      - xpack.license.self_generated.type=${LICENSE}
    mem_limit: ${MEM_LIMIT}
    ulimits:
      memlock:
        soft: -1
        hard: -1

  es04:
    depends_on:
      - es03
    image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
    restart: always
    volumes:
      - ./esdata04:/usr/share/elasticsearch/data
    environment:
      - node.name=es04
      - cluster.name=${CLUSTER_NAME}
      - cluster.initial_master_nodes=es01,es02,es03,es04,es05
      - discovery.seed_hosts=es01,es02,es03
      - bootstrap.memory_lock=true
      - node.attr.temperature=warm
      - xpack.security.enabled=false
      - xpack.security.http.ssl.enabled=false
      - xpack.security.transport.ssl.enabled=false
      - xpack.license.self_generated.type=${LICENSE}
    mem_limit: ${MEM_LIMIT}
    ulimits:
      memlock:
        soft: -1
        hard: -1

  es05:
    depends_on:
      - es04
    image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
    restart: always
    volumes:
      - ./esdata05:/usr/share/elasticsearch/data
    environment:
      - node.name=es05
      - cluster.name=${CLUSTER_NAME}
      - cluster.initial_master_nodes=es01,es02,es03,es04,es05
      - discovery.seed_hosts=es01,es02,es03
      - bootstrap.memory_lock=true
      - node.attr.temperature=warm
      - xpack.security.enabled=false
      - xpack.security.http.ssl.enabled=false
      - xpack.security.transport.ssl.enabled=false
      - xpack.license.self_generated.type=${LICENSE}
    mem_limit: ${MEM_LIMIT}
    ulimits:
      memlock:
        soft: -1
        hard: -1

  kibana:
    image: docker.elastic.co/kibana/kibana:${STACK_VERSION}
    volumes:
      - ./kibanadata:/usr/share/kibana/data
    ports:
      - ${KIBANA_PORT}:5601
    environment:
      - SERVERNAME=kibana
      - ELASTICSEARCH_HOSTS=http://es01:9200
    mem_limit: ${MEM_LIMIT}

5节点启动后如下:

cerebro管理界面如下;:

0 人点赞