赞
踩
创建分区:
/path/to/kafka_home/bin/kafka-topics.sh --bootstrap-server 192.168.233.128:9092 --create --topic quickstart76-events --partitions 6 --replication-factor 2
说明:
--bootstrap-server:kafka集群的一个或多个broker地址,通过这个地址和整个kafka集群交互,也可以通过--zookeeper 参数来连接集群
--create:创建命令,同级别的还有--delete(删除)、--alter(修改)、--describe(查看详情)
--topic:制定topic的名称
--partitions:指定这个topic的分区数,分区可以将数据均衡开,不管是对生产端还是消费端。
--replication-factor:指定这个topic的每个分区的副本数,默认是1,表示只有leader,没有follower。这个参数不能设置大于集群中broker的数量,否则会报错。副本数越大写的代价就越高,但是数据丢失的可能性就越小。
查看刚刚创建好的topic
/path/to/kafka_home/bin/kafka-topics.sh --bootstrap-server 192.168.233.132:9092 --topic quickstart76-events --describe
得到结果
- Topic: quickstart76-events TopicId: RTYJMgt-SbSPERLyUkAI6Q PartitionCount: 6 ReplicationFactor: 2 Configs: segment.bytes=1073741824
- Topic: quickstart76-events Partition: 0 Leader: 3 Replicas: 3,2 Isr: 3,2
- Topic: quickstart76-events Partition: 1 Leader: 1 Replicas: 1,3 Isr: 1,3
- Topic: quickstart76-events Partition: 2 Leader: 0 Replicas: 0,1 Isr: 1,0
- Topic: quickstart76-events Partition: 3 Leader: 2 Replicas: 2,0 Isr: 2,0
- Topic: quickstart76-events Partition: 4 Leader: 3 Replicas: 3,1 Isr: 3,1
- Topic: quickstart76-events Partition: 5 Leader: 1 Replicas: 1,0 Isr: 1,0
可以看到有6个分区,因为我的集群总共有4个broker,所以leader被尽可能分配到了全部的broker中,
然后是follower副本,每个分区的follower副本都不会被分配到leader所在的broker,而且会尽量分散
Replicas:follower副本的brokerId
Isr:可用的follower副本的brokerId,如果某个broker宕掉了,那Isr中会没掉,但Replicas还在
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。