From 343e444f1d6840948b8a7bcd5feb11ccfa598ef4 Mon Sep 17 00:00:00 2001 From: abu Date: Sat, 22 Jun 2024 19:38:21 +0800 Subject: [PATCH] Site updated: 2024-06-22 19:38:20 --- .../index.html" | 40 ++++++++----------- index.html | 9 ++--- local-search.xml | 2 +- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git "a/2024/06/22/kafka-topic\346\214\207\345\256\232\350\212\202\347\202\271\351\207\215\345\271\263\350\241\241/index.html" "b/2024/06/22/kafka-topic\346\214\207\345\256\232\350\212\202\347\202\271\351\207\215\345\271\263\350\241\241/index.html" index 5288b750f..3a52dd6e2 100644 --- "a/2024/06/22/kafka-topic\346\214\207\345\256\232\350\212\202\347\202\271\351\207\215\345\271\263\350\241\241/index.html" +++ "b/2024/06/22/kafka-topic\346\214\207\345\256\232\350\212\202\347\202\271\351\207\215\345\271\263\350\241\241/index.html" @@ -239,7 +239,7 @@ - 903 字 + 926 字 @@ -282,35 +282,29 @@

kafka topic指定节点重平衡

-

背景:

-

业务预估,某个业务所用的几个topic数据量 以及io会非常大,需要增加更多的broker来支撑。这时就有两种方案,

+

背景:

业务预估,某个业务所用的几个topic数据量 以及io会非常大,需要增加更多的broker来支撑。这时就有两种方案,

-

第一是这些特殊需求的topic独享几个broker。而其他的topic不动。

-

第二种方案是:新增broker后,可以简单粗暴的将topic的partition数量设置大一些,并且设置随机重平衡。让kafka调度器去做区分。

+

第一种: 这些特殊需求的topic独享几个broker。而其他的topic不动。

+

第二种:新增broker后,可以简单粗暴的将topic的partition数量设置大一些,并且设置随机重平衡。让kafka调度器去做区分。

在实际生产环境中,第一种方式是对其他topic影响最小,并且最符合稳定性要求的方案。图示如下

-

迁移操作步骤如下:
1、首先查看kafka集群的broker信息确保迁移的broker已经加入集群

-
1
2
3
/data/zookeeper/bin/zkCli.sh
[zk: localhost:2181(CONNECTED) 0] ls /brokers/ids
[0, 1, 2, 3, 4, 5, 6]
+

迁移操作步骤如下:

1、首先查看kafka集群的broker信息确保迁移的broker已经加入集群

1
2
3
4
本实验环境有三个broker,分别是0123456,其中123三个节点有zooKeeper。
/data/zookeeper/bin/zkCli.sh
[zk: localhost:2181(CONNECTED) 0] ls /brokers/ids
[0, 1, 2, 3, 4, 5, 6]

-

2、查看topic分区的ISR,确保topic的Leader、Replicas、ISR参数正常,确保ISR同步队列正常。

-
1
2
3
4
5
root@kafka-2:~# /data/kafka/bin/kafka-topics.sh --describe --topic my-topic --bootstrap-server 192.168.1.231:9092
Topic: my-topic TopicId: 1FtXs5m8TMyjC18Qjs3ttg PartitionCount: 3 ReplicationFactor: 3 Configs: segment.bytes=1073741824
Topic: my-topic Partition: 0 Leader: 0 Replicas: 0,1,2 Isr: 0,1,2
Topic: my-topic Partition: 1 Leader: 1 Replicas: 1,2,0 Isr: 0,1,2
Topic: my-topic Partition: 2 Leader: 1 Replicas: 2,1,0 Isr: 1,2,0
-


3、如果数据量特别大,可以提前设置好topic数据保存时间,可以加快迁移速度。

-
1
2
# 得研发确认一下是否运行丢数据。修改topic数据保存时间为一个小时。一个小时以上的数据会丢失。
/data/kafka/bin/kafka-configs.sh --bootstrap-server 192.168.1.231:9092 --alter --topic my-topic --entity-default-config retention.ms=3600000
+

2、查看topic分区的ISR,确保topic的Leader、Replicas、ISR参数正常,确保ISR同步队列正常。

1
2
3
4
5
root@kafka-2:~# /data/kafka/bin/kafka-topics.sh --describe --topic my-topic --bootstrap-server 192.168.1.231:9092
Topic: my-topic TopicId: 1FtXs5m8TMyjC18Qjs3ttg PartitionCount: 3 ReplicationFactor: 3 Configs: segment.bytes=1073741824
Topic: my-topic Partition: 0 Leader: 0 Replicas: 0,1,2 Isr: 0,1,2
Topic: my-topic Partition: 1 Leader: 1 Replicas: 1,2,0 Isr: 0,1,2
Topic: my-topic Partition: 2 Leader: 1 Replicas: 2,1,0 Isr: 1,2,0
+

+

3、如果数据量特别大,可以提前设置好topic数据保存时间,可以加快迁移速度。

1
2
# 得研发确认一下是否运行丢数据。修改topic数据保存时间为一个小时。一个小时以上的数据会丢失。
/data/kafka/bin/kafka-configs.sh --bootstrap-server 192.168.1.231:9092 --alter --topic my-topic --entity-default-config retention.ms=3600000

-

4、创建需要迁移的topic的move文件

-
1
2
3
4
5
6
7
8
root@kafka-2:~# cat topics-to-move.json
{
"topics": [
{
"topic": "my-topic"
}
]
}
-

5、通过命令生成迁移文件,包含需要迁移到哪几个broker。

-
1
2
# 前面这个命令会生成两个部分,分别问现状和迁移计划。 grep Proposed -A1 | grep -v Proposed 过滤掉Current部分,只保留迁移计划。
/data/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.1.231:9092 --topics-to-move-json-file topics-to-move.json --broker-list "4,5,6" --generate | grep Proposed -A1 | grep -v Proposed > move.json
+

4、创建需要迁移的topic的move文件

1
2
3
4
5
6
7
8
root@kafka-2:~# cat topics-to-move.json
{
"topics": [
{
"topic": "my-topic"
}
]
}
+

5、通过命令生成迁移文件,包含需要迁移到哪几个broker。

1
2
# 前面这个命令会生成两个部分,分别问现状和迁移计划。 grep Proposed -A1 | grep -v Proposed 过滤掉Current部分,只保留迁移计划。
/data/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.1.231:9092 --topics-to-move-json-file topics-to-move.json --broker-list "4,5,6" --generate | grep Proposed -A1 | grep -v Proposed > move.json

-

6、执行分区重新分配

-
1
2
3
4
5
6
7
root@kafka-2:~# /data/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.1.231:9092 --reassignment-json-file move.json --execute
Current partition replica assignment

{"version":1,"partitions":[{"topic":"my-topic","partition":0,"replicas":[0,1,2],"log_dirs":["any","any","any"]},{"topic":"my-topic","partition":1,"replicas":[1,2,0],"log_dirs":["any","any","any"]},{"topic":"my-topic","partition":2,"replicas":[2,1,0],"log_dirs":["any","any","any"]}]}

Save this to use as the --reassignment-json-file option during rollback
Successfully started partition reassignments for my-topic-0,my-topic-1,my-topic-2
-


7、验证重新分配状态

-
1
2
3
4
5
6
7
8
root@kafka-2:~# /data/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.1.231:9092 --reassignment-json-file mytopic-reassignment-plan.json --verify
Status of partition reassignment:
There is no active reassignment of partition my-topic-0, but replica set is 5,4,6 rather than 0,1,2.
There is no active reassignment of partition my-topic-1, but replica set is 6,5,4 rather than 1,2,0.
There is no active reassignment of partition my-topic-2, but replica set is 4,6,5 rather than 2,1,0.

Clearing broker-level throttles on brokers 0,5,1,6,2,3,4
Clearing topic-level throttles on topic my-topic
-


8、查看 topic 详情

-
1
2
3
4
5
root@kafka-2:~# /data/kafka/bin/kafka-topics.sh --describe --topic my-topic --bootstrap-server 192.168.1.231:9092
Topic: my-topic TopicId: 1FtXs5m8TMyjC18Qjs3ttg PartitionCount: 3 ReplicationFactor: 3 Configs: segment.bytes=1073741824
Topic: my-topic Partition: 0 Leader: 5 Replicas: 5,4,6 Isr: 5,6,4
Topic: my-topic Partition: 1 Leader: 6 Replicas: 6,5,4 Isr: 5,6,4
Topic: my-topic Partition: 2 Leader: 4 Replicas: 4,6,5 Isr: 5,6,4
-


9、操作恢复topic数据保存时间,(如果前面操作了的话)

-
1
2
root@kafka-2:~# /data/kafka/bin/kafka-configs.sh --bootstrap-server 192.168.1.231:9092 --alter --topic my-topic --entity-default-config retention.ms=360000000
entity-default-config is not a recognized option
+

6、执行分区重新分配

1
2
3
4
5
6
7
root@kafka-2:~# /data/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.1.231:9092 --reassignment-json-file move.json --execute
Current partition replica assignment

{"version":1,"partitions":[{"topic":"my-topic","partition":0,"replicas":[0,1,2],"log_dirs":["any","any","any"]},{"topic":"my-topic","partition":1,"replicas":[1,2,0],"log_dirs":["any","any","any"]},{"topic":"my-topic","partition":2,"replicas":[2,1,0],"log_dirs":["any","any","any"]}]}

Save this to use as the --reassignment-json-file option during rollback
Successfully started partition reassignments for my-topic-0,my-topic-1,my-topic-2
+

+

7、验证重新分配状态

1
2
3
4
5
6
7
8
root@kafka-2:~# /data/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.1.231:9092 --reassignment-json-file mytopic-reassignment-plan.json --verify
Status of partition reassignment:
There is no active reassignment of partition my-topic-0, but replica set is 5,4,6 rather than 0,1,2.
There is no active reassignment of partition my-topic-1, but replica set is 6,5,4 rather than 1,2,0.
There is no active reassignment of partition my-topic-2, but replica set is 4,6,5 rather than 2,1,0.

Clearing broker-level throttles on brokers 0,5,1,6,2,3,4
Clearing topic-level throttles on topic my-topic
+

+

8、查看 topic 详情

1
2
3
4
5
root@kafka-2:~# /data/kafka/bin/kafka-topics.sh --describe --topic my-topic --bootstrap-server 192.168.1.231:9092
Topic: my-topic TopicId: 1FtXs5m8TMyjC18Qjs3ttg PartitionCount: 3 ReplicationFactor: 3 Configs: segment.bytes=1073741824
Topic: my-topic Partition: 0 Leader: 5 Replicas: 5,4,6 Isr: 5,6,4
Topic: my-topic Partition: 1 Leader: 6 Replicas: 6,5,4 Isr: 5,6,4
Topic: my-topic Partition: 2 Leader: 4 Replicas: 4,6,5 Isr: 5,6,4
+

+

9、操作恢复topic数据保存时间,(如果前面操作了的话)

1
2
root@kafka-2:~# /data/kafka/bin/kafka-configs.sh --bootstrap-server 192.168.1.231:9092 --alter --topic my-topic --entity-default-config retention.ms=360000000
entity-default-config is not a recognized option

完成。

diff --git a/index.html b/index.html index 9267fad88..9196f3087 100644 --- a/index.html +++ b/index.html @@ -251,13 +251,12 @@

- 背景: -业务预估,某个业务所用的几个topic数据量 以及io会非常大,需要增加更多的broker来支撑。这时就有两种方案, + 背景:业务预估,某个业务所用的几个topic数据量 以及io会非常大,需要增加更多的broker来支撑。这时就有两种方案, -第一是这些特殊需求的topic独享几个broker。而其他的topic不动。 -第二种方案是:新增broker后,可以简单粗暴的将topic的partition数量设置大一些,并且设置随机重平衡。让kafka调度器去做区分。 +第一种: 这些特殊需求的topic独享几个broker。而其他的topic不动。 +第二种:新增broker后,可以简单粗暴的将topic的partition数量设置大一些,并且设置随机重平衡。让kafka调度器去做区分。 -在实际生产环境中,第一种方式是对其他topic +在实际生产环境中,第一种方式是对其他topic影响

diff --git a/local-search.xml b/local-search.xml index 897bc5de7..3c056f481 100644 --- a/local-search.xml +++ b/local-search.xml @@ -8,7 +8,7 @@ /2024/06/22/kafka-topic%E6%8C%87%E5%AE%9A%E8%8A%82%E7%82%B9%E9%87%8D%E5%B9%B3%E8%A1%A1/ - 背景:

业务预估,某个业务所用的几个topic数据量 以及io会非常大,需要增加更多的broker来支撑。这时就有两种方案,

第一是这些特殊需求的topic独享几个broker。而其他的topic不动。

第二种方案是:新增broker后,可以简单粗暴的将topic的partition数量设置大一些,并且设置随机重平衡。让kafka调度器去做区分。

在实际生产环境中,第一种方式是对其他topic影响最小,并且最符合稳定性要求的方案。图示如下

迁移操作步骤如下:
1、首先查看kafka集群的broker信息确保迁移的broker已经加入集群

1
2
3
/data/zookeeper/bin/zkCli.sh
[zk: localhost:2181(CONNECTED) 0] ls /brokers/ids
[0, 1, 2, 3, 4, 5, 6]

2、查看topic分区的ISR,确保topic的Leader、Replicas、ISR参数正常,确保ISR同步队列正常。

1
2
3
4
5
root@kafka-2:~# /data/kafka/bin/kafka-topics.sh --describe --topic my-topic --bootstrap-server 192.168.1.231:9092
Topic: my-topicTopicId: 1FtXs5m8TMyjC18Qjs3ttgPartitionCount: 3ReplicationFactor: 3Configs: segment.bytes=1073741824
Topic: my-topicPartition: 0Leader: 0Replicas: 0,1,2Isr: 0,1,2
Topic: my-topicPartition: 1Leader: 1Replicas: 1,2,0Isr: 0,1,2
Topic: my-topicPartition: 2Leader: 1Replicas: 2,1,0Isr: 1,2,0


3、如果数据量特别大,可以提前设置好topic数据保存时间,可以加快迁移速度。

1
2
# 得研发确认一下是否运行丢数据。修改topic数据保存时间为一个小时。一个小时以上的数据会丢失。
/data/kafka/bin/kafka-configs.sh --bootstrap-server 192.168.1.231:9092 --alter --topic my-topic --entity-default-config retention.ms=3600000

4、创建需要迁移的topic的move文件

1
2
3
4
5
6
7
8
root@kafka-2:~# cat topics-to-move.json
{
"topics": [
{
"topic": "my-topic"
}
]
}

5、通过命令生成迁移文件,包含需要迁移到哪几个broker。

1
2
# 前面这个命令会生成两个部分,分别问现状和迁移计划。 grep Proposed -A1 | grep -v Proposed 过滤掉Current部分,只保留迁移计划。
/data/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.1.231:9092 --topics-to-move-json-file topics-to-move.json --broker-list "4,5,6" --generate | grep Proposed -A1 | grep -v Proposed > move.json

6、执行分区重新分配

1
2
3
4
5
6
7
root@kafka-2:~# /data/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.1.231:9092 --reassignment-json-file move.json --execute
Current partition replica assignment

{"version":1,"partitions":[{"topic":"my-topic","partition":0,"replicas":[0,1,2],"log_dirs":["any","any","any"]},{"topic":"my-topic","partition":1,"replicas":[1,2,0],"log_dirs":["any","any","any"]},{"topic":"my-topic","partition":2,"replicas":[2,1,0],"log_dirs":["any","any","any"]}]}

Save this to use as the --reassignment-json-file option during rollback
Successfully started partition reassignments for my-topic-0,my-topic-1,my-topic-2


7、验证重新分配状态

1
2
3
4
5
6
7
8
root@kafka-2:~# /data/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.1.231:9092 --reassignment-json-file mytopic-reassignment-plan.json --verify
Status of partition reassignment:
There is no active reassignment of partition my-topic-0, but replica set is 5,4,6 rather than 0,1,2.
There is no active reassignment of partition my-topic-1, but replica set is 6,5,4 rather than 1,2,0.
There is no active reassignment of partition my-topic-2, but replica set is 4,6,5 rather than 2,1,0.

Clearing broker-level throttles on brokers 0,5,1,6,2,3,4
Clearing topic-level throttles on topic my-topic


8、查看 topic 详情

1
2
3
4
5
root@kafka-2:~# /data/kafka/bin/kafka-topics.sh --describe --topic my-topic --bootstrap-server 192.168.1.231:9092
Topic: my-topicTopicId: 1FtXs5m8TMyjC18Qjs3ttgPartitionCount: 3ReplicationFactor: 3Configs: segment.bytes=1073741824
Topic: my-topicPartition: 0Leader: 5Replicas: 5,4,6Isr: 5,6,4
Topic: my-topicPartition: 1Leader: 6Replicas: 6,5,4Isr: 5,6,4
Topic: my-topicPartition: 2Leader: 4Replicas: 4,6,5Isr: 5,6,4


9、操作恢复topic数据保存时间,(如果前面操作了的话)

1
2
root@kafka-2:~# /data/kafka/bin/kafka-configs.sh --bootstrap-server 192.168.1.231:9092 --alter --topic my-topic --entity-default-config retention.ms=360000000
entity-default-config is not a recognized option

完成。

]]>
+ 背景:

业务预估,某个业务所用的几个topic数据量 以及io会非常大,需要增加更多的broker来支撑。这时就有两种方案,

第一种: 这些特殊需求的topic独享几个broker。而其他的topic不动。

第二种:新增broker后,可以简单粗暴的将topic的partition数量设置大一些,并且设置随机重平衡。让kafka调度器去做区分。

在实际生产环境中,第一种方式是对其他topic影响最小,并且最符合稳定性要求的方案。图示如下

迁移操作步骤如下:

1、首先查看kafka集群的broker信息确保迁移的broker已经加入集群

1
2
3
4
本实验环境有三个broker,分别是0123456,其中123三个节点有zooKeeper。
/data/zookeeper/bin/zkCli.sh
[zk: localhost:2181(CONNECTED) 0] ls /brokers/ids
[0, 1, 2, 3, 4, 5, 6]

2、查看topic分区的ISR,确保topic的Leader、Replicas、ISR参数正常,确保ISR同步队列正常。

1
2
3
4
5
root@kafka-2:~# /data/kafka/bin/kafka-topics.sh --describe --topic my-topic --bootstrap-server 192.168.1.231:9092
Topic: my-topicTopicId: 1FtXs5m8TMyjC18Qjs3ttgPartitionCount: 3ReplicationFactor: 3Configs: segment.bytes=1073741824
Topic: my-topicPartition: 0Leader: 0Replicas: 0,1,2Isr: 0,1,2
Topic: my-topicPartition: 1Leader: 1Replicas: 1,2,0Isr: 0,1,2
Topic: my-topicPartition: 2Leader: 1Replicas: 2,1,0Isr: 1,2,0

3、如果数据量特别大,可以提前设置好topic数据保存时间,可以加快迁移速度。

1
2
# 得研发确认一下是否运行丢数据。修改topic数据保存时间为一个小时。一个小时以上的数据会丢失。
/data/kafka/bin/kafka-configs.sh --bootstrap-server 192.168.1.231:9092 --alter --topic my-topic --entity-default-config retention.ms=3600000

4、创建需要迁移的topic的move文件

1
2
3
4
5
6
7
8
root@kafka-2:~# cat topics-to-move.json
{
"topics": [
{
"topic": "my-topic"
}
]
}

5、通过命令生成迁移文件,包含需要迁移到哪几个broker。

1
2
# 前面这个命令会生成两个部分,分别问现状和迁移计划。 grep Proposed -A1 | grep -v Proposed 过滤掉Current部分,只保留迁移计划。
/data/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.1.231:9092 --topics-to-move-json-file topics-to-move.json --broker-list "4,5,6" --generate | grep Proposed -A1 | grep -v Proposed > move.json

6、执行分区重新分配

1
2
3
4
5
6
7
root@kafka-2:~# /data/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.1.231:9092 --reassignment-json-file move.json --execute
Current partition replica assignment

{"version":1,"partitions":[{"topic":"my-topic","partition":0,"replicas":[0,1,2],"log_dirs":["any","any","any"]},{"topic":"my-topic","partition":1,"replicas":[1,2,0],"log_dirs":["any","any","any"]},{"topic":"my-topic","partition":2,"replicas":[2,1,0],"log_dirs":["any","any","any"]}]}

Save this to use as the --reassignment-json-file option during rollback
Successfully started partition reassignments for my-topic-0,my-topic-1,my-topic-2

7、验证重新分配状态

1
2
3
4
5
6
7
8
root@kafka-2:~# /data/kafka/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.1.231:9092 --reassignment-json-file mytopic-reassignment-plan.json --verify
Status of partition reassignment:
There is no active reassignment of partition my-topic-0, but replica set is 5,4,6 rather than 0,1,2.
There is no active reassignment of partition my-topic-1, but replica set is 6,5,4 rather than 1,2,0.
There is no active reassignment of partition my-topic-2, but replica set is 4,6,5 rather than 2,1,0.

Clearing broker-level throttles on brokers 0,5,1,6,2,3,4
Clearing topic-level throttles on topic my-topic

8、查看 topic 详情

1
2
3
4
5
root@kafka-2:~# /data/kafka/bin/kafka-topics.sh --describe --topic my-topic --bootstrap-server 192.168.1.231:9092
Topic: my-topicTopicId: 1FtXs5m8TMyjC18Qjs3ttgPartitionCount: 3ReplicationFactor: 3Configs: segment.bytes=1073741824
Topic: my-topicPartition: 0Leader: 5Replicas: 5,4,6Isr: 5,6,4
Topic: my-topicPartition: 1Leader: 6Replicas: 6,5,4Isr: 5,6,4
Topic: my-topicPartition: 2Leader: 4Replicas: 4,6,5Isr: 5,6,4

9、操作恢复topic数据保存时间,(如果前面操作了的话)

1
2
root@kafka-2:~# /data/kafka/bin/kafka-configs.sh --bootstrap-server 192.168.1.231:9092 --alter --topic my-topic --entity-default-config retention.ms=360000000
entity-default-config is not a recognized option

完成。

]]>