前台启动brokershell
bin/kafka-server-start.sh <path>/server.properties复制代码
Ctrl + C 关闭bootstrap
后台启动broker工具
bin/kafka-server-start.sh -daemon <path>/server.properties复制代码
关闭brokerui
bin/kafka-server-stop.sh复制代码
建立topicspa
bin/kafka-topics.sh --create --zookeeper localhost:2181 --partitions 3 --replication-factor 3 --topic topicname 复制代码
删除topiccode
bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic topicname 复制代码
查询topic列表orm
bin/kafka-topics.sh --zookeeper localhost:2181 --list复制代码
查询topic详情cdn
bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic topicname 复制代码
修改topicserver
bin/kafka-topics.sh --alter --zookeeper localhost:2181 --partitions 6 --topic topicname 复制代码
查询消费者组kafka
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list 复制代码
查询消费者组详情
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group groupname 复制代码
重设消费者组位移
最先处
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group groupname --reset-offsets --all-topics --to-earliest --execute
最新处
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group groupname --reset-offsets --all-topics --to-latest --execute
某个位置
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group groupname --reset-offsets --all-topics --to-offset 2000 --execute
调整到某个时间以后得最先位移
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group groupname --reset-offsets --all-topics --to-datetime 2019-09-15T00:00:00.000复制代码
删除消费者组
bin/kafka-consumer-groups.sh --zookeeper localhost:2181 --delete --group groupname复制代码
producer脚本
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic topicname
参数含义:
--compression-codec lz4 压缩类型
--request-required-acks all acks的值
--timeout 3000 linger.ms的值
--message-send-max-retries 10 retries的值
--max-partition-memory-bytes batch.size值复制代码
consumer脚本
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topicname --from-beginning
指定groupid
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topicname --from-beginning
--consumer-property group.id=old-consumer-group
指定分区
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topicname --from-beginning
--partition 0复制代码
kafka-run-class脚本
kafka-run-class.sh kafka.tools.ConsoleConsumer 就是 kafka-console-consumer.sh
kafka-run-class.sh kafka.tools.ConsoleProducer 就是 kafka-console-producer.sh复制代码
获取topic当前消息数
kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic topicname --time -1复制代码
--time -1表示最大位移 --time -2表示最先位移
查询consumeroffsets
bin/kafka-simple-consumer-shell.sh --topic _consumer_offsets --partition 12 --broker-list localhost:9092 --formatter "kafka.coorfinator.GroupMetadataManager\$OffsetsMessageFormatter"复制代码
跨机房灾备工具
bin/kafka-mirror-maker.sh --consumer.config consumer.properties --producer.config producer.properties --whitelist topicA|topicB复制代码
更多实时计算,Flink,Kafka等相关技术博文,欢迎关注实时流式计算