我按如下所示键入命令行。但它显示它无法连接到localhost:2181。我已经开始了动物园管理员。
bin / kafka-console-consumer.sh --zookeeper --localhost:2181 --topic pain - from-beginning
Exception in thread "main" org.I0Itec.zkclient.exception.ZkException: Unable to connect to --localhost:2181
at org.I0Itec.zkclient.ZkConnection.connect(ZkConnection.java:66)
at org.I0Itec.zkclient.ZkClient.connect(ZkClient.java:876)
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:171)
at kafka.consumer.ZookeeperConsumerConnector.<init>(ZookeeperConsumerConnector.scala:126)
at kafka.consumer.ZookeeperConsumerConnector.<init>(ZookeeperConsumerConnector.scala:143)
at kafka.consumer.Consumer$.create(ConsumerConnector.scala:94)
at kafka.tools.ConsoleConsumer$.main(ConsoleConsumer.scala:145)
at kafka.tools.ConsoleConsumer.main(ConsoleConsumer.scala)
Caused by: java.net.UnknownHostException: --localhost
at java.net.InetAddress.getAllByName0(InetAddress.java:1252)
at java.net.InetAddress.getAllByName(InetAddress.java:1164)
at java.net.InetAddress.getAllByName(InetAddress.java:1098)
at org.apache.zookeeper.client.StaticHostProvider.init(StaticHostProvider.java:61)
at org.apache.zookeeper.ZooKeeper.<init>(ZooKeeper.java:445)
at org.apache.zookeeper.ZooKeeper.<init>(ZooKeeper.java:380)
at org.I0Itec.zkclient.ZkConnection.connect(ZkConnection.java:64)
... 9 more
[root@crxy2 kafka_2.10-0.8.2.0]# jps
5487 QuorumPeerMain
5862 Jps
5518 Kafka
[root@crxy2 kafka_2.10-0.8.2.0]# bin/kafka-topics.sh --zookeeper localhost:2181 --list
pain
答案 0 :(得分:1)
应为bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic pain --from-beginning
请注意--zookeeper localhost:2181
而不是--zookeeper --localhost:2181
答案 1 :(得分:0)
尝试以下命令:
bin/kafka-console-consumer.sh --bootstrap-server localhost:9093 --topic pain --from beginning
这里我假设您的kafka代理或kafka服务器之一正在本地主机上运行:9093
如果未提供地址给任何一位活跃的kafka经纪人作为参数 --bootstrap-server