使用kafka-lenses-dev图像时,我遇到了将Kafka连接到本地Elasticsearch 7.1.1实例的问题。如您所见,尽管实例已启动并且正在运行,并且可以卷曲文档,但连接被拒绝。Elastic的版本是否对连接器有问题或配置是否错误?
配置
connector.class=io.confluent.connect.elasticsearch.ElasticsearchSinkConnector
type.name=kafka-connect
key.converter.schemas.enable=false
topics=cc_data
name=elastic-sink
value.converter.schemas.enable=false
connection.url=http://localhost:9200
key.ignore=true
错误
org.apache.kafka.connect.errors.ConnectException: Couldn't start ElasticsearchSinkTask due to connection error:
at io.confluent.connect.elasticsearch.jest.JestElasticsearchClient.<init>(JestElasticsearchClient.java:147)
at io.confluent.connect.elasticsearch.jest.JestElasticsearchClient.<init>(JestElasticsearchClient.java:114)
at io.confluent.connect.elasticsearch.ElasticsearchSinkTask.start(ElasticsearchSinkTask.java:120)
...
Caused by: io.searchbox.client.config.exception.CouldNotConnectException: Could not connect to http://localhost:9200
at io.searchbox.client.http.JestHttpClient.execute(JestHttpClient.java:60)
at io.confluent.connect.elasticsearch.jest.JestElasticsearchClient.getServerVersion(JestElasticsearchClient.java:168)
at io.confluent.connect.elasticsearch.jest.JestElasticsearchClient.<init>(JestElasticsearchClient.java:145)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:9200 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
...
Caused by: java.net.ConnectException: Connection refused (Connection refused)
...
答案 0 :(得分:1)
您已将Elasticsearch指定为localhost:9200
。除非Elasticsearch与Kafka Connect在同一容器上运行 ,否则该主机名是错误的。您需要以一种可从Kafka Connect运行位置访问的形式指定Elasticsearch的主机名。
作为示例,您可以看到一个基于this Docker Compose here进行配置的示例。