kafka之运维命令

本文介绍了Kafka的运维命令,包括查看版本、管理主题、生产与消费数据、集群监控及压测等操作。如创建、删除主题,查看消费组信息,以及进行消息积压的统计等。
摘要由CSDN通过智能技术生成

kafka版本声明

  1. 使用的是kafka 0.10.0.1版本

常用命令

查看kafka版本

  1. 查看kafka版本

    # find / -name \*kafka_\* | head -1 | grep -o '\kafka[^\n]*'
    

主题

  1. 创建TopicPartition(5个),replication(1个)

    # bin/kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 5 --topic testTopic
    
  2. 查看Topic最大(最小)的offset,--time,-1表示最大,-2表示最小

     # bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 -topic topic-A --time -1
    
    topic-A:2:60
    topic-A:4:60
    topic-A:1:60
    topic-A:3:60
    topic-A:0:60
    
  3. 列出集群中所有的topic

    # bin/kafka-topics.sh --zookeeper zookeeper:2181 --list
    
  4. 查看Topic明细

     # bin/kafka-topics.sh --describe --zookeeper zookeeper:2181 --topic testTopic
    
    Topic:testTopic	  PartitionCount:5	ReplicationFactor:1 Configs:
    Topic: testTopic	Partition: 0	Leader: 1  Replicas: 1 Isr: 1
    Topic: testTopic	Partition: 1	Leader: 1  Replicas: 1 Isr: 1
    Topic: testTopic	Partition: 2	Leader: 1  Replicas: 1 Isr: 1
    Topic: testTopic	Partition: 3	Leader: 1  Replicas: 1 Isr: 1
    Topic: testTopic	Partition: 4	Leader: 1  Replicas: 1 Isr: 1
    
  5. 修改topic参数,partitions个数只能被增加不能减少。如果一定要减少partitions个数,只能删除整个主题,重新建立

     # bin/kafka-topics.sh --zookeeper zookeeper:2181 --partition 6 --topic testTopic --alter
    
  6. 删除Topicbrokerdelete.topic.enable=true才可以删除,否则删除topic的请求会被忽略.删除topic会丢弃topic里所有数据。

    # bin/kafka-topics.sh --zookeeper zookeeper:2181 --delete --topic topicAgroup
    

生产

  1. 生产数据

    # bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test --producer.config config/producer.properties
    

消费

  1. 消费

    # bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --new-consumer --from-beginning --consumer.config config/consumer.properties
    
    # bin/kafka-simple-consumer-shell.sh --brist localhost:9092 --topic test --partition 0 --offset 1234  --max
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值