前提
- 安装了docker,docker-compose,pull了相关的镜像,创建了相关的存放目录
- 本文相关环境如下:
linux:ubuntu:16.04
docker version:19.03.1
docker-compose version:1.24.1
elasticsearch kibana version:7.3.0
docker 安装
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" --name myEs -d elasticsearch:7.3.0
docker run -p 5601:5601 --name myKb --link myEs -d kibana:7.3.0
docker-compose安装
version: '2.2'
services:
es01:
image: elasticsearch:7.3.0
container_name: es01
environment:
- node.name=es01
- discovery.seed_hosts=es02
- cluster.initial_master_nodes=es01,es02
- cluster.name=docker-elasticsearch-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
nofile:
soft: 65536
hard: 65536
memlock:
soft: -1
hard: -1
volumes:
- ./es01/data:/usr/share/elasticsearch/data
- ./es01/logs:/usr/share/elasticsearch/logs
restart: always
ports:
- 9200:9200
- 9300:9300
networks:
- esnet
es02:
image: elasticsearch:7.3.0
container_name: es02
environment:
- node.name=es02
- discovery.seed_hosts=es01
- cluster.initial_master_nodes=es01,es02
- cluster.name=docker-elasticsearch-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
nofile:
soft: 65536
hard: 65536
memlock:
soft: -1
hard: -1
volumes:
- ./es02/data:/usr/share/elasticsearch/data
- ./es02/logs:/usr/share/elasticsearch/logs
restart: always
ports:
- 9201:9200
- 9301:9300
networks:
- esnet
kibana:
image: kibana:7.3.0
container_name: kibana
environment:
- server.host=0.0.0.0
- elasticsearch.hosts=http://es01:9200
- I18N_LOCALE=zh-CN
- XPACK_MONITORING_ENABLED=true
volumes:
- ./kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml
restart: always
ports:
- 5601:5601
networks:
- esnet
networks:
esnet:
driver: bridge
其中kibana.yml配置如下
server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://es01:9200" ]
xpack.monitoring.ui.container.elasticsearch.enabled: true
问题
- 1.es节点挂载目录的权限不够造成容器启动失败,可以执行命令chmod 777 XXX赋予文件权限
- 2.es需要的内存不够可能造成容器未正常启动,可以编辑文件vim /etc/sysctl.conf,在末尾添加vm.max_map_count=262144,最后需要执行命令sysctl -p使配置生效
参考
docker-compose搭建elasticsearch集群,同时部署Kibana,elasticsearch-head