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集群-LMLPHP

参考文章:https://blog.csdn.net/sinat_28434649/article/details/79278975

07-24 22:56