前提:docker 环境已经安装完毕
# 拉取镜像
docker pull elasticsearch:6.7.1
# 创建配置文件
mkdir -p /home/local/elasticsearch
vim es1.yml
:wq
vim es2.yml
:wq
vim es3.yml
:wq
- 写入 es1.yml
cluster.name: elasticsearch-cluster
node.name: es-node1
network.host: 0.0.0.0
network.publish_host: 192.168.2.32
http.port: 9100
transport.tcp.port: 9101
http.cors.enabled: true
http.cors.allow-origin: “*”
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: [“192.168.2.32:9101”,“192.168.2.32:9102”,“192.168.2.32:9103”]
discovery.zen.minimum_master_nodes: 2
- 写入 es2.yml
cluster.name: elasticsearch-cluster
node.name: es-node2
network.host: 0.0.0.0
network.publish_host: 192.168.2.32
http.port: 9200
transport.tcp.port: 9201
http.cors.enabled: true
http.cors.allow-origin: “*”
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: [“192.168.2.32:9101”,“192.168.2.32:9102”,“192.168.2.32:9103”]
discovery.zen.minimum_master_nodes: 2
- 写入 es3.yml
cluster.name: elasticsearch-cluster
node.name: es-node3
network.host: 0.0.0.0
network.publish_host: 192.168.2.32
http.port: 9300
transport.tcp.port: 9301
http.cors.enabled: true
http.cors.allow-origin: “*”
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: [“192.168.2.32:9101”,“192.168.2.32:9102”,“192.168.2.32:9103”]
discovery.zen.minimum_master_nodes: 2
# docker 开始运行
# ES01
docker run \
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" \
-d -p 9101:9101 -p 9100:9100 \
-v /home/local/elasticsearch/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
--name ES01 e2667f5db289
# ES02
docker run \
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" \
-d -p 9201:9201 -p 9200:9200 \
-v /home/local/elasticsearch/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
--name ES02 e2667f5db289
# ES03
docker run \
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" \
-d -p 9301:9301 -p 9300:9300 \
-v /home/local/elasticsearch/es3.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
--name ES03 e2667f5db289
测试
http://192.168.2.32:9100/_cluster/health?pretty
http://192.168.2.32:9200/_cluster/health?pretty
http://192.168.2.32:9300/_cluster/health?pretty