kafka自带维护脚本工具总结:
topic管理脚本:kafka-topics.sh(包括topic的创建,修改,删除,查询)
创建topic: sh kafka-topics.sh –zookeeper localip:2181 –create –topictest1 –partitions 4 --replication-factor 2
列出所有topic: sh kafka-topics.sh –zookeeper localip:2181 –list
显示某个topic的详细信息(包括partitions,leader partition,isr等):shkafka-topics.sh --zookeeper localip:2181 --describe --topic billtest
终止脚本:kafka-server-stop.sh
目前该脚本有问题,用netstat -anp|grep 端口号然后kill掉
启动脚本:kafka-server-start.sh
用法nohup sh kafka-server-start.sh ../config/server.properties &
自带的生产脚本:kafka-console-producer.sh
用法:sh kafka-console-producer.sh --broker-list xxxx,xxxxx,xxxxx --topic billtest
自带的消费脚本:用法:kafka-console-consumer.sh
sh kafka-console-consumer.sh--bootstrap-server xxxx,xxxxx,xxxxx --topic billtest
手工平衡(rebalance)脚本:kafka-preferred-replica-election.sh
用法:sh kafka-preferred-replica-election.sh --zookeeper localhost:2181
检查偏移量状态脚本:kafka-consumer-offset-checker.sh
用法 : sh kafka-consumer-offset-checker.sh --zookeeper localhost:2181 --group test --topicbilltest3 --broker-info (--broker-info显示broker_id和ip:端口的关联)
管理消费组的脚本:kafka-consumer-groups.sh(可以描述和删除消费者组)
用法:sh kafka-consumer-groups.sh --bootstrap-server xxxx,xxxx,xxxx --describe --group mytest
分区管理脚本:kafka-reassign-partitions.sh(该脚本是管理数据迁移,分布的重要工具)
用法:
1.产生候选作业:shkafka-reassign-partitions.sh --zookeeper localhost:2181 --topics-to-move-json-filetopics-to-move.json --broker-list "5,6" –generate(只是产生分配方案,还未执行)
> cattopics-to-move.json
{"topics": [{"topic":"foo1"},
{"topic":"foo2"}],
"version":1
}
2.执行分配作业:sh kafka-reassign-partitions.sh--zookeeper localhost:2181 --reassignment-json-fileexpand-cluster-reassignment.json –execute
--其实可以直接写分配作业json文件以供执行,json文件的格式也是很容易发现格式规范,expand-cluster-reassignment.json如下
{"version":1,
"partitions":[{"topic":"foo1","partition":2,"replicas":[5,6]},
{"topic":"foo1","partition":0,"replicas":[5,6]},
{"topic":"foo2","partition":2,"replicas":[5,6]},
{"topic":"foo2","partition":0,"replicas":[5,6]},
{"topic":"foo1","partition":1,"replicas":[5,6]},
{"topic":"foo2","partition":1,"replicas":[5,6]}]
}
--除了固定的”version":1和"partitions":外,里面的内容是最终要生成的分配方案,哪个topic的某个partition的副本replicas要分布到哪些节点上。
3.检查作业执行情况:kafka-reassign-partitions.sh--zookeeper localhost:2181 --reassignment-json-fileexpand-cluster-reassignment.json –verify
4.控制数据重分布的速度:kafka-reassign-partitions.sh--zookeeper myhost:2181--execute --reassignment-json-file bigger-cluster.json—throttle 50000000
为主题,客户端,用户或代理添加/删除实体配置的脚本:kafka-configs.sh
用法:in/kafka-configs.sh --zookeeperlocalhost:2181 --alter --add-config'producer_byte_rate=1024,consumer_byte_rate=2048' --entity-type clients--entity-default
安装目录和文件说明:
Data目录下的文件和子目录:
· cleaner-offset-checkpoint:存了每个log的最后清理offset
· meta.properties: broker.id 信息
· recovery-point-offset-checkpoint:表示已经刷写到磁盘的记录。recoveryPoint以下的数据都是已经刷到磁盘上的了。
· replication-offset-checkpoint: 用来存储每个replica的HighWatermark的(high watermark (HW),表示已经被commited的message,HW以下的数据都是各个replicas间同步的,一致的。)
子目录:类似__consumer_offsets-16(其中__consumer_offsets是topic名,16是partitions号)
子目录里面包含三类文件:
-rw-rw-r-- 1 itzxyy itzxyy 10485756 May 5 16:48 00000000000000000000.timeindex
-rw-rw-r-- 1 itzxyy itzxyy 10485760 May 5 16:48 00000000000000000000.index
-rw-rw-r-- 1 itzxyy itzxyy 303547066May 5 16:50 00000000000000000000.log
Timeindex是时间戳+偏移量组成的索引文件
Index是消息偏移量+物理偏移量组成的索引文件
Log是消息元信息和具体数据保存文件
Config目录下的文件:
server.properties 服务端的配置文件
producer.properties 可能是供自带生产脚本使用
consumer.properties可能是供自带消费脚本使用