1. 安装环境前提:docker
环境docker-compose
工具
备注:基础不好的同学请先了解docker相关内容,否则理解上可能有难度
2. 创建文件docker-compose.yml
,然后放入下面的内容
version: '3'
services:
es-master:
image: elasticsearch:7.1.1
container_name: es-master
privileged: true
environment:
- cluster.name=elasticsearch-cluster
- node.name=es-master
- node.master=true
- node.data=true
- bootstrap.memory_lock=true
#- discovery.seed_hosts=es-node1,es-node2
- http.cors.enabled=true
- http.cors.allow-origin=*
- cluster.initial_master_nodes=es-master,es-node1,es-node2
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "discovery.zen.ping.unicast.hosts=es-master,es-node1,es-node2"
- "discovery.zen.minimum_master_nodes=2"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./es/master/data:/usr/share/elasticsearch/data
- ./es/master/logs:/usr/share/elasticsearch/logs
ports:
- 9200:9200
es-node1:
image: elasticsearch:7.1.1
container_name: es-node1
privileged: true
environment:
- cluster.name=elasticsearch-cluster
- node.name=es-node1
- node.master=true
- node.data=true
- bootstrap.memory_lock=true
#- discovery.seed_hosts=es-node1,es-node2
- http.cors.enabled=true
- http.cors.allow-origin=*
- cluster.initial_master_nodes=es-master,es-node1,es-node2
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "discovery.zen.ping.unicast.hosts=es-master,es-node1,es-node2"
- "discovery.zen.minimum_master_nodes=2"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./es/node1/data:/usr/share/elasticsearch/data
- ./es/node1/logs:/usr/share/elasticsearch/logs
ports:
- 9201:9200
es-node2:
image: elasticsearch:7.1.1
container_name: es-node2
privileged: true
environment:
- cluster.name=elasticsearch-cluster
- node.name=es-node2
- node.master=true
- node.data=true
- bootstrap.memory_lock=true
#- discovery.seed_hosts=es-node1,es-node2
- http.cors.enabled=true
- http.cors.allow-origin=*
- cluster.initial_master_nodes=es-master,es-node1,es-node2
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "discovery.zen.ping.unicast.hosts=es-master,es-node1,es-node2"
- "discovery.zen.minimum_master_nodes=2"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./es/node2/data:/usr/share/elasticsearch/data
- ./es/node2/logs:/usr/share/elasticsearch/logs
ports:
- 9202:9200
kibana:
image: docker.elastic.co/kibana/kibana:7.1.1
container_name: kibana
environment:
- SERVER_NAME=kibana
- ELASTICSEARCH_HOSTS=http://es-master:9200
- XPACK_MONITORING_ENABLED=true
ports:
- 5601:5601
depends_on:
- es-master
es-head:
image: tobias74/elasticsearch-head:6
container_name: es-head
restart: always
ports:
- "9100:9100"
3. 然后在终端中运行如下命令启动各个容器:
docker-compose up -d es-master es-node1 es-node2 kibana es-head
备注1:至于为什么要Es结合kibana和es-head使用,这其实是一套通用的解决方案,大家可以根据实际情况进行安装。
备注2:Es对内存空间的要求比较高,有的时候启动比较慢,可以稍等片刻再检查启动效果
4. 检查容器的启动情况,输入命令docker ps
如果看到了上面的效果即表示环境已经安装成功!
5. 与es进行简单交互,查看服务正常运行的情况,下面是正常情况
6. 访问es-head查看集群概览,如果9200端口需要能查到如下情况
6. 访问kibana
今天的内容就分享到这里,有任何问题欢迎下方留言,或者关注公众号"编程社"与我直接交流吧!