1、创建3个node节点并授权,es集群至少需要3个节点,防止脑裂
# 创建node目录 mkdir -p /data/es/data/node1/data mkdir -p /data/es/data/node2/data mkdir -p /data/es/data/node3/data# 授权node目录 chmod 777 /data/es/data/node1/data chmod 777 /data/es/data/node2/data chmod 777 /data/es/data/node3/data
2、修改 sysctl.conf 文件
# 修改sysctl.conf,解决 max virtual memory areas vm.max_map_count [65530] is too low 问题 vi /etc/sysctl.conf# 在最后添加一行 vm.max_map_count=655300# 使文件生效 sysctl -p /etc/sysctl.conf
3、创建docker-compose.yaml
version: '2.2' services:es01:image: docker.elastic.co/elasticsearch/elasticsearch:7.14.0container_name: es01environment:- node.name=es01- cluster.name=es-cluster- discovery.seed_hosts=es02,es03- cluster.initial_master_nodes=es01,es02,es03- bootstrap.memory_lock=true- "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"ulimits:memlock:soft: -1hard: -1volumes:- /data/es/data/node1/data:/usr/share/elasticsearch/data- /data/es/ik:/usr/share/elasticsearch/plugins/ikports:- 9201:9200networks:- elastices02:image: docker.elastic.co/elasticsearch/elasticsearch:7.14.0container_name: es02environment:- node.name=es02- cluster.name=es-cluster- discovery.seed_hosts=es01,es03- cluster.initial_master_nodes=es01,es02,es03- bootstrap.memory_lock=true- "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"ulimits:memlock:soft: -1hard: -1volumes:- /data/es/data/node2/data:/usr/share/elasticsearch/data- /data/es/ik:/usr/share/elasticsearch/plugins/ikports:- 9202:9200networks:- elastices03:image: docker.elastic.co/elasticsearch/elasticsearch:7.14.0container_name: es03environment:- node.name=es03- cluster.name=es-cluster- discovery.seed_hosts=es01,es02- cluster.initial_master_nodes=es01,es02,es03- bootstrap.memory_lock=true- "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"ulimits:memlock:soft: -1hard: -1volumes:- /data/es/data/node3/data:/usr/share/elasticsearch/data- /data/es/ik:/usr/share/elasticsearch/plugins/ikports:- 9203:9200networks:- elasticnetworks:elastic:driver: bridge
4、启动es集群
# 启动 docker-compose up -d# 查看启动状态 docker ps -a# 查看日志命令,es01代表其中一个node节点 docker logs es01