- 1. 创建topic
- 2. 查询topic
- 3. 修改topic副本数为2
./kafka-topics.sh --zookeeper=localhost:2181 --create --replication-factor 1 --partitions 3 --topic TEST2. 查询topic
./kafka-topics.sh --zookeeper=localhost:2181 --describe --topic TEST
3. 修改topic副本数为2Topic: TEST TopicId: yxXZoA78TCyJDYekr_89iw PartitionCount: 3 ReplicationFactor: 1 Configs:
Topic: TEST Partition: 0 Leader: 1 Replicas: 1 Isr: 1
Topic: TEST Partition: 1 Leader: 2 Replicas: 2 Isr: 2
Topic: TEST Partition: 2 Leader: 3 Replicas: 3 Isr: 3
创建配置文件add_test_topic_replication2.json,内容如下
{ "version":1, "partitions":[ { "topic":"TEST", "partition":0, "replicas":[ 1, 2 ] }, { "topic":"TEST", "partition":1, "replicas":[ 2, 3 ] }, { "topic":"TEST", "partition":2, "replicas":[ 3, 1 ] } ] }
执行命令修改分区副本数
./kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file add_test_topic_replication2.json --execute
结果如下
[2021-09-29 14:07:29,513] INFO Registered kafka:type=kafka.Log4jController MBean (kafka.utils.Log4jControllerRegistration$:31)
[2021-09-29 14:07:30,222] INFO [ZooKeeperClient] Initializing a new session to localhost:2181. (kafka.zookeeper.ZooKeeperClient:66)
[2021-09-29 14:07:30,263] INFO [ZooKeeperClient] Waiting until connected. (kafka.zookeeper.ZooKeeperClient:66)
[2021-09-29 14:07:30,290] INFO [ZooKeeperClient] Connected. (kafka.zookeeper.ZooKeeperClient:66)
Current partition replica assignment
{“version”:1,“partitions”:[{“topic”:“TEST”,“partition”:0,“replicas”:[1],“log_dirs”:[“any”]},{“topic”:“TEST”,“partition”:1,“replicas”:[2],“log_dirs”:[“any”]},{“topic”:“TEST”,“partition”:2,“replicas”:[3],“log_dirs”:[“any”]}]}