kafka 脚本学习 (基于2.8.0-0.8.1)

1:kafka-topics.sh(如果没有返回信息,说明命令无效)

创建一个top

名字:gbz4,zookeeper地址:本机,两个分区,两个副本
./bin/kafka-topics.sh -create --topic 'gbz4' --zookeeper '127.0.0.1' --partitions 2 --replication-factor 2

 查看zookeeper上有多少个topic

./bin/kafka-topics.sh --list --zookeeper '127.0.0.1'

 查看topic的具体信息

./bin/kafka-topics.sh --zookeeper '127.0.0.1' --describe

 删除topic

./bin/kafka-topics.sh --delete --zookeeper '127.0.0.1' --topic 'gbz4'

 修改(如果没有这个topic哪么不显示成功,注意)

./bin/kafka-topics.sh --alter --zookeeper '127.0.0.1' --topic 'gbz1'   --partitions 3

 修改,创建,删除它全包了(config是属性,后面可跟alter,delete,create等)

./bin/kafka-topics.sh --config 'partitions=3' -zookeeper '127.0.0.1' --topic 'gbz4' --alter

 删除配置(partitions是必须要的,会报错,这里只告诉用法)

./bin/kafka-topics.sh --deleteConfig 'partitions' -zookeeper '127.0.0.1' --topic 'gbz4' --alter

 显示分区的Leader不可用的

./bin/kafka-topics.sh --unavailable-partitions --describe --zookeeper '127.0.0.1' --topic 'gbz1'

 显示副本少于配置的分区

./bin/kafka-topics.sh --under-replicated-partitions --describe --zookeeper '127.0.0.1' --topic 'hb4'

 显示tipic有覆盖的配置

./bin/kafka-topics.sh --topics-with-overrides --describe --zookeeper '127.0.0.1' --topic 'gbz'

 2:kafka-simple-consumer-shell.sh(起作用的都是最后的参数)

查看topic在分区上的数据

./kafka-simple-consumer-shell.sh --broker-list 192.168.230.131:9092,192.168.230.130:9092,192.168.230.129:9092 --topic gbz4 --partition 0

 得到消息的数量

./kafka-simple-consumer-shell.sh --broker-list 192.168.230.131:9092,192.168.230.130:9092,192.168.230.129:909--topic gbz4 --partition 0 --max-messages 1

 显示offset 并跳过错误的信息

./kafka-simple-consumer-shell.sh --broker-list 192.168.230.131:9092,192.168.230.130:9092,192.168.230.129--topic gbz4 --partition 0 --print-offsets --skip-message-on-error

 显示offset之后的信息

./kafka-simple-consumer-shell.sh --broker-list 192.168.230.131:9092,192.168.230.130:9092,192.168.230.129:909--topic gbz4 --partition 0 --print-offsets --skip-message-on-error --offset 2

 显示完就退出

./kafka-simple-consumer-shell.sh --broker-list 192.168.230.131:9092,192.168.230.130:9092,192.168.230.129:9092 --topic gbz4 --partition 0 --print-offsets --skip-message-on-error --no-wait-at-logend

 3:./kafka-preferred-replica-election.sh  数据迁移用

./kafka-preferred-replica-election.sh --zookeeper 127.0.0.1:2181 --path-to-json-file /root/a.json

 文件格式

{"partitions":
[{"topic": "foo", "partition": 1},
{"topic": "foobar", "partition": 2}]
}

 

后续更新中。。。。

你可能感兴趣的:(kafka)