Kafka 集群数据备份 MirrorMaker 详解

时间:2025-03-04 14:08:55

什么是 MirrorMaker?

MirrorMaker是Kafka附带的一个用于在Kafka集群之间制作镜像数据的工具。该工具主要动作就是从源集群中消费并生产到目标群集。

一个集群可以启动多个MirrorMaker配置到多个集群

 

运行 MirrorMaker方法

 -- ./ -- ./ -- 8 --whitelist ".*"

实际操作一遍

文件

root@DESKTOP-I0EG1MJ:~/kafka-client/mirror-maker# cat 
=192.168.3.194:9092
=mirrormaker
=earliest

文件

root@DESKTOP-I0EG1MJ:~/kafka-client/mirror-maker# cat 
=192.168.2.123:9092

 运行mirror-maker

root@DESKTOP-I0EG1MJ:~/kafka-client/mirror-maker# cat 
 -- ./ -- ./ -- 5000 -- 2 --whitelist "test0428"

参数说明:

-- 消费者的配置文件(要消费的集群)

-- 指定生产配置文件(要发送到的目标集群)

--whitelist 要同步的topic白名单,可以匹配正则,也可以指定具体topic

-- 消费端提交offset时间间隔

--  MirrorMaker 要创建多少个 KafkaConsumer 实例

更多可以使用 --help查看

root@DESKTOP-I0EG1MJ:~/kafka-client/mirror-maker#  --help
This tool helps to continuously copy data between two Kafka clusters.
Option                                   Description
------                                   -----------
-- <String: Stop    Configure the mirror maker to exit on
  the entire mirror maker when a send      a failed send. (default: true)
  failure occurs>
-- <String: config file>  Embedded consumer config for consuming
                                           from the source cluster.
-- <String:   The consumer rebalance listener to use
  A custom rebalance listener of type      for mirror maker consumer.
  ConsumerRebalanceListener>
--help                                   Print usage information.
-- <String: A custom      Message handler which will process
  message handler of type                  every record in-between consumer and
  MirrorMakerMessageHandler>               producer.
-- <String:          Arguments used by custom message
  Arguments passed to message handler      handler for mirror maker.
  constructor.>
--                           DEPRECATED Use new consumer in mirror
                                           maker (this is the default so this
                                           option will be removed in a future
                                           version).
-- <Integer: Number of        Number of consumption streams.
  threads>                                 (default: 1)
-- <Integer:    Offset commit interval in ms.
  offset commit interval in                (default: 60000)
  millisecond>
-- <String: config file>  Embedded producer config.
-- <String:       Arguments used by custom rebalance
  Arguments passed to custom rebalance     listener for mirror maker consumer.
  listener constructor as a string.>
--version                                Display Kafka version.
--whitelist <String: Java regex          Whitelist of topics to mirror.
  (String)>

 

运行后会提示这么一句话

WARNING: The default partition assignment strategy of the mirror maker will change from 'range' to 'roundrobin' in an upcoming release (so that better load balancing can be achieved). If you prefer to make this switch in advance of that release add the following to the corresponding config: '='

 主要是说是MirrorMaker使用的消费策略是 Range ,以后可能改成 “轮训策略” ,我们可以手动指定“轮询策略”

在中设置即可

=

 

 

此时我们已经运行成功,直接去查看是否可以消费成功即可。

注意:同步前最后将目标集群的Topic创建好,否则会使用Broker默认配置

相关文章