最新消息:

Kafka常用命令

Linux ipcpu 2833浏览

Kafka常用命令.md

Topic相关

##查看所有topic
./kafka-topics.sh --zookeeper localhost:2181 --list
##查看topic详情(分区和副本)
./kafka-topics.sh --zookeeper localhost:2181 --describe --topic topic.dau
##查看UnderReplicated失效分区
./kafka-topics.sh --zookeeper localhost:2181 --describe --under-replicated-partitions

消费者相关

##查看所有消费者列表
./kafka-consumer-groups.sh --bootstrap-server 172.28.9.65:9092 --list
(只能显示non-ZooKeeper-based consumers)
./kafka-consumer-groups.sh --zookeeper localhost:2181 --list
(只能显示ZooKeeper消费者)
##查看消费者详细信息(包含IP地址和端口信息)
./kafka-consumer-groups.sh --bootstrap-server 172.28.0.65:9092 --describe --group group_new_device
./kafka-consumer-groups.sh --zookeeper 127.0.0.1:2181 --describe --group ip_save

增加topic分区数

./kafka-topics.sh --zookeeper localhost:2181 --topic nginxaccess --alter --partitions 3

这里有一点需要格外注意,kafka不支持减少分区数,可能是实现上比较复杂吧,需要考虑减少的分区数据问题。而副本数可以增加也可以减少。
另外,增加了分区以后,生产者可能需要重启一下,否则在短时间内新增的分区没有数据。

增加或者减少topic分区的副本

先查询现有topic的partitions和现有副本的分布情况

 ./kafka-topics.sh --zookeeper localhost:2181 --describe --topic nginxaccess

然后编写json文件

cat > increase-replication-factor.json <<EOF
{"version":1, "partitions":[
{"topic":"topicpc","partition":0,"replicas":[0,1]},
{"topic":"topicpc","partition":1,"replicas":[1,2]},
{"topic":"topicpc","partition":2,"replicas":[0,2]}]
}
EOF

然后执行重分配

./kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file increase-replication-factor.json --execute

默认分区和副本数

server.properties

num.partitions=3
default.replication.factor=2

参考资料

http://orchome.com/454

转载请注明:IPCPU-网络之路 » Kafka常用命令