一 .修改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:test01PartitionCount:5ReplicationFactor:3Configs:
Topic: test01Partition: 0Leader: 0Replicas: 0,1,2Isr: 0,1,2
Topic: test01Partition: 1Leader: 1Replicas: 1,2,0Isr: 1,2,0
Topic: test01Partition: 2Leader: 2Replicas: 2,0,1Isr: 2,0,1
Topic: test01Partition: 3Leader: 0Replicas: 0,2,1Isr: 0,2,1
Topic: test01Partition: 4Leader: 1Replicas: 1,0,2Isr: 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:test01PartitionCount:5ReplicationFactor:2Configs:
Topic: test01Partition: 0Leader: 0Replicas: 0,2Isr: 0,2
Topic: test01Partition: 1Leader: 1Replicas: 0,1Isr: 1,0
Topic: test01Partition: 2Leader: 2Replicas: 1,2Isr: 2,1
Topic: test01Partition: 3Leader: 1Replicas: 1,2Isr: 2,1
Topic: test01Partition: 4Leader: 0Replicas: 0,2Isr: 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:test01PartitionCount:5ReplicationFactor:2Configs:
Topic: test01Partition: 0Leader: 0Replicas: 0,2Isr: 0,2
Topic: test01Partition: 1Leader: 1Replicas: 0,1Isr: 1,0
Topic: test01Partition: 2Leader: 2Replicas: 1,2Isr: 2,1
Topic: test01Partition: 3Leader: 1Replicas: 1,2Isr: 2,1
Topic: test01Partition: 4Leader: 0Replicas: 0,2Isr: 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:test01PartitionCount:6ReplicationFactor:2Configs:
Topic: test01Partition: 0Leader: 0Replicas: 0,2Isr: 0,2
Topic: test01Partition: 1Leader: 1Replicas: 0,1Isr: 1,0
Topic: test01Partition: 2Leader: 2Replicas: 1,2Isr: 2,1
Topic: test01Partition: 3Leader: 1Replicas: 1,2Isr: 2,1
Topic: test01Partition: 4Leader: 0Replicas: 0,2Isr: 0,2
Topic: test01Partition: 5Leader: 2Replicas: 2,0Isr: 2,0
##查看详情来看分区数已经被改成6个,副本数还是2