Operations 18 min read

Step‑by‑Step Installation and Configuration of a 2‑Master‑2‑Slave Asynchronous RocketMQ Cluster

This article provides a comprehensive guide to installing and configuring Apache RocketMQ, covering its history, core features, high‑availability architectures, detailed port planning, downloading, editing broker configuration files, creating data directories, starting NameServer and brokers, troubleshooting common issues, and deploying the web console for monitoring.

Architecture Digest
Architecture Digest
Architecture Digest
Step‑by‑Step Installation and Configuration of a 2‑Master‑2‑Slave Asynchronous RocketMQ Cluster

RocketMQ is an open‑source messaging middleware originally released by Alibaba in 2012 and graduated to an Apache top‑level project in 2017. It supports Java, C/C++, Python and Go, and its design borrows heavily from Kafka while adding several distinct capabilities such as zero‑copy I/O, Netty‑based networking, and NameServer‑based service discovery.

High‑Availability Architecture

RocketMQ offers multiple cluster modes: single master, multiple masters, multi‑master with asynchronous replication, and multi‑master with synchronous replication. The article recommends the fourth mode (2‑master‑2‑slave asynchronous) for a balance of performance and reliability.

Port Planning

# Machine 1 (42.192.77.73)
NameServer1: 9876
BrokerA‑master: 10910
BrokerB‑slave: 10921

# Machine 2 (39.103.144.86)
NameServer2: 9876
BrokerB‑master: 10920
BrokerA‑slave: 10911

Downloading RocketMQ

Obtain the latest binary package from rocketmq.apache.org , unzip it and rename the directory to rocketmq:

cd /jackxu
wget https://mirror.bit.edu.cn/apache/rocketmq/4.8.0/rocketmq-all-4.8.0-bin-release.zip
unzip rocketmq-all-4.8.0-bin-release.zip
mv rocketmq-all-4.8.0-bin-release rocketmq

Configuration Files

Use the 2m-2s-async configuration set. Edit broker-a.properties and broker-b-s.properties on the first machine, and the corresponding files on the second machine, setting the cluster name, listen ports, auto‑creation flags, NameServer addresses, and storage paths. Example snippet:

brokerClusterName=jackxu-cluster
listenPort=10910
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
namesrvAddr=39.103.144.86:9876;42.192.77.73:9876
storePathRootDir=/jackxu/rocketmq/store/broker-a
storePathCommitLog=/jackxu/rocketmq/store/broker-a/commitlog
storePathConsumeQueue=/jackxu/rocketmq/store/broker-a/consumequeue
storePathIndex=/jackxu/rocketmq/store/broker-a/index

Data Directories

Create the required directories on both machines, e.g.:

mkdir -p /jackxu/rocketmq/store/broker-a /jackxu/rocketmq/store/broker-a/consumequeue /jackxu/rocketmq/store/broker-a/commitlog /jackxu/rocketmq/store/broker-a/index /jackxu/rocketmq/logs

Starting Services

Start a NameServer on each host:

nohup sh /jackxu/rocketmq/bin/mqnamesrv > /jackxu/rocketmq/logs/mqnamesrv.log 2>&1 &

Then start the brokers in the order A‑master, A‑slave, B‑master, B‑slave:

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

Verify the four Java processes with jps. Common pitfalls include missing JDK, insufficient memory, firewall blocks, and un‑opened ports; adjust runserver.sh and runbroker.sh to lower heap sizes if needed.

Web Console

Download the RocketMQ console source from github.com/apache/rocketmq-externals , build it with Maven, and run the generated JAR. Modify application.properties to set the console port and NameServer addresses.

server.port=7298
rocketmq.config.namesrvAddr=39.103.144.86:9876;42.192.77.73:9876

Access the UI at http://42.192.77.73:7298/ to view clusters, topics, consumers, producers, and messages.

High Availability & DLedger

Older versions rely on master‑slave replication; newer versions (>=4.5.0) can enable DLedger for Raft‑based automatic leader election. Enable it by adding:

enableDLegerCommitLog=true
dLegerGroup=broker-a
dLegerPeers=n0-192.168.44.163:10911;n1-192.168.44.164:10911;n2-192.168.44.165:10911
dLegerSelfId=n0

The recommended production setup combines asynchronous flushing (ASYNC_FLUSH) with synchronous replication (SYNC_MASTER) for high throughput while preserving data safety.

Conclusion

Hands‑on installation of RocketMQ helps developers understand its configuration nuances, prepares them for real‑world deployment, and lays the groundwork for later topics such as message production, consumption, and performance tuning.

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.

high availabilityMessage QueueRocketMQInstallation
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

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.