1>拉取镜像
docker pull elasticsearch:5.6.8
2>创建数据挂在目录,以及配置ElasticSearch集群配置文件
mkdir /docker/ES
mkdir /docker/ES/data1
mkdir /docker/ES/data2
mkdir /docker/ES/data3
mkdir /docker/ES/config
在config文件夹下创建配置文件
touch es1.yml es2.yml es3.yml
编辑es1.yml文件
vi es1.yml
cluster.name: elasticsearch-cluster//集群名
node.name: es-node1//节点名
network.bind_host: 0.0.0.0
network.publish_host: 你的IP//对外的IP
http.port: 9200//访问的端口
transport.tcp.port: 9300//该参数表示通过9200转发给这个9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true//是否是主集群
node.data: true //是否存储数据
discovery.zen.ping.unicast.hosts: ["你的IP:9300","你的IP:9301","你的IP:9302"]
discovery.zen.minimum_master_nodes: 1//该参数表示有多少个master
vi es2.yml
cluster.name: elasticsearch-cluster
node.name: es-node2
network.bind_host: 0.0.0.0
network.publish_host: 47.112.214.91
http.port: 9201
transport.tcp.port: 9301
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: false
node.data: true
discovery.zen.ping.unicast.hosts: ["你的IP:9300","你的IP:9301","你的IP:9302"]
discovery.zen.minimum_master_nodes: 1
vi es3.yml
cluster.name: elasticsearch-cluster
node.name: es-node3
network.bind_host: 0.0.0.0
network.publish_host: 47.112.214.91
http.port: 9202
transport.tcp.port: 9302
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: false
node.data: true
discovery.zen.ping.unicast.hosts: ["你的IP:9300","你的IP:9301","你的IP:9302"]
discovery.zen.minimum_master_nodes: 1
添加防火墙:
firewall-cmd --add-port=9300/tcp
firewall-cmd --add-port=9301/tcp
firewall-cmd --add-port=9302/tcp
改变创建的文件夹权限:
chmod 777 data1 data2 data3
3>启动ElasticSearch集群容器
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 -v /docker/ES/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /docker/ES/data1:/usr/share/elasticsearch/data --name ES01 elasticsearch:5.6.8
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9201:9201 -p 9301:9301 -v /docker/ES/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /docker/ES/data2:/usr/share/elasticsearch/data --name ES02 elasticsearch:5.6.8
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9202:9202 -p 9302:9302 -v /docker/ES/config/es3.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /docker/ES/data3:/usr/share/elasticsearch/data --name ES03 elasticsearch:5.6.8
4>查看es是否启动成功
curl 127.0.0.1:9200
或者在你浏览器输入 http://你的ip:9200,显示下图内容则是成功
5>查看集群健康状态
curl '127.0.0.1:9200/_cat/health?pretty=true'
或者在浏览器输入 http://你的ip:9200/_cat/health?pretty=true
6>使用elasticsearch-head前端框架
拉取镜像 docker pull mobz/elasticsearch-head:5
启动容器 docker run -d -p 9100:9100 --name es-manager mobz/elasticsearch-head:5
浏览器访问http://192.168.9.219:9100/,如下图表示
(如果是阿里云服务器,记得在安全组中加端口策略开放相应的端口号)