- 拉取镜像
docker pull elasticsearch:6.5.4
- 先创建本地容器映射目录方便管理,我的目录结构
+ haoke
+ es-cluster
+ node01
+ data
+ elasticsearch.yml
+ jvm.options
+ node02
+ data
+ elasticsearch.yml
+ jvm.options
+ node03
+ data
+ elasticsearch.yml
+ jvm.options
+ ik // IK分词
+ pinyin // 拼音分词
- 分词器上传(非必须)
上传ik分词器和pinyin分词器并解压到对应文件夹
unzip elasticsearch-analysis-ik-6.5.4.zip /haoke/es-cluster/ik/
unzip elasticsearch-analysis-pinyin-6.5.4.zip /haoke/es-cluster/pinyin/
- 配置文件
node01的elasticsearch.yml
# 集群名称
cluster.name: es-itcast-cluster
# 节点名称
node.name: node01
node.master: true
node.data: true
truenetwork.host: 192.168.134.128
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.168.134.128"]
# 设置minimum_master_nodes的大小为2,官方推荐:(N/2)+1,N为集群中节点数
discovery.zen.minimum_master_nodes: 2
# 跨域(非必须)
http.cors.enabled: true
http.cors.allow-origin: "*"
node02的elasticsearch.yml
cluster.name: es-itcast-cluster
node.name: node02
node.master: true
node.data: true
truenetwork.host: 192.168.134.128
http.port: 9201
discovery.zen.ping.unicast.hosts: ["192.168.134.128"]
discovery.zen.minimum_master_nodes: 2
http.cors.enabled: true
http.cors.allow-origin: "*"
node03的elasticsearch.yml
cluster.name: es-itcast-cluster
node.name: node03
node.master: true
node.data: true
truenetwork.host: 192.168.134.128
http.port: 9202
discovery.zen.ping.unicast.hosts: ["192.168.134.128"]
discovery.zen.minimum_master_nodes: 2
http.cors.enabled: true
http.cors.allow-origin: "*"
node01、node02、node03的jvm.options
-Xms256m
-Xmx256m
- 容器创建,设置net为host设置与虚拟机同一个IP
创建容器node01
docker create --name es-node01 --net host
-v /haoke/es-cluster/node01/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
-v /haoke/es-cluster/node01/jvm.options:/usr/share/elasticsearch/config/jvm.options
-v /haoke/es-cluster/ik:/usr/share/elasticsearch/plugins/ik
-v /haoke/es-cluster/pinyin:/usr/share/elasticsearch/plugins/pinyin
-v /haoke/es-cluster/node01/data:/usr/share/elasticsearch/data elasticsearch:6.5.4
创建容器node02
docker create --name es-node02 --net host
-v /haoke/es-cluster/node02/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
-v /haoke/es-cluster/node02/jvm.options:/usr/share/elasticsearch/config/jvm.options
-v /haoke/es-cluster/ik:/usr/share/elasticsearch/plugins/ik
-v /haoke/es-cluster/pinyin:/usr/share/elasticsearch/plugins/pinyin
-v /haoke/es-cluster/node02/data:/usr/share/elasticsearch/data elasticsearch:6.5.4
创建容器node03
docker create --name es-node03 --net host
-v /haoke/es-cluster/node03/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
-v /haoke/es-cluster/node03/jvm.options:/usr/share/elasticsearch/config/jvm.options
-v /haoke/es-cluster/ik:/usr/share/elasticsearch/plugins/ik
-v /haoke/es-cluster/pinyin:/usr/share/elasticsearch/plugins/pinyin
-v /haoke/es-cluster/node03/data:/usr/share/elasticsearch/data elasticsearch:6.5.4
- 启动容器,并查看日志
docker start es-node01 && docker logs -f es-node01
docker start es-node02 && docker logs -f es-node02
docker start es-node03 && docker logs -f es-node03