采用docker-compose搭建Elasticsearch集群
首先安装docker-compose
在主节点创建一个目录es,并创建docker-compose.yaml,主节点yaml文件如下
version: '2'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.6.2
privileged: true
environment:
- cluster.name=docker-cluster
- xpack.security.enabled=false
- bootstrap.memory_lock=true
- node.master=true
- node.data=true # store data on master
- "ES_JAVA_OPTS=-Xms512m -Xmx512m" #根据机器实际来分配
- "discovery.zen.ping.unicast.hosts=192.168.30.30" # put your master_ip here! make sure `telnet MASTER_IP 9300` is oK
- "transport.host=0.0.0.0"
- "network.host=0.0.0.0"
- node.name=esmaster
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
cap_add:
- IPC_LOCK
volumes:
- /data/elasticsearch-service/data:/usr/share/elasticsearch/data
ports:
- 9208:9200
- 9308:9300
network_mode: "host"
执行命令docker-compose up -d启动es,一般会报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144],可以通过sudo sysctl -w vm.max_map_count=262144设置下值
在node节点上同样操作创建es目录,创建docker-compose.yaml,node节点yaml文件如下
version: '2.2'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.6.2
privileged: true
environment:
- cluster.name=docker-cluster
- xpack.security.enabled=false
- bootstrap.memory_lock=true
- node.master=false
- node.data=true
- "ES_JAVA_OPTS=-Xms12g -Xmx12g"
- "discovery.zen.ping.unicast.hosts=192.168.30.30" # put your master_ip here! make sure `telnet MASTER_IP 9300` is oK
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
cap_add:
- IPC_LOCK
volumes:
- /data/elasticsearch-service/data:/usr/share/elasticsearch/data
ports:
- 9208:9200
- 9308:9300
network_mode: "host"
执行命令docker-compose up -d启动es,一般会报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144],可以通过sudo sysctl -w vm.max_map_count=262144设置下值
执行完成后可以去master节点采用
curl http://localhost:9200/_cat/health?v 查看集群状态,出现如下信息则集群搭建成功
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1568794538 08:15:38 docker-cluster green 3 3 0 0 0 0 0 0 - 100.0%