系统环境
- Elasticsearch版本:7.6.2
- OS版本:centos7.x
- docker版本:19.03.08
- docker-compose版本:1.25.4
- elasticsearch实用工具:logstash、elastichq、containerize-elastichd、kibana、cerebro,当然这几个工具大家可以随意选择,亦可不装不影响正常使用。
操作步骤
首先准备工作,先将docker、docker-compose环境都安装好。
#主要为了logstash相关配置文件的随时修改之用,如果不用logstash,则不用创建该目录
mkdir -p /home/server/elasticsearch/pipeline/
# 临时生效
sysctl -w vm.max_map_count=262144
vim docker-compse.yml,然后将如下内容写入:
version: "3.7"
# edit by jiucool.org
# 功能自动构建 docker elasticsearch
services:
es01:
# https://www.elastic.co/guide/en/elasticsearch/reference/7.5/docker.html
container_name: es01
image: elasticsearch:7.6.2
ports:
- "9200:9200"
- "9300:9300"
restart: always
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms1024m -Xmx1024m" # JVM大小
- TZ=Asia/Shanghai
- http.cors.allow-credentials=true
- http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
- http.cors.allow-origin=*
- http.cors.enabled=true
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data01:/usr/share/elasticsearch/data
networks:
- elastic
es02:
image: elasticsearch:7.6.2
container_name: es02
environment:
- node.name=es02
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- 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
es03:
image: elasticsearch:7.6.2
container_name: es03
environment:
- node.name=es03
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data03:/usr/share/elasticsearch/data
ports:
- 9202:9200
networks:
- elastic
logstash:
# https://www.elastic.co/guide/en/elasticsearch/reference/7.5/docker.html
container_name: logstash
image: logstash:7.6.2
ports:
- "4560:4560"
restart: always
environment:
- TZ=Asia/Shanghai
volumes:
- /home/server/elasticsearch/pipeline/:/usr/share/logstash/pipeline/
networks:
- elastic
links:
- es01:elasticsearch
elastichq:
# ElasticHD 支持 ES监控、实时搜索,Index template快捷替换修改,索引列表信息查看, SQL converts to DSL工具等,体验下来感觉还是比较强大的!
# https://hub.docker.com/r/elastichq/elasticsearch-hq
container_name: elastichq
image: elastichq/elasticsearch-hq:latest
ports:
- "5001:5000"
restart: always
environment:
- TZ=Asia/Shanghai
- HQ_DEFAULT_URL=http://es:9200
links:
- es01:es
# volumes:
# - /home/htdocs/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf:rw
networks:
- elastic
containerize-elastichd:
# ElasticHD 支持 ES监控、实时搜索,Index template快捷替换修改,索引列表信息查看, SQL converts to DSL工具等,体验下来感觉还是比较强大的!
# https://github.com/360EntSecGroup-Skylar/ElasticHD
container_name: containerize-elastichd
image: containerize/elastichd:latest
ports:
- "9800:9800"
restart: always
environment:
- TZ=Asia/Shanghai
links:
- es01:es
networks:
- elastic
dejavu:
# https://hub.docker.com/r/appbaseio/dejavu
# The missing Web UI for Elasticsearch
container_name: dejavu
image: appbaseio/dejavu:v3.4.6
ports:
- "1358:1358"
restart: always
environment:
- TZ=Asia/Shanghai
# volumes:
# - /home/htdocs/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf:rw
networks:
- elastic
kibana:
# https://hub.docker.com/r/appbaseio/dejavu
# The missing Web UI for Elasticsearch
container_name: kibana
image: kibana:7.6.2
ports:
- "5601:5601"
restart: always
links:
- es01:es
environment:
- TZ=Asia/Shanghai
- I18N_LOCALE=zh-CN
- ELASTICSEARCH_URL=http://es:9200
- ELASTICSEARCH_HOSTS=http://es:9200
networks:
- elastic
cerebro:
# https://hub.docker.com/r/lmenezes/cerebro/
# 集群管理工具
container_name: cerebro
image: lmenezes/cerebro:latest
ports:
- "9003:9000"
restart: always
links:
- es01:es
environment:
- TZ=Asia/Shanghai
- I18N_LOCALE=zh-CN
- ELASTICSEARCH_URL=http://es:9200
networks:
- elastic
volumes:
data01:
driver: local
data02:
driver: local
data03:
driver: local
networks:
elastic:
driver: bridge
然后启动之
docker-compse up -d
输入任意的工具地址,比如http://192.168.20.6:9003,连接到集群,发现集群已经成功创建,一共3个node节点,接下来就可以正常进行相关操作了。
版权声明:除特殊说明,文章均为博主 久酷 原创文章,转载请注明来源