Kafka3.0版本 日常使用指令

1. 启动指令.

nohup ./kafka-server-start.sh ../config/server.properties &

2. topic 管理指令

2.1 查看topic

./kafka-topics.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --list

2.2 创建topic

./kafka-topics.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092  --create --topic test-topic --replication-factor 3 --partitions 3

2.3查看topic 详细信息

./kafka-topics.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --describe --topic test-topic

 2.4 修改topic日志存储时长(单位: ms).

kafka-configs.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092  --entity-type topics --entity-name test-topic --alter --add-config retention.ms=86400000

 2.5 修改topic 分区数据

./kafka-topics.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 -alter --partitions 4 --topic test-topic

 2.6 修改topic 副本数,不推荐使用,建议重新创建topic .

vim   increase-replication-factor.json 

{
"version":1,
"partitions":[{"topic":"test-topic","partition":0,"replicas":[0,1]},
{"topic":"three","partition":1,"replicas":[0,1]},
{"topic":"three","partition":2,"replicas":[1,0]},
{"topic":"three","partition":3,"replicas":[1,0]}]
}

执行副本存储计划

./kafka-reassign-partitions.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --reassignment-json-file increase-replication-factor.json --execute

 验证副本存储计划

./kafka-reassign-partitions.sh --

bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --reassignment-json-file increase-replication-factor.json --verify

 3. 生产者和消费者

3.1 生产者

./kafka-console-producer.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092  --topic test-topic

3.2 消费者

3.2.1 从创建topic开始消费

./kafka-console-consumer.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092  --topic test-topic --from-beginning

3.2.2从最新数据开始消费.

./kafka-console-consumer.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --topic test-topic

3.3 消费者

./kafka-console-producer.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092  --topic test-topic

4. topic 压测

4.1 生产者压测:

./kafka-producer-perf-test.sh --topic test-topic --record-size 1024 --num-records 1000000 --throughput -1 --producer-props bootstrap.servers=hdp1:9092,hdp2:9092,hdp3:9092 batch.size=4096 linger.ms=0

4.2 消费者压测:

./kafka-consumer-perf-test.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092  --topic test-topic --messages 1000000 --consumer.config ../config/consumer.properties

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值