未知主机异常卡夫卡

编程入门 行业动态 更新时间:2024-10-28 16:25:13
本文介绍了未知主机异常卡夫卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试设置 Kafka 集群(实际上是集群中的第一个节点).

I am trying to setup a Kafka cluster (the first node in the cluster actually).

我有一个单节点的 zookeeper 集群设置.我正在一个单独的节点上设置 kafka.

I have a single node zookeeper cluster setup. I am setting up kafka on a separate node.

两者都运行 CentOS 6.4,运行有点像 PITA 的 IPV6.我验证了这些机器可以使用 netcat 相互通信.

Both running CentOS 6.4, running IPV6 which is a bit of a PITA. I verified that the machines can talk to each other using netcat.

当我启动 kafka 时,出现以下异常(导致 kafka 关闭).我启动了 kafka,我必须在 server.config 文件中设置 host.name 属性.

When I startup kafka, I am getting the following exception (which causes kafka to shut down). I got kafka starting, I had to set the host.name property in the server.config file.

我能够创建一个测试主题并从 kafka 服务器正常发送消息.

I was able to create a test topic and send messages just fine from the kafka server.

但是,我在尝试使用消息时遇到了同样的错误.

However, I get the same error when trying to consume the messages.

有什么帮助、建议吗?

bin/kafka-console-consumer.sh --zookeeper zk1:2181 --topic test --from-beginning
Exception in thread "main" java.UnknownHostException: kafka: kafka: Name or service not known
    at java.InetAddress.getLocalHost(InetAddress.java:1473)
    at kafka.consumer.ZookeeperConsumerConnector.<init>(ZookeeperConsumerConnector.scala:107)
    at kafka.consumer.ZookeeperConsumerConnector.<init>(ZookeeperConsumerConnector.scala:128)
    at kafka.consumer.Consumer$.create(ConsumerConnector.scala:89)
    at kafka.consumer.ConsoleConsumer$.main(ConsoleConsumer.scala:178)
    at kafka.consumer.ConsoleConsumer.main(ConsoleConsumer.scala)
Caused by: java.UnknownHostException: kafka: Name or service not known
    at java.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
    at java.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
    at java.InetAddress.getLocalHost(InetAddress.java:1469)
    ... 5 more

推荐答案

当你运行 >bin/kafka-console-consumer.sh 命令 kafka 加载一个 ConsoleConsumer,它将尝试使用自动生成的消费者 ID 创建消费者.Kafka 生成消费者 id 的方式是将本地主机的名称连接到它.因此,问题在于 java 无法解析我正在使用的 Open Stack VM 上本地主机的 IP 地址.

When you run > bin/kafka-console-consumer.sh command kafka loads a ConsoleConsumer, which will attempt to create a consumer with an auto generated consumer id. The way Kafka generates the consumer id is to concatenate the name of the local host to it. So, in the problem was the fact that java could not resolve the ip address for local host on the Open Stack VM I am working with.

所以答案是 Open Stack VM 将本地主机名解析为 kafka,这是 VM 的名称.我在 Kafka 和 Zookeeper 实例中将所有内容设置为 kafka1.

So the answer was that the Open Stack VM was resolving the local host name to kafka, which is the name of the VM. I had everything setup in the Kafka and Zookeeper instances as kafka1.

因此,当 java 调用 getLocalHost 时,它试图找到 kafka 的 IP 地址,而我的/etc/hosts 文件中没有.

So, when java was calling getLocalHost, it was trying to find the IP Address for kafka, which I did not have in my /etc/hosts file.

我只是在我的/etc/hosts 文件中为 kafka 添加了一个条目,一切都开始正常运行!!!

I simply added an entry for kafka in my /etc/hosts file and everything started working wonderfully!!!

我以为它会解析为 localhost,但它没有,它解析为 vm 的名称,kafka.

I would have thought it would resolve to localhost, but it did not, it resolved to the name of the vm, kafka.

这篇关于未知主机异常卡夫卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-18 17:55:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/943832.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:卡夫卡   异常   主机

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!