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配置以下:java

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配置以下:node

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: "*"

說明:docker

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


啓動以下:bootstrap

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 瀏覽器訪問
 bash

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

瀏覽器訪問:xxx:9100cors

參考文章:http://www.javashuo.com/article/p-smwcnobx-cp.htmlcurl

相關文章
相關標籤/搜索