How to Build a High‑Availability RocketMQ Cluster on Two Linux Servers

This guide walks through setting up a fault‑tolerant RocketMQ cluster on two CentOS 7 servers, covering installation of Java, NameServer, multiple Master‑Slave brokers in async and sync modes, configuration tweaks, port opening, verification, and optional console deployment.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Build a High‑Availability RocketMQ Cluster on Two Linux Servers

1. Cluster Deployment Options

RocketMQ physical deployment diagram.

Producer and Consumer are applications. NameServer cluster consists of independent instances; deploying two or more ensures high availability. For Broker, several cluster deployment modes are available:

1. Single Master Mode

High risk; not recommended for production, only for local testing.

2. Multi‑Master Mode

All nodes are Masters (e.g., 2 or 3). Advantages: simple configuration, no impact when a Master restarts, high performance with RAID10. Disadvantages: messages on a down machine cannot be consumed until it recovers.

3. Multi‑Master Multi‑Slave (Async Replication)

Each Master has a Slave; HA uses asynchronous replication, causing millisecond‑level delay. Advantages: minimal message loss, transparent failover, performance similar to multi‑master. Disadvantage: possible loss of a few messages if Master fails and disk is damaged.

4. Multi‑Master Multi‑Slave (Sync Dual‑Write)

HA uses synchronous dual‑write; both Master and Slave must write successfully. Advantages: no single point of failure, zero message delay on Master failure. Disadvantage: ~10% lower performance, higher latency, and current version does not auto‑promote Slave after Master crash.

This article shows how to build a high‑availability RocketMQ cluster with dual NameServers, dual Masters, and dual Slaves on two servers (IP 192.168.31.186 and 192.168.31.231).

2. Installation Environment

Linux: CentOS 7

RocketMQ version: 4.7.0

Java version: JDK 1.8

3. Installation Steps

3.1 Install Java

On each server, download the JDK package, upload to /usr/local/java, extract, and configure environment variables.

cd /usr/local/
mkdir java
tar zxvf jdk-8u161-linux-x64.tar.gz
vi /etc/profile
JAVA_HOME=/usr/local/java/jdk1.8.0_161
CLASSPATH=.:$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
source /etc/profile
java -version

3.2 Install NameServer

Create data directory, download and unzip RocketMQ, then start NameServer.

mkdir /data
wget https://mirror.bit.edu.cn/apache/rocketmq/4.7.0/rocketmq-all-4.7.0-bin-release.zip
unzip rocketmq-all-4.7.0-bin-release.zip
nohup sh /data/rocketmq-all-4.7.0-bin-release/bin/mqnamesrv &
jps

3.3 Install Brokers

Configure Master and Slave broker property files for each server (examples of broker-a.properties, broker-b.properties, broker-a-s.properties, broker-b-s.properties). Key settings include brokerClusterName, brokerName, brokerId, brokerRole, flushDiskType, listenPort, namesrvAddr, and storage paths.

# Example snippet from broker-a.properties
brokerClusterName=rocketmq-cluster
brokerName=broker-a
brokerId=0
brokerRole=ASYNC_MASTER
flushDiskType=SYNC_FLUSH
listenPort=10911
namesrvAddr=192.168.31.186:9876;192.168.31.231:9876
...

Start Brokers

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

3.3.1 Memory Issues

If Java cannot allocate memory, reduce JVM heap in bin/runbroker.sh:

JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn512m"

3.3.2 Open Required Ports

NameServer: 9876; Broker: 10911, 11011, 10909, 11009.

3.4 Verification

Check broker.log and use mqadmin to list cluster status.

sh bin/mqadmin clusterList -n "192.168.31.186:9876;192.168.31.231:9876"

3.5 Shutdown

sh bin/mqshutdown broker
sh bin/mqshutdown namesrv

4. Optional: Install rocketmq-console

Install Maven, download rocketmq-externals, build the console, and run it.

wget http://mirrors.cnnic.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
tar zxvf apache-maven-3.5.4-bin.tar.gz
export MAVEN_HOME=/data/apache-maven-3.5.4
export PATH=$MAVEN_HOME/bin:$PATH
mvn -v
wget https://github.com/apache/rocketmq-externals/archive/refs/heads/master.zip
unzip master.zip
cd rocketmq-externals-master/rocketmq-console/
mvn clean package -Dmaven.test.skip=true
java -jar target/rocketmq-console-ng-1.0.1.jar --rocketmq.config.namesrvAddr='192.168.31.186:9876;192.168.31.231:9876'

Access http://192.168.31.186:8080 to view the console UI.

5. References

http://rocketmq.apache.org/docs/quick-start/
https://github.com/apache/rocketmq/tree/master/docs/cn
https://github.com/apache/rocketmq-externals/tree/master/rocketmq-console
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.

Javahigh availabilityRocketMQBrokerCluster Deployment
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.