2014-03-06 97 views
7

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

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) 

回答

3

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

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

4

请与telnet命令你的动物园管理员连接:在这种情况下,检查该进程正在运行

telnet 192.xxxxxx.110 2181

你可能会得到一个错误,:

ps -ef | grep "zookeeper.properties"

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

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

2

我碰到同样的问题,问题是最大客户端连接属性在zookeeper配置。

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

7

卡夫卡

看起来你没有连接到正确的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_HOME/config/server.properties文件zookeeper.connect配置属性所指定的地址。开始Kafka之前一定要编辑它。另外,请尝试给出您的Zookeeper实例的实际公共IP,而不仅仅是127.0.0.1,因为如果您在容器中运行,那么解决了很多混乱。在你的情况下,它看起来会是: zookeeper.connect=192.xxxxxx.110:2182

此外,如果你在AWS上运行或在容器操作相关的卡夫卡配置时,不要忘记更新下面的两个配置属性,以确保客户谁连接到卡夫卡看到正确的公共IP

  • advertised.host.name
  • advertised.port

和卡夫卡认为正确的内部IP

  • host.name
  • port

动物园管理员

动物园管理员设置它最多时也有一些陷阱。在您的Zookeeper实例上,不要忘记编辑zoo.cfg(通常在/etc/zookeeper/conf)文件中的server配置属性,以指向Zookeeper实例的正确IP。你的情况可能如下:

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

最后两个端口(2888 3888)如果你正在运行一个动物园管理员组(追随者分别与领导和动物园管理员领导人选举,只需要,所以如果你有多个Zookeeper服务器,一定要在防火墙的东西上解锁它们)。

+1

谢谢@ joel-b,这让我朝着正确的方向前进。 advertised.host.name现已弃用,因此您需要使用advertised.listeners代替。 – ammills01

0

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

0

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