Migrating data to Redpanda
One of the more elegant aspects of Redpanda is that it is compatible with the Kafka API and ecosystem. So when you want to migrate data from Kafka or replicate data between Redpanda clusters, the MirrorMaker 2 tool bundled in the Kafka download package is a natural solution.
In this article, we'll go through the process of configuring MirrorMaker to replicate data from one Redpanda cluster to another. In short, MirrorMaker reads a configuration file that specifies the connection details for the Redpanda clusters, as well as other options. After you start MirrorMaker, the data migration continues according to the configuration at launch time until you shutdown the MirrorMaker process.
For all of the details on MirrorMaker and its options, check out the Kafka documentation.
To set up the replication, we'll need:
MirrorMaker host - You install MirrorMaker on a separate system or on one of the Redpanda clusters, as long as the IP addresses and ports on each cluster are accessible from the MirrorMaker host. You must install the Java Runtime Engine (JRE) on the MirrorMaker host.
MirrorMaker 2 is run by a shell script that is part of the Kafka download package. To install MirrorMaker 2 on the machine that you want to run the replication between the clusters:
Download the latest Kafka download package.
curl -O https://dlcdn.apache.org/kafka/3.0.0/kafka_2.13-3.0.0.tgz
Extract the files from the archive:
tar -xvf kafka_2.13-3.0.0.tgz
Create the MirrorMaker 2 config files
MirrorMaker uses configuration files to get the connection details for the clusters. You can find the MirrorMaker script and configuration files in the expanded Kafka directory.
The sample configuration is a great place to understand a number of the settings for MirrorMaker.
To create a basic configuration file, go to the
config and run this command:
cat << EOF > mm2.properties
// Name the clusters
clusters = redpanda1, redpanda2
// Assign IP addresses to the cluster names
redpanda1.bootstrap.servers = <redpanda1_cluster_ip>:9092
redpanda2.bootstrap.servers = <redpanda2_cluster_ip>:9092
// Set replication for all topics from Redpanda 1 to Redpanda 2
redpanda1->redpanda2.enabled = true
redpanda1->redpanda2.topics = .*
// Setting replication factor of newly created remote topics
replication.factor = 1
Run MirrorMaker to start replication
To start MirrorMaker in the
kafka_2.13-3.0.0/bin/ directory, run:
With this command, MirrorMaker consumes all topics from the redpanda1 cluster and replicates them into the redpanda2 cluster.
MirrorMaker adds the prefix
redpanda1 to the names of replicated topics.
MirrorMaker uses the
__consumer_offsets topic to replicate consumer offsets between clusters. This is currently not supported in Redpanda, but you can follow the progress of this issue at: https://github.com/redpanda-data/redpanda/issues/1752
See migration in action
Here are the basic commands to produce and consume streams:
Create a topic in the source cluster. We'll call it "twitch_chat":
rpk topic create twitch_chat --brokers <node IP>:<kafka API port>
Produce messages to the topic:
rpk topic produce twitch_chat --brokers <node IP>:<kafka API port>
Type text into the topic and press Ctrl + D to seperate between messages.
Press Ctrl + C to exit the produce command.
Consume (or read) the messages from the destination cluster:
rpk topic consume twitch_chat --brokers <node IP>:<kafka API port>
Each message is shown with its metadata, like this:
"message": "How do you stream with Redpanda?\n",
Now you know the replication is working!
To stop the MirrorMaker process, use
top to find its process ID and then run:
kill <MirrorMaker pid>
If you run into any difficulty with data migration, contact us in our Slack community so we can help you succeed.