ECE认证笔记之使用docker compose快速启动ES+Kibaba测试环境
0x00 概述
为了避开虚拟机,在基于docker compose的基础上快速启动一套3节点es+kibana的测试环境(7.13.3);
要求理解docker原理和熟悉基本docker操作,本集群仅供测试用。
win平台报错,参考
0x01 准备
1.1 电脑win或者mac安装好docker desktop
1.2 将docker镜像源改为国内源,加快镜像下载速度
{ "debug": true, "experimental": false, "registry-mirrors": [ "https://docker.mirrors.ustc.edu.cn", "https://hub-mirror.c.163.com" ] }
点击Apply & Reset.
1.3 docker提前下载好镜像,以便快速启动
docker pull elasticsearch:7.13.3
docker pull kibaba:7.13.3
1.4 使用ES提前制作elastic-certificates.p12,方便挂载
制作方法参考这里,存在D盘es-cluster目录,挂载路径为/d/es-cluster/elastic-certificates.p12
1.5 在本地提前新建es存储用的文件夹,方便挂在
es有存储数据的需求,这里将数据直接挂载到本机,存在D盘es-cluster目录,3个es实例对应的分别为该目录下的es01,es02,es03,挂载路径为/d/es-cluster/es01,/d/es-cluster/es02,/d/es-cluster/es03
0x02 启动测试集群
2.1 docker-compose.yml文件
新建docker-compose.yml,放在D盘es-cluster目录,路径为D:\es-cluster\docker-compose.yml
docker-compose.yml (注意参数配置和用户密码)
version: '1.0' services: es01: image: elasticsearch:7.13.3 container_name: es01 environment: - node.name=es01 - cluster.name=es-docker-01 - discovery.seed_hosts=es02,es03 - cluster.initial_master_nodes=es01,es02,es03 - bootstrap.memory_lock=true - xpack.security.enabled=true - xpack.security.transport.ssl.enabled=true - xpack.security.transport.ssl.verification_mode=certificate - xpack.security.transport.ssl.keystore.path=elastic-certificates.p12 - xpack.security.transport.ssl.truststore.path=elastic-certificates.p12 - "ES_JAVA_OPTS=-Xms2g -Xmx2g -Xlog:disable -Xlog:all=warning:stderr:utctime,level,tags -Xlog:gc=debug:stderr:utctime" - ELASTIC_PASSWORD=123456 ulimits: memlock: soft: -1 hard: -1 nofile: soft: 65536 hard: 65536 mem_limit: 4g volumes: - /d/es-cluster/es01:/usr/share/elasticsearch/data - /d/es-cluster/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12 ports: - 9200:9200 networks: - elastic-stack es02: image: elasticsearch:7.13.3 container_name: es02 environment: - node.name=es02 - cluster.name=es-docker-01 - discovery.seed_hosts=es01,es03 - cluster.initial_master_nodes=es01,es02,es03 - bootstrap.memory_lock=true - xpack.security.enabled=true - xpack.security.transport.ssl.enabled=true - xpack.security.transport.ssl.verification_mode=certificate - xpack.security.transport.ssl.keystore.path=elastic-certificates.p12 - xpack.security.transport.ssl.truststore.path=elastic-certificates.p12 - "ES_JAVA_OPTS=-Xms2g -Xmx2g -Xlog:disable -Xlog:all=warning:stderr:utctime,level,tags -Xlog:gc=debug:stderr:utctime" - ELASTIC_PASSWORD=123456 ulimits: memlock: soft: -1 hard: -1 nofile: soft: 65536 hard: 65536 mem_limit: 4g volumes: - /d/es-cluster/es02:/usr/share/elasticsearch/data - /d/es-cluster/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12 ports: - 9201:9200 networks: - elastic-stack es03: image: elasticsearch:7.13.3 container_name: es03 environment: - node.name=es03 - cluster.name=es-docker-01 - discovery.seed_hosts=es01,es02 - cluster.initial_master_nodes=es01,es02,es03 - bootstrap.memory_lock=true - xpack.security.enabled=true - xpack.security.transport.ssl.enabled=true - xpack.security.transport.ssl.verification_mode=certificate - xpack.security.transport.ssl.keystore.path=elastic-certificates.p12 - xpack.security.transport.ssl.truststore.path=elastic-certificates.p12 - "ES_JAVA_OPTS=-Xms2g -Xmx2g -Xlog:disable -Xlog:all=warning:stderr:utctime,level,tags -Xlog:gc=debug:stderr:utctime" - ELASTIC_PASSWORD=123456 ulimits: memlock: soft: -1 hard: -1 nofile: soft: 65536 hard: 65536 mem_limit: 4g volumes: - /d/es-cluster/es03:/usr/share/elasticsearch/data - /d/es-cluster/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12 ports: - 9202:9200 networks: - elastic-stack kibana: image: kibana:7.13.3 container_name: kibana depends_on: - es01 - es02 - es03 environment: SERVER_NAME: kibana SERVER_HOST: "0.0.0.0" ELASTICSEARCH_HOSTS: http://es01:9200 ELASTICSEARCH_USERNAME: "elastic" ELASTICSEARCH_PASSWORD: 123456 ports: - 5601:5601 networks: - elastic-stack networks: elastic-stack: driver: bridge
2.2 启动和关闭
使用命令行进入到D:\es-cluster\,使用docker compoe up命令启动即可,注意观察日志,集群状态变为Green即可访问Kibana;
docker compose down关闭测试环境
2.3 注意事项
如下命令用于后台启动
docker compose up -d
如下命令用于停止测试集群
docker compose down
由于ES会存储数据,使用ctrl+C停止集群会造成数据损坏或丢失,导致无法再次重启集群,切记。
如果启动报错,或者需要清空集群数据,删除/d/es-cluster/下3个es开头文件夹下面的所有内容,再次启动即可。
0x03 参考
需要Ansible步骤的参考这里