UnknownHostException卡夫卡 [英] UnknownHostException kafka

查看:263
本文介绍了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.net.UnknownHostException: kafka: kafka: Name or service not known
    at java.net.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.net.UnknownHostException: kafka: Name or service not known
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
    at java.net.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卡夫卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆