--create topic
/usr/local/kafka/bin/kafka-topics.sh --bootstrap-server ip:9092 -replication-factor 3 --partitions 10 --create --topic test
--show topic
/usr/local/kafka/bin/kafka-topics.sh --bootstrap-server ip:9092 --list|grep topic_name
--delete topic
/usr/local/kafka/bin/kafka-topics.sh --bootstrap-server ip:9092 --delete --topic test
--ConsumeMessage
/usr/local/kafka/bin/kafka-console-consumer.sh --bootstrap-server ip:9092 --topic test --from-beginning --max-messages 1
--ProduceMessage
/usr/local/kafka/bin/kafka-console-producer.sh ----bootstrap-server ip:9092 --topic test
--Addconfig
/usr/local/kafka/bin/kafka-configs.sh --bootstrap-server ip:9092 --entity-type topics--entity-name test --alter --add-config retention.ms=259200000
--TOpicDescribe
/usr/local/kafka/bin/kafka-topics.sh --bootstrap-server ip:9092 --describe --topic
--renew replicate copies 动态重新分布副本数量
/usr/local/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server ip:9092 -reassignment-jason-file increase-replication-factor.json -execute
--动态调整分布文档
/usr/local/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server ip:9092 -reassignment-jason-file increase-replication-factor.json -verify
--动态调整分布文档
increase-replication-factor.json{"version".2,"partitions":[{"topic"."_consumer_offsets","partition":1"replicas":[1,2,3]},{"topic"."_consumer_offsets","partition":1"replicas":[1,2,3]},{"topic"."_consumer_offsets","partition":1"replicas":[1,2,3]},]}
-- 查看topic 设置
/usr/local/kafka/bin/kafka-configs.sh --bootstrap-server kafka 地址:9001 --describe --entity-name newgameimesports --entity-type topics
--单独对某个topic 设置过期时间
/usr/local/kafka/bin/kafka-configs.sh --bootstrap-server kafka地址:9001 --alter --entity-name topic 名称 --entity-type topics --add-config retention.ms=86400000
--批量调整&查看topic 过期时间
##需要将调整的topic 写入文本,例如以下是将newgame 关键词的topic 写入文本
/usr/local/kafka/bin/kafka-topics.sh --list --zookeeper localhost:2181 | grep newgame >>/tmp/topicname.txt
##批量调整 topicname.txt 中的topic 过期时间,一下调整过期时间为30天
cat topicname.txt | while read line; do echo $line; /user/local/kafka/bin/kafka-configs.sh --zookeeper localhost:2181 --alter--entity-name $line --entity-type topics --add-config retention.ms=2592000000; done
## 批量查看topicname.txt中的topic 设置
cat topicname.txt | while read line; do echo $line; /usr/local/kafka/bin/kafka-config.sh --bootstrap-server 192.168..10.0:9001 --descirbe --entity-name $line --entity-type topics
kafka management script
于 2024-05-06 16:59:48 首次发布