1.首先安装Docker-compose
2.docker pull elasticsearch7.4.2
3.创建/usr/local/docker/es目录
4.vim docker-compose.yml。
注意:环境是生成环境,定义端口是有规定的
具体ip不方便透露,所有用127.0.0.1,127.0.0.2代替
version: '2.2'
services:
es1:
image: elasticsearch:7.4.2
container_name: elasticsearch
restart: always
environment:
- cluster.name=elasticsearch-cluster
- node.name=node2
- node.master=true
- node.data=true
- http.port=19085
- transport.tcp.port=19084
- bootstrap.memory_lock=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- "ES_JAVA_OPTS=-Xms2g -Xmx2g"
- "discovery.seed_hosts=127.0.0.1:19084,127.0.0.2:19084"
- "cluster.initial_master_nodes=node1,node2"
network_mode: "host"
volumes:
- /usr/local/docker/es/data:/usr/share/elasticsearch/data
- /usr/local/docker/es/plugins:/usr/share/elasticsearch/plugins
- /usr/local/docker/es/logs:/usr/share/elasticsearch/logs
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
ports:
- "19085:19085"
- "19084:19084"
挂载数据卷时,可能会出现权限问题。我们用 chmod 777 '具体文件路径’降低文件权限
5.复制上面docker-compose.yml的内容,将节点名称改为node1
6.分别启动,输入curl http://localhost:19085/_cluster/health?pretty