docker中怎么搭建elastatic集群

这篇文章给大家介绍docker中怎么搭建elastatic集群,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

cd /root
touch  node1/config/elasticsearch.yml
touch  node2/config/elasticsearch.yml
chmod 775 /root/node1/config/elasticsearch.yml
chmod 775 /root/node2/config/elasticsearch.yml

/root/node1/config/elasticsearch.yml配置如下:

http.host: 0.0.0.0
cluster.name: elastic-cky
node.name: es1
node.master: true
node.data: true
bootstrap.system_call_filter: false
transport.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
http.cors.enabled: true
http.cors.allow-origin: "*"


/root/node2/config/elasticsearch.yml配置如下:

http.host: 0.0.0.0
cluster.name: elastic-cky
node.name: es2
node.master: true
node.data: true
bootstrap.system_call_filter: false
transport.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.unicast.hosts: ["es1:9300"]
http.cors.enabled: true
http.cors.allow-origin: "*"

说明:

跨域请求
http.cors.enabled: true  
http.cors.allow-origin: "*"


启动如下:

cd /root
docker run --name es1 -p 9201:9200 -p 9301:9300 -v "$PWD/node1/config/elasticsearch.yml":/usr/share/elasticsearch/config/elasticsearch.yml --ulimit nofile=65536:131072  -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" -d elasticsearch 

 
docker run --name es2 -p 9202:9200 -p 9302:9300 -v "$PWD/node2/config/elasticsearch.yml":/usr/share/elasticsearch/config/elasticsearch.yml --ulimit nofile=65536:131072 --link es1:es1  -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" -d elasticsearch

检测是否成功

docker exec -it es2 /bin/bash
curl http://localhost:9200/_cat/health

效果:

root@1256b78663ef:/usr/share/elasticsearch# curl http://localhost:9200/_cat/health 
1563959266 09:07:46 elastic-cky green 1 1 0 0 0 0 0 0 - 100.0%

插件elasticsearch-head 浏览器访问
 

docker run -d --name es-head -p 9100:9100 mobz/elasticsearch-head:5

浏览器访问:xxx:9100

docker中怎么搭建elastatic集群

关于docker中怎么搭建elastatic集群就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。