创建集群目录
mkdir -p /usr/local/elasticsearch-7.5.0-node-1/config &&
mkdir -p /usr/local/elasticsearch-7.5.0-node-1/data \&\&
mkdir -p /usr/local/elasticsearch-7.5.0-node-1/plugins/ik \&\&
mkdir -p /usr/local/elasticsearch-7.5.0-node-2config \&\&
mkdir -p /usr/local/elasticsearch-7.5.0-node-2/data \&\&
mkdir -p /usr/local/elasticsearch-7.5.0-node-2/plugins/ik \&\&
mkdir -p /usr/local/elasticsearch-7.5.0-node-3/config \&\&
mkdir -p /usr/local/elasticsearch-7.5.0-node-3/data \&\&
`mkdir -p /usr/local/elasticsearch-7.5.0-node-3/plugins/ik
`
修改目录权限
chmod 777 -R /usr/local/elasticsearch-7.5.0-node-1 &&
chmod 777 -R /usr/local/elasticsearch-7.5.0-node-2 &&
chmod 777 -R /usr/local/elasticsearch-7.5.0-node-3
分别在node1,node2,node3的config目录下创建elasticsearch.yml文件
node1的elasticsearch.yml
cluster.name: es-cluster
node.name: es-node-1
node.master: true
node.data: true
network.host: es-node-1
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "\*"
discovery.zen.ping.unicast.hosts: \["es-node-1:9300", "es-node-3:9300", "es-node-3:9300"\]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s
`bootstrap.memory_lock: true
action.destructive_requires_name: true
cluster.initial_master_nodes: ["es-node-1"]
`
node2的elasticsearch.yml
cluster.name: es-cluster
node.name: es-node-2
node.master: false
node.data: true
network.host: es-node-2
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "\*"
discovery.zen.ping.unicast.hosts: \["es-node-1:9300", "es-node-3:9300", "es-node-3:9300"\]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s
`bootstrap.memory_lock: true
action.destructive_requires_name: true
cluster.initial_master_nodes: ["es-node-1"]
`
node3的elasticsearch.yml
cluster.name: es-cluster
node.name: es-node-3
node.master: false
node.data: true
network.host: es-node-3
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "\*"
discovery.zen.ping.unicast.hosts: \["es-node-1:9300", "es-node-3:9300", "es-node-3:9300"\]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s
`bootstrap.memory_lock: true
action.destructive_requires_name: true
cluster.initial_master_nodes: ["es-node-1"]
`
在/usr/local/elasticsearch 目录下创建 docker-compose.yml
version: "3"
services:
es-node-1:
image: elasticsearch:7.5.0
container_name: es-node-1
environment:
- "ES_JAVA_OPTS=-Xms256m -Xmx256m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
ports:
- "9200:9200"
- "9300:9300"
volumes:
- /usr/local/elasticsearch-7.5.0-node-1/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- /usr/local/elasticsearch-7.5.0-node-1/data:/usr/share/elasticsearch/data
- /usr/local/elasticsearch-7.5.0-node-1/plugins/ik:/usr/share/elasticsearch/plugins/ik
networks:
- net-es
es-node-2:
image: elasticsearch:7.5.0
container_name: es-node-2
environment:
- "ES_JAVA_OPTS=-Xms256m -Xmx256m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
ports:
- "9201:9200"
- "9301:9300"
volumes:
- /usr/local/elasticsearch-7.5.0-node-2/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- /usr/local/elasticsearch-7.5.0-node-2/data:/usr/share/elasticsearch/data
- /usr/local/elasticsearch-7.5.0-node-2/plugins/ik:/usr/share/elasticsearch/plugins/ik
networks:
- net-es
es-node-3:
image: elasticsearch:7.5.0
container_name: es-node-3
environment:
- "ES_JAVA_OPTS=-Xms256m -Xmx256m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
ports:
- "9202:9200"
- "9302:9300"
volumes:
- /usr/local/elasticsearch-7.5.0-node-3/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- /usr/local/elasticsearch-7.5.0-node-3/data:/usr/share/elasticsearch/data
- /usr/local/elasticsearch-7.5.0-node-3/plugins/ik:/usr/share/elasticsearch/plugins/ik
networks:
- net-es
# es-head:
# image: mobz/elasticsearch-head:5
# container_name: es-head
# restart: always
# ports:
# - 9100:9100
# networks:
# - net-es
# es-kibana:
# image: kibana:7.5.0
# container_name: es-kibana
# restart: always
# ports:
# - 5601:5601
# volumes:
# - /usr/local/kibana/kibana.yml:/usr/share/kibana/config/kibana.yml
# networks:
# - net-es
networks:
net-es:
driver: bridge
执行docker-compose命令
docker-compose -f docker-compose.yml up -d