更新时间:2022-07-14 GMT+08:00
分享

Shell命令

  1. 查看当前集群Topic列表。

    bin/kafka-topics.sh --list --zookeeper <ZooKeeper集群IP:2181/kafka>

    bin/kafka-topics.sh --list --bootstrap-server <Kafka集群IP:21007> --command-config config/client.properties

  2. 查看单个Topic详细信息。

    bin/kafka-topics.sh --describe --zookeeper <ZooKeeper集群IP:2181/kafka> --topic <Topic名称>

    bin/kafka-topics.sh --describe --bootstrap-server <Kafka集群IP:21007> --command-config config/client.properties --topic <Topic名称>

  3. 删除Topic,由管理员用户操作。

    bin/kafka-topics.sh --delete --zookeeper <ZooKeeper集群IP:2181/kafka> --topic <Topic名称>

    bin/kafka-topics.sh --delete --bootstrap-server <Kafka集群IP:21007>--command-config config/client.properties --topic <Topic名称>

  4. 创建Topic,由管理员用户操作。

    bin/kafka-topics.sh --create --zookeeper <ZooKeeper集群IP:2181/kafka> --partitions 6 --replication-factor 2 --topic <Topic名称>

    bin/kafka-topics.sh --create --bootstrap-server <Kafka集群IP:21007> --command-config config/client.properties --partitions 6 --replication-factor 2 --topic <Topic名称>

  5. 赋Consumer权限命令,由管理员用户操作。

    bin/kafka-acls.sh --authorizer-properties zookeeper.connect=<ZooKeeper集群IP:2181/kafka > --add --allow-principal User:<用户名> --consumer --topic <Topic名称> --group <消费者组名称>

    bin/kafka-acls.sh --bootstrap-server <Kafka集群IP:21007> --command-config config/client.properties --add --allow-principal User:<用户名> --consumer --topic <Topic名称> --group <消费者组名称>

  6. 赋Producer权限命令,由管理员用户操作。

    bin/kafka-acls.sh --authorizer-properties zookeeper.connect=<ZooKeeper集群IP:2181/kafka > --add --allow-principal User:<用户名> --producer --topic <Topic名称>

    bin/kafka-acls.sh --bootstrap-server <Kafka集群IP:21007> --command-config config/client.properties --add --allow-principal User:<用户名> --producer --topic <Topic名称>

  7. 生产消息,需要拥有该Topic生产者权限。

    bin/kafka-console-producer.sh --broker-list <Kafka集群IP:21007> --topic <Topic名称> --producer.config config/producer.properties

  8. 消费数据,需要拥有该Topic的消费者权限

    bin/kafka-console-consumer.sh --topic <Topic名称> --bootstrap-server <Kafka集群IP:21007> --consumer.config config/consumer.properties

分享:

    相关文档

    相关产品