UnknownHostException卡夫卡

编程入门 行业动态 更新时间:2024-10-21 20:27:49
本文介绍了UnknownHostException卡夫卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试设置一个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,运行的IPV6有点PITA.我验证了这些机器可以使用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文件中拥有该IP地址.

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,但是没有,它解析为虚拟机的名称kafka.

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

更多推荐

UnknownHostException卡夫卡

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

发布评论

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

>www.elefans.com

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