cdh安装的kafka在linux里面创建topic主题报错:Replication factor: 1 larger than available brokers: 0

遇到问题

用CDH搭建的kafka集群,想通过linux的kafka直接创建topic主题来测试一下kafka

kafka-topics --zookeeper localhost:2181 --create -replication-factor 1 --partitions 3 --topic test

直接报错

20/07/17 14:30:54 INFO zookeeper.ZooKeeper: Client environment:user.dir=/opt/cloudera/parcels/KAFKA-3.1.0-1.3.1.0.p0.35/lib/kafka/bin
20/07/17 14:30:54 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=192.168.1.112:2181 sessionTimeout=30000 watcher=org.I0Itec.zkclient.ZkClient@52e6fdee
20/07/17 14:30:54 INFO zkclient.ZkClient: Waiting for keeper state SyncConnected
20/07/17 14:30:54 INFO zookeeper.ClientCnxn: Opening socket connection to server datalinux3/192.168.1.112:2181. Will not attempt to authenticate using SASL (unknown error)
20/07/17 14:30:54 INFO zookeeper.ClientCnxn: Socket connection established, initiating session, client: /192.168.1.109:44623, server: datalinux3/192.168.1.112:2181
20/07/17 14:30:54 INFO zookeeper.ClientCnxn: Session establishment complete on server datalinux3/192.168.1.112:2181, sessionid = 0x3735b5800ab0048, negotiated timeout = 30000
20/07/17 14:30:54 INFO zkclient.ZkClient: zookeeper state changed (SyncConnected)
WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both.
Error while executing topic command : Replication factor: 1 larger than available brokers: 0.
20/07/17 14:30:54 ERROR admin.TopicCommand$: org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 1 larger than available brokers: 0.

直接报错

Error while executing topic command : Replication factor: 1 larger than available brokers: 0.
20/07/17 14:30:54 ERROR admin.TopicCommand$: org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 1 larger than available brokers: 0.

问题解决

需要看 CDH 中 kafka broker 的属性:zookeeper.chroot 这个属性与 kafka 创建 topic 后,信息存放的路径有关。然后我看了看同事配置的CDH中的 zookeeper.chroot 属性,原来是/kafka。如下图:
cdh安装的kafka在linux里面创建topic主题报错:Replication factor: 1 larger than available brokers: 0_第1张图片
如果这里设置 zookeeper.chroot 为 /kafka。那么对应的,我们需要在/kafka 路径下创建topic。所以创建topic指令如下:

kafka-topics --zookeeper localhost:2181/kafka --create -replication-factor 1 --partitions 3 --topic test

我们只需在localhost:2181后加 /kafka 即可。

你可能感兴趣的:(大数据,基础)