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.
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:9876Then 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:98764. 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.outStart 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Coder Trainee
Experienced in Java and Python, we share and learn together. For submissions or collaborations, DM us.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
