首页 > 系统服务 > 详细

kafka_shell操作

时间:2019-03-03 16:30:36      阅读:195      评论:0      收藏:0      [点我收藏+]

单机版

  • 开启进程:

    ./bin/kafka-server-start.sh config/server.properties
  • 查看topic列表:

    ./bin/kafka-topics.sh --list --zookeeper localhost:2181
  • 创建topic:

    ./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic zhongqiu_test
  • 查看topic描述:

    ./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic zhongqiu_test
  • producer发送信息:

    ./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic zhongqiu_test
  • consumer接收信息:

    ./bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic zhongqiu_test --from-beginning
  • 删除topic:

    ./bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic zhongqiu_test 

集群版

  • 分别设置slave1、slave2两个节点的server.properties配置中的broker.id分别为1和2

  • 创建topic:

    ./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 5 --topic zhongqiu_many_brokers
    ?
  • 下面的命令会创建失败,原因是副本数大于实际broker个数

    ./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 4 --partitions 5 --topic zhongqiu_many_brokers_4reps
  • 查看topic描述:

    ./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic zhongqiu_many_brokers
    # 执行结果
    Topic:zhongqiu_many_brokers     PartitionCount:5       ReplicationFactor:3     Configs:
          Topic: zhongqiu_many_brokers   Partition: 0   Leader: 2       Replicas: 2,1,0 Isr: 0,1,2
          Topic: zhongqiu_many_brokers   Partition: 1   Leader: 0       Replicas: 0,2,1 Isr: 0,1,2
          Topic: zhongqiu_many_brokers   Partition: 2   Leader: 1       Replicas: 1,0,2 Isr: 0,1,2
          Topic: zhongqiu_many_brokers   Partition: 3   Leader: 2       Replicas: 2,0,1 Isr: 0,1,2
          Topic: zhongqiu_many_brokers   Partition: 4   Leader: 0       Replicas: 0,1,2 Isr: 0,1,2

kafka_shell操作

原文:https://www.cnblogs.com/zxbdboke/p/10466106.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!