繁体   English   中英

测试kafka消费者和生产者连接失败

[英]testing kafka consumer and producer failed on connection

我一直在尝试测试kafka安装并使用指南创建了一个生产者和消费者。 尝试检索邮件时,出现以下错误:

 WARN Session 0x0 for server null, unexpected error, closing socket connection and 
 attempting reconnect (org.apache.zookeeper.ClientCnxn)
 java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1146)
 [2014-03-04 18:01:20,628] INFO Terminate ZkClient event thread. (org.I0Itec.zkclient.ZkEventThread)
 [2014-03-04 18:01:21,315] INFO Opening socket connection to server kafka-test/192.xxxxxx.110:2182 (org.apache.zookeeper.ClientCnxn)
 [2014-03-04 18:01:21,418] INFO Session: 0x0 closed (org.apache.zookeeper.ZooKeeper)
 Exception in thread "main" org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server within timeout: 6000
    at org.I0Itec.zkclient.ZkClient.connect(ZkClient.java:880)
    at org.I0Itec.zkclient.ZkClient.<init>(ZkClient.java:98)
    at org.I0Itec.zkclient.ZkClient.<init>(ZkClient.java:84)
    at kafka.consumer.ZookeeperConsumerConnector.connectZk(ZookeeperConsumerConnector.scala:151)
    at kafka.consumer.ZookeeperConsumerConnector.<init>(ZookeeperConsumerConnector.scala:112)
    at kafka.consumer.ZookeeperConsumerConnector.<init>(ZookeeperConsumerConnector.scala:123)
    at kafka.consumer.Consumer$.create(ConsumerConnector.scala:89)
    at kafka.consumer.ConsoleConsumer$.main(ConsoleConsumer.scala:178)
    at kafka.consumer.ConsoleConsumer.main(ConsoleConsumer.scala)
 [2014-03-04 18:01:21,419] INFO EventThread shut down (org.apache.zookeeper.ClientCnxn)

卡夫卡

看起来你没有正确连接到Zookeeper。 我不确定你的设置(多机,虚拟机,容器),所以很难说出错了什么。 从调试输出中,我看到以下一行暗示您预期的Zookeeper IP:

[2014-03-04 18:01:21,315] INFO Opening socket connection to server kafka-test/192.xxxxxx.110:2182 (org.apache.zookeeper.ClientCnxn)

Kafka在$KAFKA_HOME/config/server.properties文件中的zookeeper.connect配置属性指定的地址处查找Zookeeper。 在开始Kafka之前一定要编辑它。 另外,尝试给出Zookeeper实例的实际公共IP,而不仅仅是127.0.0.1 ,因为如果你在容器中运行,它会解决很多混乱。 在你的情况下,它看起来像: zookeeper.connect=192.xxxxxx.110:2182

如果您在AWS上运行或在容器中运行,也与Kafka配置相关,请不要忘记更新以下两个配置属性,以确保连接到Kafka的客户端看到正确的公共IP

  • advertised.host.name
  • advertised.port

和Kafka看到正确的内部IP

  • host.name
  • port

动物园管理员

Zookeeper在设置时也有一些问题。 在Zookeeper实例上,不要忘记编辑zoo.cfg (通常在/etc/zookeeper/conf )文件中的server配置属性,以指向Zookeeper实例的正确IP。 在您的情况下可能如下:

server.1=192.xxxxxx.110:2888:3888

只有当你运行Zookeeper集群时才需要最后两个端口(2888 3888)(分别为追随者连接到领导者和Zookeeper领导者选举,所以如果你有多个Zookeeper服务器,请务必在防火墙上取消阻止它们) 。

使用telnet命令检查zookeeper连接:

telnet 192.xxxxxx.110 2181

您可能会收到错误,在这种情况下检查进程是否正在运行:

ps -ef | grep“zookeeper.properties”

如果它没有运行,请通过进入kafka主目录启动它:

bin / zookeeper-server-start.sh config / zookeeper.properties&

您的Zookeper配置有问题。 确保您的zookeeper已启动并正在运行。 它运行的默认端口是2181

我相信更多的信息和一些code可能是有用的。

我遇到了同样的问题,问题是zookeeper配置中的max client连接属性。

如果你在/ etc / zookeeper / conf的配置文件中看到类似“maxClientCnxns = 20”的内容,请将其注释掉并重新启动zookeeper。

您还可以检查所有可用连接是否已用尽。 如果您使用API​​连接到ZK,请确保在完成后释放连接。

我也遇到了这个问题。 当我关闭zk节点的防火墙时,它会工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM