docker安装可参照:https://www.jianshu.com/p/0a0d2315805a
elasticsearch-head和kibana安装可参照:https://www.jianshu.com/p/3883774d80ed
拉取elasticsearch镜像
docker pull elasticsearch:6.8.0
创建es配置文件,容器映射目录
cd /
mkdir elasticsearch
cd elasticsearch
在elasticsearch目录下分别创建:elasticsearch-1.yml、elasticsearch-2.yml
elasticsearch-1.yml配置如下:
cluster.name: elasticsearch-cluster
node.name: es-node1
network.host: 0.0.0.0
network.publish_host: es容器1IP
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["es容器1IP:9300","es容器2IP:9300"]
discovery.zen.minimum_master_nodes: 1
elasticsearch-2.yml
cluster.name: elasticsearch-cluster
node.name: es-node2
network.host: 0.0.0.0
network.publish_host: es容器2IP
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["es容器1IP:9300","es容器2IP:9300"]
discovery.zen.minimum_master_nodes: 1
创建es容器
# es容器1
docker run -itd --name es1 -p 9200:9200 -p 9300:9300 \
-v /elasticsearch/elasticsearch-1.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" elasticsearch:6.8.0
# es容器2
docker run -itd --name es2 -p 9201:9200 -p 9301:9300 \
-v /elasticsearch/elasticsearch-2.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" elasticsearch:6.8.0
查看两个容器IP
# 查看es1IP
docker inspect --format '{{ .NetworkSettings.IPAddress }}' es1
# 查看es2IP
docker inspect --format '{{ .NetworkSettings.IPAddress }}' es2
修改elasticsearch-1.yml、elasticsearch-2.yml配置文件IP设置
重启容器,打开 elasticsearch-head 查看
image.png
打开kibana查看
image.png
网友评论