kafka 提供了一個鏡像操作工具 kafka-mirror-maker.sh 用於將一個集群中的數據同步到另一個集群中去。
kafka 鏡像操作工具的本質是一個消費者,從源集群中待遷移的主題消費數據,然后創建一個生產者,將消費者從源集群中拉取到的數據寫入目標集群。
將 host 為host1 的kafka環境中的主題名為“test-mirror”的數據寫入到host為 host2 的環境中:
1):首先在源集群中分別創建消費者和生產者啟動配置文件:
消費者配置文件 mirror-consumer.properties:
bootstrap.servers=host1:9092 #指源集群的代理地址 group.id=mirror #消費組名
生產者配置文件 mirror-producer.properties:
bootstrap.servers=host2:9092 #指目標集群的代理地址
2):運行鏡像工具:
kafka-mirror-maker.sh --consumer.config ../config/mirror-consumer.properties --producer.config ../config/mirror-producer.properties --whitelist test-mirror
參數 --whitelist 指定要復制的主題,支持正則;
參數 --blacklist 指定不需要復制的主題;