Docker中运行Elasticsearch,Logstash, Kibana和Cerebro

前提

本机已安装Docker

创建yaml文件

创建7.x-docker-2-es-instances文件夹,并创建docker-compose.yaml文件。

dailong-MacBook-Pro:7.x-docker-2-es-instances dailong$ pwd
/work/geektime-ELK/work/7.x-docker-2-es-instances
dailong-MacBook-Pro:7.x-docker-2-es-instances dailong$ ls
docker-compose.yaml
dailong-MacBook-Pro:7.x-docker-2-es-instances dailong$ 

编写docker-compose.yaml

version: '2.2'
services:
  cerebro:
    image: lmenezes/cerebro:0.8.3
    container_name: cerebro
    ports:
      - "9000:9000"
    command:
      - -Dhosts.0.host=http://elasticsearch:9200
    networks:
      - es7net
  kibana:
    image: docker.elastic.co/kibana/kibana:7.1.0
    container_name: kibana7
    environment:
      - I18N_LOCALE=zh-CN
      - XPACK_GRAPH_ENABLED=true
      - TIMELION_ENABLED=true
      - XPACK_MONITORING_COLLECTION_ENABLED="true"
    ports:
      - "5601:5601"
    networks:
      - es7net
  logstash:
    image: logstash:7.1.0
    container_name: logstash7
    ports:
      - "9600:9600"
    networks:
      - es7net
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.1.0
    container_name: es7_01
    environment:
      - cluster.name=geektime
      - node.name=es7_01
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.seed_hosts=es7_01,es7_02
      - cluster.initial_master_nodes=es7_01,es7_02
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - es7data1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - es7net
  elasticsearch2:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.1.0
    container_name: es7_02
    environment:
      - cluster.name=geektime
      - node.name=es7_02
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.seed_hosts=es7_01,es7_02
      - cluster.initial_master_nodes=es7_01,es7_02
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - es7data2:/usr/share/elasticsearch/data
    networks:
      - es7net


volumes:
  es7data1:
    driver: local
  es7data2:
    driver: local

networks:
  es7net:
    driver: bridge

启动及相关命令

#进入7.x-docker-2-es-instances目录

#启动
docker-compose up -d

#停止容器
docker-compose down

#停止容器并且移除数据
docker-compose down -v

#一些docker 命令
docker ps
docker stop Name/ContainerId
docker start Name/ContainerId
docker logs -f -t --tail=100 CONTAINER_ID

#查看日志compose
docker-compose logs -f

#删除单个容器
$docker rm Name/ID
-f, –force=false; -l, –link=false Remove the specified link and not the underlying container; -v, –volumes=false Remove the volumes associated to the container

#删除所有容器
$docker rm `docker ps -a -q`  
停止、启动、杀死、重启一个容器
$docker stop Name/ID  
$docker start Name/ID  
$docker kill Name/ID  
$docker restart name/ID

结果

dailong-MacBook-Pro:7.x-docker-2-es-instances dailong$ docker ps
CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS              PORTS                              NAMES
d7a2530db909        docker.elastic.co/elasticsearch/elasticsearch:7.1.0   "/usr/local/bin/dock…"   8 seconds ago       Up 4 seconds        0.0.0.0:9200->9200/tcp, 9300/tcp   es7_01
71640372d86c        lmenezes/cerebro:0.8.3                                "/opt/cerebro/bin/ce…"   8 seconds ago       Up 4 seconds        0.0.0.0:9000->9000/tcp             cerebro
879269a493e1        docker.elastic.co/elasticsearch/elasticsearch:7.1.0   "/usr/local/bin/dock…"   8 seconds ago       Up 4 seconds        9200/tcp, 9300/tcp                 es7_02
13c94f6bd3a8        docker.elastic.co/kibana/kibana:7.1.0                 "/usr/local/bin/kiba…"   8 seconds ago       Up 4 seconds        0.0.0.0:5601->5601/tcp             kibana7
799f178fa2ed        logstash:7.1.0                                        "/usr/local/bin/dock…"   8 seconds ago       Up 4 seconds        5044/tcp, 0.0.0.0:9600->9600/tcp   logstash7
  • Elasticsearch


    Docker中运行Elasticsearch,Logstash, Kibana和Cerebro_第1张图片
    image.png
  • Logstash


    image.png
  • Kibana


    Docker中运行Elasticsearch,Logstash, Kibana和Cerebro_第2张图片
    image.png
  • Cerebro


    Docker中运行Elasticsearch,Logstash, Kibana和Cerebro_第3张图片
    image.png

相关阅读

  • 安装docker https://www.docker.com/products/docker-desktop
  • 安装 docker-compose https://docs.docker.com/compose/install/
  • 如何创建自己的Docker Image - https://www.elastic.co/cn/blog/how-to-make-a-dockerfile-for-elasticsearch
  • 如何在为docker image安装 Elasticsearch 插件 - https://www.elastic.co/cn/blog/elasticsearch-docker-plugin-management
  • 如何设置 Docker 网络 - https://www.elastic.co/cn/blog/docker-networking
  • Cerebro 源码 https://github.com/lmenezes/cerebro
  • 一个开源的 ELK(Elasticsearch + Logstash + Kibana) docker-compose 配置 https://github.com/deviantony/docker-elk
  • Install Elasticsearch with Docker https://www.elastic.co/guide/en/elasticsearch/reference/7.2/docker.html

你可能感兴趣的:(Docker中运行Elasticsearch,Logstash, Kibana和Cerebro)