El contenido no se encuentra disponible en el idioma seleccionado. Estamos trabajando continuamente para agregar más idiomas. Gracias por su apoyo.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Distributed Message Service for Kafka/ Best Practices/ Using MirrorMaker to Synchronize Data Across Clusters

Using MirrorMaker to Synchronize Data Across Clusters

Updated on 2024-12-12 GMT+08:00

Overview

Scenario

In the following scenarios, MirrorMaker can be used to synchronize data between different Kafka clusters to ensure the availability and reliability of the clusters:

  • Backup and disaster recovery: An enterprise has multiple data centers. To prevent service unavailability caused by a fault in one data center, cluster data is synchronously backed up in multiple data centers.
  • Cluster migration: As enterprises migrate services to the cloud, data in on-premises clusters must be synchronized with that in cloud clusters to ensure service continuity.

Principle

MirrorMaker can be used to mirror data from the source cluster to the target cluster. As shown in Figure 1, in essence, MirrorMaker first consumes data from the source cluster and then produces the consumed data to the target cluster. For more information about MirrorMaker, see Mirroring data between clusters.

Figure 1 How MirrorMaker works

Restrictions

  • The IP addresses and port numbers of the nodes in the source cluster cannot be the same as those of the nodes in the target cluster. Otherwise, data will be replicated infinitely in a topic.
  • Use MirrorMaker to synchronize data between at least two clusters. If there is only one cluster, data will be replicated infinitely in a topic.

Procedure

  1. Buy an ECS that can communicate with the source and target clusters. For details, see the Purchasing a Custom ECS.
  2. Log in to the ECS, install JDK, and add the following contents to .bash_profile in the home directory to configure the environment variables JAVA_HOME and PATH. In this command, /opt/java/jdk1.8.0_151 is the JDK installation path. Change it to the path where you install JDK.

    export JAVA_HOME=/opt/java/jdk1.8.0_151 
    export PATH=$JAVA_HOME/bin:$PATH

    Run the source .bash_profile command for the modification to take effect.

    NOTE:

    Use Oracle JDK instead of ECS's default JDK (for example, OpenJDK), because ECS's default JDK may not be suitable. Obtain Oracle JDK 1.8.111 or later from Oracle's official website.

  3. Download the binary software package of Kafka 3.3.1.

    wget https://archive.apache.org/dist/kafka/3.3.1/kafka_2.12-3.3.1.tgz

  4. Decompress the binary software package.

    tar -zxvf kafka_2.12-3.3.1.tgz

  5. Go to the binary software package directory and specify the IP addresses and ports of the source and target clusters and other parameters in the connect-mirror-maker.properties configuration file in the config directory.

    # Specify two clusters.
    clusters = A, B
    A.bootstrap.servers = A_host1:A_port, A_host2:A_port, A_host3:A_port
    B.bootstrap.servers = B_host1:B_port, B_host2:B_port, B_host3:B_port
    
    # Specify the data synchronization direction. The data can be synchronized unidirectionally or bidirectionally.
    A->B.enabled = true
    
    # Specify the topics to be synchronized. Regular expressions are supported. By default, all topics are replicated, for example, foo-.*.
    A->B.topics = .*
    
    # If the following two configurations are enabled, clusters A and B replicate data with each other.
    #B->A.enabled = true
    #B->A.topics = .*
    
    # Specify the number of replicas. If multiple topics need to be synchronized and their replica quantities are different, create topics with the same name and replica quantity before starting MirrorMaker.
    replication.factor=3
    
    # Specify the consumer offset synchronization direction (unidirectionally or bidirectionally).
    A->B.sync.group.offsets.enabled=true
    
    ############################# Internal Topic Settings  #############################
    # The replication factor for mm2 internal topics "heartbeats", "B.checkpoints.internal" and
    # "mm2-offset-syncs.B.internal"
    # In the test environment, the value can be 1. In the production environment, it is recommended that the value be greater than 1, for example, 3.
    checkpoints.topic.replication.factor=3
    heartbeats.topic.replication.factor=3
    offset-syncs.topic.replication.factor=3
    
    # The replication factor for connect internal topics "mm2-configs.B.internal", "mm2-offsets.B.internal" and
    # "mm2-status.B.internal"
    # In the test environment, the value can be 1. In the production environment, it is recommended that the value be greater than 1, for example, 3.
    offset.storage.replication.factor=3
    status.storage.replication.factor=3
    config.storage.replication.factor=3
    
    # customize as needed
    # replication.policy.separator = _
    # sync.topic.acls.enabled = false
    # emit.heartbeats.interval.seconds = 5
    # Match the topic name of the target cluster to that of the source.
    # replication.policy.class = org.apache.kafka.connect.mirror.IdentityReplicationPolicy

  6. In the binary software package directory, start MirrorMaker to synchronize data.

    ./bin/connect-mirror-maker.sh config/connect-mirror-maker.properties

  7. (Optional) If a topic is created in the source cluster after MirrorMaker has been started, and the topic data needs to be synchronized, restart MirrorMaker. For details about how to restart MirrorMaker, see 6. You can also add configurations listed in Table 1 to periodically synchronize new topics without restarting MirrorMaker. refresh.topics.interval.seconds is mandatory. Other parameters are optional.

    Table 1 MirrorMaker configurations

    Parameter

    Default Value

    Description

    sync.topic.configs.enabled

    true

    Whether to monitor the source cluster for configuration changes.

    sync.topic.acls.enabled

    true

    Whether to monitor the source cluster for ACL changes.

    emit.heartbeats.enabled

    true

    Whether to let the connector send heartbeats periodically.

    emit.heartbeats.interval.seconds

    5 seconds

    Heartbeat frequency.

    emit.checkpoints.enabled

    true

    Whether to let the connector periodically send the consumer offset information.

    emit.checkpoints.interval.seconds

    5 seconds

    Checkpoint frequency.

    refresh.topics.enabled

    true

    Whether to let the connector periodically check for new topics.

    refresh.topics.interval.seconds

    5 seconds

    Frequency of checking for new topics in the source cluster.

    refresh.groups.enabled

    true

    Whether to let the connector periodically check for new consumer groups.

    refresh.groups.interval.seconds

    5 seconds

    Frequency of checking for new consumer groups in the source cluster.

    replication.policy.class

    org.apache.kafka.connect.mirror.DefaultReplicationPolicy

    Use LegacyReplicationPolicy to imitate MirrorMaker of an earlier version.

    heartbeats.topic.retention.ms

    One day

    Used when heartbeat topics are created for the first time.

    checkpoints.topic.retention.ms

    One day

    Used when checkpoint topics are created for the first time.

    offset.syncs.topic.retention.ms

    max long

    Used when offset sync topics are created for the first time.

Verifying Data Synchronization

  1. View the topic list in the target cluster to check whether there are source topics.

    NOTE:

    The default value of replication.policy.class is org.apache.kafka.connect.mirror.DefaultReplicationPolicy, which adds a prefix (for example, "A.") to target topic names to differentiate them from the source. This setting helps MirrorMaker avoid circular replication. To mirror the target and source topic names, set replication.policy.class to org.apache.kafka.connect.mirror.IdentityReplicationPolicy.

  2. Produce and consume messages in the source cluster, view the consumption progress in the target cluster, and check whether data has been synchronized from the source cluster to the target cluster.

    If the target cluster is a Huawei Cloud Kafka instance, view the consumption progress on the Consumer Groups page.

Utilizamos cookies para mejorar nuestro sitio y tu experiencia. Al continuar navegando en nuestro sitio, tú aceptas nuestra política de cookies. Descubre más

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback