Operations 16 min read

Step‑by‑Step Guide to Deploy RocketMQ 4.9.7: Single‑Node and Cluster Installation

This tutorial walks you through installing RocketMQ 4.9.7, configuring a single‑node setup, then building a production‑grade nameserver cluster and master‑slave broker cluster with all required scripts, directories, and commands for running and shutting down the services.

Lin is Dream
Lin is Dream
Lin is Dream
Step‑by‑Step Guide to Deploy RocketMQ 4.9.7: Single‑Node and Cluster Installation

RocketMQ is a high‑performance Java‑based message queue system that runs a nameserver and broker processes. This guide shows how to install the binary release (v4.9.7), configure and start a single‑node instance, then build a production‑grade nameserver cluster and a master‑slave broker cluster, including all required configuration files, directory layout, and command‑line scripts. It also provides the commands to run and verify the services and to shut them down safely.

Single‑Node Deployment

1. Download binary package

cd /home/recharge/local
wget https://archive.apache.org/dist/rocketmq/4.9.7/rocketmq-all-4.9.7-bin-release.zip
# If unzip is not installed, install it first: yum install -y unzip
unzip rocketmq-all-4.9.7-bin-release.zip
mv rocketmq-all-4.9.7-bin-release rocketmq-4.9.7

2. Initialize configuration files

mkdir -p ./rocketmq-namesrv-1/logs \
    ./rocketmq-namesrv-1/store \
    ./rocketmq-master-1/logs \
    ./rocketmq-master-1/store

vim ./rocketmq-namesrv-1/namesrv.properties
# NameServer storage path
storePathRootDir=/home/recharge/local/rocketmq-namesrv-1/store/
# NameServer listening port (default 9876)
listenPort=9876
# Broker heartbeat timeout (ms)
waitTimeMillsInHeartbeat=30000

vim ./rocketmq-master-1/broker.conf
# Edit the following fields
brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
namesrvAddr=127.0.0.1:9876
brokerIP1=192.168.110.10
listenPort=10911
haListenPort=10912
autoCreateTopicEnable=true

3. Run services

# Start nameserver
nohup sh ./rocketmq-4.9.7/bin/mqnamesrv -c ./rocketmq-namesrv-1/namesrv.properties &> ./rocketmq-namesrv-1/logs/namesrv.log &
# Verify nameserver startup
tail -f -n 100 ./rocketmq-namesrv-1/logs/namesrv.log
# Start broker
nohup sh ./rocketmq-4.9.7/bin/mqbroker -c ./rocketmq-master-1/broker.conf &> ./rocketmq-master-1/logs/broker.log &
# Verify broker startup
tail -f -n 100 ./rocketmq-master-1/logs/broker.log

4. Shut down services

sh ./rocketmq-4.9.7/bin/mqshutdown namesrv
sh ./rocketmq-4.9.7/bin/mqshutdown broker

Cluster Deployment

Nameserver Cluster

1. Initialize directories

mkdir -p ./rocketmq-namesrv-1/logs ./rocketmq-namesrv-1/store \
    ./rocketmq-namesrv-2/logs ./rocketmq-namesrv-2/store \
    ./rocketmq-namesrv-3/logs ./rocketmq-namesrv-3/store

2. Configure each nameserver

# namesrv-1
vim ./rocketmq-namesrv-1/namesrv.properties
storePathRootDir=/home/recharge/local/rocketmq-namesrv-1/store/
listenPort=9876
waitTimeMillsInHeartbeat=30000

# namesrv-2
vim ./rocketmq-namesrv-2/namesrv.properties
storePathRootDir=/home/recharge/local/rocketmq-namesrv-2/store/
listenPort=9877
waitTimeMillsInHeartbeat=30000

# namesrv-3
vim ./rocketmq-namesrv-3/namesrv.properties
storePathRootDir=/home/recharge/local/rocketmq-namesrv-3/store/
listenPort=9878
waitTimeMillsInHeartbeat=30000

3. Start the nameserver cluster

# namesrv-1
nohup sh ./rocketmq-4.9.7/bin/mqnamesrv -c ./rocketmq-namesrv-1/namesrv.properties &> ./rocketmq-namesrv-1/logs/namesrv.log &
# namesrv-2
nohup sh ./rocketmq-4.9.7/bin/mqnamesrv -c ./rocketmq-namesrv-2/namesrv.properties &> ./rocketmq-namesrv-2/logs/namesrv.log &
# namesrv-3
nohup sh ./rocketmq-4.9.7/bin/mqnamesrv -c ./rocketmq-namesrv-3/namesrv.properties &> ./rocketmq-namesrv-3/logs/namesrv.log &

Master‑Slave Broker Cluster

1. Initialize directories for masters and slaves

mkdir -p ./rocketmq-master-1/logs ./rocketmq-master-1/store \
    ./rocketmq-slave-1/logs ./rocketmq-slave-1/store \
    ./rocketmq-master-2/logs ./rocketmq-master-2/store \
    ./rocketmq-slave-2/logs ./rocketmq-slave-2/store

2. Configure master‑1

cp ./rocketmq-4.9.7/conf/broker.conf ./rocketmq-master-1/broker.conf
vim ./rocketmq-master-1/broker.conf
brokerClusterName=rocketmq-cluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
namesrvAddr=127.0.0.1:9876;127.0.0.1:9877;127.0.0.1:9878
brokerIP1=192.168.110.10
listenPort=10911
haListenPort=10912
autoCreateTopicEnable=true

3. Configure slave‑1

cp ./rocketmq-4.9.7/conf/broker.conf ./rocketmq-slave-1/broker.conf
vim ./rocketmq-slave-1/broker.conf
brokerClusterName=rocketmq-cluster
brokerName=broker-a
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
namesrvAddr=127.0.0.1:9876;127.0.0.1:9877;127.0.0.1:9878
brokerIP1=192.168.110.10
listenPort=20911
haListenPort=20912
autoCreateTopicEnable=false

4. Configure master‑2 and slave‑2 (similar to above, using broker-b and ports 11911/11912, 21911/21912)

# master‑2
cp ./rocketmq-4.9.7/conf/broker.conf ./rocketmq-master-2/broker.conf
vim ./rocketmq-master-2/broker.conf
brokerClusterName=rocketmq-cluster
brokerName=broker-b
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
namesrvAddr=127.0.0.1:9876;127.0.0.1:9877;127.0.0.1:9878
brokerIP1=192.168.110.10
listenPort=11911
haListenPort=11912
autoCreateTopicEnable=true

# slave‑2
cp ./rocketmq-4.9.7/conf/broker.conf ./rocketmq-slave-2/broker.conf
vim ./rocketmq-slave-2/broker.conf
brokerClusterName=rocketmq-cluster
brokerName=broker-b
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
namesrvAddr=127.0.0.1:9876;127.0.0.1:9877;127.0.0.1:9878
brokerIP1=192.168.110.10
listenPort=21911
haListenPort=21912
autoCreateTopicEnable=false

5. Start all broker services

# master‑1
nohup sh ./rocketmq-4.9.7/bin/mqbroker -c ./rocketmq-master-1/broker.conf &> ./rocketmq-master-1/logs/broker.log &
# slave‑1
nohup sh ./rocketmq-4.9.7/bin/mqbroker -c ./rocketmq-slave-1/broker.conf &> ./rocketmq-slave-1/logs/broker.log &
# master‑2
nohup sh ./rocketmq-4.9.7/bin/mqbroker -c ./rocketmq-master-2/broker.conf &> ./rocketmq-master-2/logs/broker.log &
# slave‑2
nohup sh ./rocketmq-4.9.7/bin/mqbroker -c ./rocketmq-slave-2/broker.conf &> ./rocketmq-slave-2/logs/broker.log &

6. Verify and shut down the cluster

# Verify broker processes
ps -aux | grep org.apache.rocketmq.broker.BrokerStartup
# Shut down all brokers
sh ./rocketmq-4.9.7/bin/mqshutdown broker
# Shut down all nameservers
sh ./rocketmq-4.9.7/bin/mqshutdown namesrv

After completing these steps, the RocketMQ cluster is ready for production use.

Lin is Dream
Written by

Lin is Dream

Sharing Java developer knowledge, practical articles, and continuous insights into computer engineering.

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.