Operations 11 min read

How to Build a RocketMQ Cluster with Dual Master‑Slave Async Replication

This guide walks through setting up a two‑node RocketMQ cluster with dual master‑slave asynchronous replication, covering host role assignment, configuration file edits, binary deployment, memory tuning, and the exact commands to start NameServers, master brokers, and slave brokers.

Coder Trainee
Coder Trainee
Coder Trainee
How to Build a RocketMQ Cluster with Dual Master‑Slave Async Replication

1. Cluster Architecture

The tutorial creates a broker cluster with two masters and two slaves using asynchronous replication. Two physical hosts are used, each running a NameServer and a Broker. The role assignment is:

Host rocketmq1 (IP 192.168.1.8): NameServer + Broker (Master1 + Slave2)

Host rocketmq2 (IP 192.168.1.9): NameServer + Broker (Master1 + Slave2)

2. Prepare the RocketMQ Binary

Download the binary package from the Apache RocketMQ site, unzip it, and navigate to the configuration directory

/tools/rocketMq/rocketmq-all-4.9.4-bin-release/conf/2m-2s-async

.

3. Configure rocketmq1

Edit broker-a.properties with the following essential settings:

brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
namesrvAddr=192.168.1.8:9876;192.168.1.9:9876

Then edit broker-b-s.properties (the slave configuration) similarly, but set brokerId=1 and brokerRole=SLAVE:

brokerClusterName=DefaultCluster
brokerName=broker-b
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
namesrvAddr=192.168.1.8:9876;192.168.1.9:9876

4. Configure rocketmq2

Rename the host to rocketmq2 (or keep using the IP) and repeat the same edits for broker-b.properties (master) and broker-a-s.properties (slave) with the appropriate brokerId and brokerRole values.

5. Adjust Startup Scripts

Modify runserver.sh to reduce the NameServer JVM memory:

JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

Modify runbroker.sh to reduce the broker JVM memory:

JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -Xmn1g"

6. Start the Services

On each host, start the NameServer:

nohup sh bin/mqnamesrv &
 tail -f nohup.out

Start the master brokers:

nohup sh bin/mqbroker -c conf/2m-2s-async/broker-a.properties > broker-a.log 2>&1 &
nohup sh bin/mqbroker -c conf/2m-2s-async/broker-b.properties > broker-b.log 2>&1 &

Start the slave brokers:

nohup sh bin/mqbroker -c conf/2m-2s-async/broker-b-s.properties > broker-b-s.log 2>&1 &
nohup sh bin/mqbroker -c conf/2m-2s-async/broker-a-s.properties > broker-a-s.log 2>&1 &

7. Verification

After all processes are running, the cluster provides asynchronous master‑slave replication across the two hosts. The tutorial recommends consulting the official RocketMQ documentation for deeper understanding.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Message Queuerocketmqcluster-setupbroker-configurationasync-replication
Coder Trainee
Written by

Coder Trainee

Experienced in Java and Python, we share and learn together. For submissions or collaborations, DM us.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.