Docker 解决kibana无法连接elasticsearch<br/> 9200端口

Docker 解决kibana无法连接elasticsearch
9200端口

{"type":"log","@timestamp":"2021-02-01T02:47:38Z","tags":["error","elasticsearch","monitoring"],"pid":6,"message":"Request error, retrying\nGET http://192.168.1.115:9200/_xpack => connect EHOSTUNREACH 192.168.1.115:9200"}
{"type":"log","@timestamp":"2021-02-01T02:47:41Z","tags":["warning","elasticsearch","monitoring"],"pid":6,"message":"No living connections"}
{"type":"log","@timestamp":"2021-02-01T02:47:41Z","tags":["warning","plugins","licensing"],"pid":6,"message":"License information could not be obtained from Elasticsearch due to Error: No Living connections error"}
{"type":"log","@timestamp":"2021-02-01T02:47:43Z","tags":["warning","elasticsearch","data"],"pid":6,"message":"Unable to revive connection: http://192.168.1.115:9200/"}
{"type":"log","@timestamp":"2021-02-01T02:47:43Z","tags":["warning","elasticsearch","data"],"pid":6,"message":"No living connections"}

image-20210201105131242

究其原因还是因为网络设置的问题。

解决方案

1. 删除elasticsearch以及kibana

docker rm elasticsearch
docker rm kibana

2. 创建docker网络

docker network create --subnet=172.18.0.0/16 mynetwork

3. 启动elasticsearch

docker run --name elasticsearch --privileged=true -p 9200:9200 -p 9300:9300 \
--net mynetwork --ip 172.18.0.2 \
-e  "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx512m" \
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-v  /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.9.2

4. 启动kibana

docker run --name kibana --net mynetwork -e ELASTICSEARCH_HOSTS=http://172.18.0.2:9200 -p 5601:5601 -d kibana:7.9.2

在后面的启动过程中注意,要先启动elasticsearch 在启动kibana, 否则启动elasticsearch会出现错误.

image-20210201102828183

image-20210201102743621

Copyright: 采用 知识共享署名4.0 国际许可协议进行许可

Links: https://quguai.cn/archives/d-o-c-k-e-r--jie-jue-k-i-b-a-n-a-wu-fa-lian-jie-e-l-a-s-t-i-c-s-e-a-r-c-h--9-2-0-0-duan-kou