Deploying a Sharded RocketMQ Cluster on CentOS 7

This guide walks through building a 3-master–3-slave RocketMQ cluster on CentOS 7, including NameServer setup, broker configuration, and the optional web console.

Prerequisites

  • JDK 8 or newer
  • Maven 3.2+
  • Git

Note: RocketMQ expects /usr/local/jdk by default. If your JDK lives elsewhere, update the startup scripts.

Install RocketMQ

Download

wget https://archive.apache.org/dist/rocketmq/4.9.0/rocketmq-all-4.9.0-bin-release.zip

Extract

unzip rocketmq-all-4.9.0-bin-release.zip -d /opt
mv /opt/rocketmq-all-4.9.0-bin-release /opt/rocketmq

Tune JVM settings

Edit /opt/rocketmq/bin/runserver.sh and /opt/rocketmq/bin/runbroker.sh:

# runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

# runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn1g"

Configure the cluster

The example uses three masters and three slaves (3m-3s). Each node needs its own broker.conf; adjust paths and IPs as needed.

Broker cofniguration (/opt/rocketmq/conf/broker.conf)

# Common
brokerClusterName = DataCluster
brokerName = broker-a          # broker-b, broker-c on other nodes
brokerId = 0                   # 0 = master, >0 = slave
namesrvAddr = 10.0.27.132:9876;10.0.27.133:9876;10.0.27.134:9876
brokerRole = ASYNC_MASTER      # or SLAVE / SYNC_MASTER
flushDiskType = ASYNC_FLUSH

# Storage
storePathRootDir = /data/rocketmq/store
storePathCommitLog = /data/rocketmq/store/commitlog
storePathConsumeQueue = /data/rocketmq/store/consumequeue
storePathIndex = /data/rocketmq/store/index
storeCheckpoint = /data/rocketmq/store/checkpoint
abortFile = /data/rocketmq/store/abort

# Misc
autoCreateTopicEnable = false
autoCreateSubscriptionGroup = false
brokerIP1 = 10.0.27.132
listenPort = 10911

NameServer configuration (/opt/rocketmq/conf/namesrv.conf)

listenPort = 9876
serverWorkerThreads = 8
serverSelectorThreads = 3
serverChannelMaxIdleTimeSeconds = 120
useEpollNativeSelector = true

Start the cluster

On every node:

# NameServer
nohup sh /opt/rocketmq/bin/mqnamesrv -c /opt/rocketmq/conf/namesrv.conf > namesrv.log 2>&1 &

# Broker
nohup sh /opt/rocketmq/bin/mqbroker -c /opt/rocketmq/conf/broker.conf > broker.log 2>&1 &

Install the web console

Clone & build

git clone https://github.com/apache/rocketmq-externals.git
cd rocketmq-externals/rocketmq-console
mvn clean package -DskipTests

Configure

Edit src/main/resources/application.properties:

server.port=8081
rocketmq.config.namesrvAddr=10.0.27.132:9876;10.0.27.133:9876;10.0.27.134:9876
rocketmq.config.dataPath=/opt/rocketmq-console/data

Run

java -jar target/rocketmq-console-ng-*.jar

Open http://<host>:8081 to monitor topics, brokers, and consumers.

Tags: rocketmq CentOS7 apache NameServer Broker

Posted on Mon, 27 Jul 2026 16:18:35 +0000 by andremta