kafka消费者启动报错

报错信息:

 WARN Fetching topic metadata with correlation id 14 for topics [Set(test)] from broker [BrokerEndPoint(2,ubuntu,9092)] failed (kafka.client.ClientUtils$)

WARN Fetching topic metadata with correlation id 14 for topics [Set(test)] from broker [BrokerEndPoint(2,ubuntu,9092)] failed (kafka.client.ClientUtils$)
java.nio.channels.ClosedChannelException
    at kafka.network.BlockingChannel.send(BlockingChannel.scala:112)
    at kafka.producer.SyncProducer.liftedTree1$1(SyncProducer.scala:80)
    at kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(SyncProducer.scala:79)
    at kafka.producer.SyncProducer.send(SyncProducer.scala:124)
    at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:61)
    at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:96)
    at kafka.consumer.ConsumerFetcherManager$LeaderFinderThread.doWork(ConsumerFetcherManager.scala:68)
    at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:64)
^X[2019-01-18 15:54:50,516] WARN Fetching topic metadata with correlation id 17 for topics [Set(test)] from broker [BrokerEndPoint(2,ubuntu,9092)] failed (kafka.client.ClientUtils$)
java.nio.channels.ClosedChannelException
    at kafka.network.BlockingChannel.send(BlockingChannel.scala:112)
    at kafka.producer.SyncProducer.liftedTree1$1(SyncProducer.scala:80)
    at kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(SyncProducer.scala:79)
    at kafka.producer.SyncProducer.send(SyncProducer.scala:124)
    at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:61)
    at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:96)
    at kafka.consumer.ConsumerFetcherManager$LeaderFinderThread.doWork(ConsumerFetcherManager.scala:68)
    at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:64)

 

  问题:可以非常明显的看到

  这个主机名是ubuntu,这个名字在hosts文件中我没有配置映射,非常粗心的一个问题。

  解决:在/etc/hosts文件中添加主机名和ip映射。

  说明:这个kafka相互通信连接的时候是默认拿着主机名加端口号的,而我开始在hosts文件中映射的ip并不是使用的主机名,因为几台机器的主机名命名不规范,所以我的映射文件是统一命名py101、py102、py103这种。而kafka默认拿着主机名寻找映射信息,然而hosts文件中没有,故报错。

 

posted @ 2019-01-18 16:19  董秀才  阅读(2718)  评论(0编辑  收藏  举报