如何部署Docker ElasticSearch?
- By : Will
- Category : Docker, Elastic Stack
1 基础知识
1.1 Elasticsearch的基础知识
1.1.1 Elasticsearch的简介
– Elasticsearch是一个高度可扩展的开源全文搜索和分析引擎
– Elasticsearch允许快速实时地存储、搜索和分析大量的数据
– Elasticsearch支持复杂收缩功能和需求的应用程序底层引擎或技术
1.1.2 Elasticsearch的应用场景
– 为线上商店客户提供产品目录和库存的搜索和自动填充建议
– 收集日志或交易数据用于分析或挖掘数据查询趋势,统计或汇总或异常情况
— Elasticsearch/Logstash/Kibana stack
– 搭建降价提醒平台(商品价格低于某个值通知用户)
— Elasticsearch
— Percolator
– 实现分析/商业智能需求,快速调查、分析并使用仪表板可视化
— Elasticsearch/Logstash/Kibana stack
1.1.3 Docker的Elasticsearch镜像分类
– basic,预装并通过免费许可自动激活,附带基础的X-Pack功能
– platinum,30天使用许可证,附带所有的X-Pack功能
– oss,包含开源Elasticsearch许可,不包含任何X-Pack功能
注:三个版本的拉取路径如下,
docker pull docker.elastic.co/elasticsearch/elasticsearch:6.2.4 docker pull docker.elastic.co/elasticsearch/elasticsearch-platinum:6.2.4 docker pull docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4
2 最佳实践
2.1 部署前的准备
2.1.1 部署Docker环境
本章使用如下Docker环境部署,参阅本章建议你先搭建以下Docker集群环境并熟悉,
2.1.2 准备elasticsearch镜像
In docker01
cd /data/docker/images/ docker load -i elasticsearch_7.11.1.tar docker tag elasticsearch:7.11.1 docker01.cmdschool.org:5000/elasticsearch:7.11.1 docker push docker01.cmdschool.org:5000/elasticsearch:7.11.1 docker image rm elasticsearch:7.11.1
另外,安装包的离线下载请在能上网的docker环境的机器上使用如下命令,
docker pull elasticsearch:7.11.1 docker save elasticsearch:7.11.1 -o elasticsearch_7.11.1.tar
另外,其他版本请从以下链接下载,
https://hub.docker.com/r/elasticsearch/server
2.2 部署elasticsearch
In docker01
2.2.1 创建服务配置文件
vim /data/docker/yml/es7111-01-stack.yml
加入如下配置,
version: '3.8' services: es01: image: docker01.cmdschool.org:5000/elasticsearch:7.11.1 environment: - node.name=es01 - cluster.name=es-docker-cluster - discovery.seed_hosts=es02,es03 - cluster.initial_master_nodes=es01,es02,es03 - bootstrap.memory_lock=false - "ES_JAVA_OPTS=-Xms512m -Xmx512m" - TZ=Asia/Shanghai volumes: - data-es01:/usr/share/elasticsearch/data ports: - target: 9200 published: 9200 protocol: tcp mode: host networks: - elk deploy: replicas: 1 endpoint_mode: dnsrr placement: constraints: [node.labels.es01 == true] volumes: data-es01: external: true networks: elk: external: true name: elk driver: overlay
以上命令创建第一个节点的配置,以下命令创建第二节点的配置,
vim /data/docker/yml/es7111-02-stack.yml
加入如下配置,
version: '3.8' services: es02: image: docker01.cmdschool.org:5000/elasticsearch:7.11.1 environment: - node.name=es02 - cluster.name=es-docker-cluster - discovery.seed_hosts=es01,es03 - cluster.initial_master_nodes=es01,es02,es03 - bootstrap.memory_lock=false - "ES_JAVA_OPTS=-Xms512m -Xmx512m" - TZ=Asia/Shanghai volumes: - data-es02:/usr/share/elasticsearch/data ports: - target: 9200 published: 9200 protocol: tcp mode: host networks: - elk deploy: replicas: 1 endpoint_mode: dnsrr placement: constraints: [node.labels.es02 == true] volumes: data-es02: external: true networks: elk: external: true name: elk driver: overlay
以下命令创建第三节点的配置,
vim /data/docker/yml/es7111-03-stack.yml
加入如下配置,
version: '3.8' services: es03: image: docker01.cmdschool.org:5000/elasticsearch:7.11.1 environment: - node.name=es03 - cluster.name=es-docker-cluster - discovery.seed_hosts=es01,es03 - cluster.initial_master_nodes=es01,es02,es03 - bootstrap.memory_lock=false - "ES_JAVA_OPTS=-Xms512m -Xmx512m" - TZ=Asia/Shanghai volumes: - data-es03:/usr/share/elasticsearch/data ports: - target: 9200 published: 9200 protocol: tcp mode: host networks: - elk deploy: replicas: 1 endpoint_mode: dnsrr placement: constraints: [node.labels.es03 == true] volumes: data-es03: external: true networks: elk: external: true name: elk driver: overlay
2.2.2 根据配置准备网络
docker network create --driver=overlay elk
2.2.2 根据配置标记运行节点
docker node update --label-add es01=true docker01.cmdschool.org docker node update --label-add es02=true docker02.cmdschool.org docker node update --label-add es03=true docker03.cmdschool.org
2.2.3 部署服务
docker stack deploy -c /data/docker/yml/es7111-01-stack.yml elk docker stack deploy -c /data/docker/yml/es7111-02-stack.yml elk docker stack deploy -c /data/docker/yml/es7111-03-stack.yml elk
2.2.4 排错方法
In docker0[1-3]
docker exec -it `docker container ls | grep elk_es | cut -d" " -f1` /bin/bash
然后可以使用如下命令查看ElasticSearch的日志,
tail -f /usr/share/elasticsearch/logs/gc.log
参阅文档
====================
安装教程
————
https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
hub安装源
—————
https://registry.hub.docker.com/_/elasticsearch
compose文件规范
—————-
https://docs.docker.com/compose/compose-file/
docker网络创建
————–
https://docs.docker.com/engine/reference/commandline/network_create/
没有评论