kafka修改Topic副本数和分区数

一 .修改Kafka Topic副本数 

1.bin/kafka-topics.sh --zookeeper 172.18.163.203:2181,172.18.163.204:2181,172.18.163.205:2181 --create --partitions 5 --replication-factor 3 --topic test01   
##新建测试topic test01
2.bin/kafka-topics.sh --zookeeper 172.18.163.203:2181 --topic test01 --describe ##查看Topic详情如下:
  Topic:test01	PartitionCount:5	ReplicationFactor:3	Configs:
	Topic: test01	Partition: 0	Leader: 0	Replicas: 0,1,2	Isr: 0,1,2
	Topic: test01	Partition: 1	Leader: 1	Replicas: 1,2,0	Isr: 1,2,0
	Topic: test01	Partition: 2	Leader: 2	Replicas: 2,0,1	Isr: 2,0,1
	Topic: test01	Partition: 3	Leader: 0	Replicas: 0,2,1	Isr: 0,2,1
	Topic: test01	Partition: 4	Leader: 1	Replicas: 1,0,2	Isr: 1,0,2

3.cat << EOF > increase-replication-factor.json
{"version":1,
"partitions":[
{"topic":"test01","partition":0,"replicas":[0,2]},
{"topic":"test01","partition":1,"replicas":[0,1]},
{"topic":"test01","partition":2,"replicas":[1,2]},
{"topic":"test01","partition":3,"replicas":[1,2]},
{"topic":"test01","partition":4,"replicas":[0,2]}
]
}
EOF
##新建修改副本数 increase-replication-factor.json 文件
4.bin/kafka-reassign-partitions.sh --zookeeper 172.18.163.203:2181,172.18.163.204:2181,172.18.163.205:2181  --reassignment-json-file increase-replication-factor.json --execute
##执行操作命令将副本数改为 2 
5.看到successfully,查看现在test01的副本数已经修改为2
  Topic:test01	PartitionCount:5	ReplicationFactor:2	Configs:
	Topic: test01	Partition: 0	Leader: 0	Replicas: 0,2	Isr: 0,2
	Topic: test01	Partition: 1	Leader: 1	Replicas: 0,1	Isr: 1,0
	Topic: test01	Partition: 2	Leader: 2	Replicas: 1,2	Isr: 2,1
	Topic: test01	Partition: 3	Leader: 1	Replicas: 1,2	Isr: 2,1
	Topic: test01	Partition: 4	Leader: 0	Replicas: 0,2	Isr: 0,2

二 .  修改Kafka 分区数操作步骤

1.bin/kafka-topics.sh --zookeeper 172.18.163.203:2181,172.18.163.204:2181,172.18.163.205:2181 --create --partitions 5 --replication-factor 3 --topic test01   
##新建测试topic test01
2.bin/kafka-topics.sh --zookeeper 172.18.163.203:2181 --topic test01 --describe ##查看Topic详情如下:
   Topic:test01	PartitionCount:5	ReplicationFactor:2	Configs:
	Topic: test01	Partition: 0	Leader: 0	Replicas: 0,2	Isr: 0,2
	Topic: test01	Partition: 1	Leader: 1	Replicas: 0,1	Isr: 1,0
	Topic: test01	Partition: 2	Leader: 2	Replicas: 1,2	Isr: 2,1
	Topic: test01	Partition: 3	Leader: 1	Replicas: 1,2	Isr: 2,1
	Topic: test01	Partition: 4	Leader: 0	Replicas: 0,2	Isr: 0,2
##分区数为5,副本数为2

3.bin/kafka-topics.sh --zookeeper 172.18.163.203:2181,172.18.163.204:2181,172.18.163.205:2181 -alter --partitions 6 --topic test01  ##分区数只能增加不能减小

4.bin/kafka-topics.sh --zookeeper 172.18.163.203:2181 --topic test01 --describe
Topic:test01	PartitionCount:6	ReplicationFactor:2	Configs:
	Topic: test01	Partition: 0	Leader: 0	Replicas: 0,2	Isr: 0,2
	Topic: test01	Partition: 1	Leader: 1	Replicas: 0,1	Isr: 1,0
	Topic: test01	Partition: 2	Leader: 2	Replicas: 1,2	Isr: 2,1
	Topic: test01	Partition: 3	Leader: 1	Replicas: 1,2	Isr: 2,1
	Topic: test01	Partition: 4	Leader: 0	Replicas: 0,2	Isr: 0,2
	Topic: test01	Partition: 5	Leader: 2	Replicas: 2,0	Isr: 2,0
##查看详情来看分区数已经被改成6个,副本数还是2
发布了165 篇原创文章 · 获赞 183 · 访问量 58万+

猜你喜欢

转载自blog.csdn.net/DreamWeaver_zhou/article/details/103260391