kafka增加副本

原创
半兽人 发表于: 2015-03-10   最后更新时间: 2021-10-19 19:57:08  
{{totalSubscript}} 订阅, 17,488 游览

Increasing the replication factor of an existing partition is easy. Just specify the extra replicas in the custom reassignment json file and use it with the --execute option to increase the replication factor of the specified partitions.
在现有分区增加副本是很容易的,只要指定自定义的重新分配的json文件脚本,并用 --execute 选项去执行这个脚本。

For instance, the following example increases the replication factor of partition 0 of topic foo from 1 to 3. Before increasing the replication factor, the partition's only replica existed on broker 5. As part of increasing the replication factor, we will add more replicas on brokers 6 and 7.
增加副本之前,分区已存在的副本在broker5上,它也作为增加副本的一部分,我们将副本添加到broker6和7上。

The first step is to hand craft the custom reassignment plan in a json file:
第一步手工写一个自定义的分配的json脚本:

> cat increase-replication-factor.json
{"version":1,
 "partitions":[{"topic":"foo","partition":0,"replicas":[5,6,7]}]}

Then, use the json file with the --execute option to start the reassignment process:
然后,用--execute选项运行json脚本:

> bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file increase-replication-factor.json --execute
Current partition replica assignment

{"version":1,
 "partitions":[{"topic":"foo","partition":0,"replicas":[5]}]}

Save this to use as the --reassignment-json-file option during rollback
Successfully started reassignment of partitions
{"version":1,
 "partitions":[{"topic":"foo","partition":0,"replicas":[5,6,7]}]}

The --verify option can be used with the tool to check the status of the partition reassignment. Note that the same increase-replication-factor.json (used with the --execute option) should be used with the --verify option
-- version 选项来验证parition分配的状态。注意,使用同样的 increase-replication-factor.json

bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file increase-replication-factor.json --verify
Status of partition reassignment:
Reassignment of partition [foo,0] completed successfully

You can also verify the increase in replication factor with the kafka-topics tool:
你也可以使用kafka-topic工具验证:

> bin/kafka-topics.sh --zookeeper localhost:2181 --topic foo --describe
Topic:foo    PartitionCount:1    ReplicationFactor:3    Configs:
    Topic: foo    Partition: 0    Leader: 5    Replicas: 5,6,7    Isr: 5,6,7
更新于 2021-10-19

起于累土 5年前

增加副本会对该topic的生产及消费端造成影响吗?

java调用send,默认创建的是一个分区和一个副本。能否通过api获得存活的broker,然后直接设置副本数。还是只能通过命令行执行?

可以通过api实现,你可通过sh命令,找到对应的实现入口。
这种行为都是管理人员来操作的,直接操作就好了,而且我用了5年,很少执行这种命令,不必花精力自己实现。

你可以在server.properties中设置默认分区数和副本数。

谢谢~

周五的时候摸索了一番,通过配置设定了分区数和副本数。



您上面说的,“”管理人员来操作“”,目前就安排我在研究kafka,没什么管理人员了。另外,我能理解为主题是否先确定好,然后通过sh命令创建(设定分区数、副本数),程序再使用相应的主题?

以后如果增加了broker,也只能通过这种json方式扩充了吗?



“而且我用了5年,很少执行这种命令,不必花精力自己实现”,您的意思是副本和分区这一块,不用你去管理的?

只能通过json的方式扩充(你可以找对应的程序入口,调用对应实现,也能做,麻烦),有现成的命令可以扩展broker,就够了。
这些干嘛要通过程序去实现呢。你可以在看下 kafka manager,实现了kafka分区扩展等管理。

Vani 5年前

请问"partitions":[{"topic":"foo","partition":0,"replicas":[5,6,7]}]} replicas里面的broker567顺序上有要求吗

無名 -> Vani 5年前

没有吧,从未关注过这个。。

查看kafka更多相关的文章或提一个关于kafka的问题,也可以与我们一起分享文章