且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Kibana未连接到Elasticsearch([“警告","elasticsearch","admin"],"pid":12,“消息":“无活动连接"})

更新时间:2023-02-16 18:54:17

问题在于,这三个容器在网络方面相互分离和/或配置错误.让我们讨论一下实际发生的情况以及如何解决此问题:

The Problem is that the three container are separated in terms of networking from each other and/or misconfigured. Let us discuss what is actualy happening and how to fix it:

1. Elasticsearch

您正在启动一个名为elasticsearch_container的Elasticsearch容器:

You are starting an elasticsearch container named elasticsearch_container:

docker run -d -p 9200:9200 -e "discovery.type=single-node" --volume C:\Dockers\simplest-try\esdata:/usr/share/elasticsearch/data --name elasticsearch_container docker.elastic.co/elasticsearch/elasticsearch:7.5.2

到目前为止,很好.

2. Filebeat

如开头所述,容器彼此分开.为了使elasticsearch对于filebeat可见,您需要创建一个链接:

As mentioned at the beginning, the containers are separated from each other. In order to make elasticsearch visible for filebeat, you need to create a link:

docker run -d --link elasticsearch_container:elasticsearch --mount type=bind,source=C:\Dockers\simplest-try\filebeat.yml,target=/usr/share/filebeat/filebeat.yml --volume C:\Dockers\simplest-try\mylogs:/mylogs docker.elastic.co/beats/filebeat:7.5.2 

请注意容器链接:--link elasticsearch_container:elasticsearch,这是这里的关键.现在,由于elasticsearch_container对于名称为elasticsearch的文件拍子是可见的,因此我们需要以这种方式更改filebeat.yml:

Please note the container link: --link elasticsearch_container:elasticsearch which is the key here. Now, as the elasticsearch_container is visible to filebeat under the name elasticsearch, we need to change the filebeat.yml in that way:

output.elasticsearch:
  hosts: ["http://elasticsearch:9200"]

使用localhost的意思是从filebeat容器的角度来看,它不知道docker主机.因此,filebeat容器中的localhost可以解决filebeat容器本身的问题.但是,通过上面的配置更改,我们将其更改为链接的elasticsearch容器的名称,该怎么做.

Using localhost here is meant from the perspective of the filebeat container, which is unaware of the docker host. So localhost within the filebeat container adresses the filebeat container itself. But with the configuration change above, we changed it to the name of the linked elasticsearch container, what should do the trick.

3.基巴纳语

Kibana抱怨缺少与Elasticsearch的连接:

Kibana is complaining about missing connection to elasticsearch:

Unable to revive connection: http://elasticsearch:9200

这里与filebeat的情况相同:elasticsearch在名称为elasticsearch的kibana容器中不可见,而在elasticsearch_alias下可见.此外,ELASTICSEARCH_URL在您使用的版本中不是预期的配置. elasticsearch.hosts是正确的设置,默认为http://elasticsearch:9200.这是错误消息的根源:kibana无法识别ELASTICSEARCH_URL,回退到默认值并失败,因为elasticsearch_container被链接为elasticsearch_alias而不是elasticsearch.修复此问题很容易,因为我们只需要删除ELASTICSEARCH_URL并让kibana还原为默认值即可.为了使kibana可以看到elasticsearch,我们只需应用与文件拍子相同的链接即可:

Here it's the same case as for filebeat: elasticsearch is not visible to the kibana container under the name elasticsearch but elasticsearch_alias. Additionally, ELASTICSEARCH_URL is not an expected configuration in the version you are using. elasticsearch.hosts is the correct setting and defaults to http://elasticsearch:9200. And this is the root of the error message: kibana is not recognising ELASTICSEARCH_URL, falls back to the default value and fails because elasticsearch_container is linked as elasticsearch_alias and not as elasticsearch. Fixing this is easy, as we need just to remove ELASTICSEARCH_URL and let kibana fall back to the default. To make elasticsearch visible to kibana, we just apply the same link as we did for filebeat already:

docker run -d --name kibana -p 5601:5601 --link elasticsearch_container:elasticsearch docker.elastic.co/kibana/kibana:7.5.2

重要: 请在执行所讨论的更改之前处置(停止并删除)旧的容器实例,因为它们要求容器名称.

Important: Please dispose (stop & remove) the old container instances as they are claiming the container names before executing the discussed changes.