环境要求:

需要安装jdk1.6以上,maven3.X以上,git

一、maven安装

1.下载软件:wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz

2.安装

tar xf apache-maven-3.3.9-bin.tar.gz -C /usr/local
cd /usr/local
ln -sv apache-maven-3.3.9 maven
vi /etc/profile.d/maven.sh
export PATH=$PATH:/usr/local/maven/bin

3.验证

wKioL1kR4yWjDLSuAAAi8ExXwpY795.png-wh_50

二、安装rocketmq

1.下载软件

git clone https://github.com/alibaba/RocketMQ.git

版本:3.5.8

2.安装

cd RocketMQ
bash install.sh

安装过程比较久,安装结束后

wKiom1kR40nw6fG-AABkllYVa4E527.png-wh_50

3.拷贝文件

安装结束后会生成链接文件

devenv -> target/alibaba-rocketmq-broker/alibaba-rocketmq

wKioL1kR43TiuZh3AAAjeRcTA14163.png-wh_50

alibaba-rocketmq目录下的文件拷贝出来即可

三、配置rocketmq

搭建双主双从

由于topics.json及subscriptionGroup.json默认位置保存在用户家目录下,当一台机器部署多个broker时,采用不同的用户启动broker以保证配置文件唯一。

nameserver:192.168.115.11

broker-a-6.0-test:192.168.115.11  master

broker-a-6.0-test:192.168.115.12  slave

broker-b-6.0-test:192.168.115.12  master

broker-b-6.0-test:192.168.115.11  slave

1.修改broker配置文件(broker-a-6.0-test为例)

master

# cd /usr/local/rocketMQ/conf/2m-2s-sync/
# cat broker-a.properties
listenPort=10911
namesrvAddr=192.168.115.11:9876
brokerIP1=192.168.115.11
brokerName=broker-a-6.0-test
brokerClusterName=fjhb6_test
brokerId=0
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=false
rejectTransactionMessage=false
fetchNamesrvAddrByAddressServer=false
diskMaxUsedSpaceRatio=95
rootDir=/data/rocketmq_data/broke-a/store
storePathRootDir=/data/rocketmq_data/broke-a/store
storePathCommitLog=/data/rocketmq_data/broke-a/commitlog
storePathConsumeQueue=/data/rocketmq_data/broke-a/consumequeue
storePathIndex=/data/rocketmq_data/broke-a/index
storeCheckpoint=/data/rocketmq_data/broke-a/checkpoint
abortFile=/data/rocketmq_data/broke-a/abort
topicConfigPath=/data/rocketmq_data/broke-a/store/config
subscriptionGroupPath=/data/rocketmq_data/broke-a/store/config
flushIntervalCommitLog=1000
flushCommitLogTimed=false
deleteWhen=04
fileReservedTime=72
maxTransferBytesOnMessageInMemory=33554432
maxTransferCountOnMessageInMemory=32
maxTransferBytesOnMessageInDisk=65536
maxTransferCountOnMessageInDisk=8
accessMessageInMemoryMaxRatio=40
messageIndexEnable=true
messageIndexSafe=false
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
cleanFileForciblyEnable=true
创建目录
#mkdir /data/rocketmq_data/broke-a
#chown  -R mqtest.root /data/rocketmq_data/broke-a

slave

# cd /usr/local/rocketMQ/conf/2m-2s-sync/
# cat broker-a-s.properties
listenPort=30922
namesrvAddr=192.168.115.11:9876
brokerIP1=192.168.115.12
brokerName=broker-a-6.0-test
brokerClusterName=fjhb6_test
brokerId=1
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=false
rejectTransactionMessage=false
fetchNamesrvAddrByAddressServer=false
diskMaxUsedSpaceRatio=95
storePathRootDir=/data/rocketmq_data/broker-a/store
storePathCommitLog=/data/rocketmq_data/broker-a/commitlog
storePathConsumeQueue=/data/rocketmq_data/broker-a/consumequeue
storePathIndex=/data/rocketmq_data/broker-a/index
storeCheckpoint=/data/rocketmq_data/broker-a/checkpoint
abortFile=/data/rocketmq_data/broker-a/abort
topicConfigPath=/data/rocketmq_data/broker-a/store/config/topics.json
subscriptionGroupPath=/data/rocketmq_data/broker-a/store/config/subscriptionGroup.json
flushIntervalCommitLog=1000
flushCommitLogTimed=false
deleteWhen=04
fileReservedTime=72
maxTransferBytesOnMessageInMemory=33554432
maxTransferCountOnMessageInMemory=32
maxTransferBytesOnMessageInDisk=65536
maxTransferCountOnMessageInDisk=8
accessMessageInMemoryMaxRatio=40
messageIndexEnable=true
messageIndexSafe=false
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
cleanFileForciblyEnable=true
创建目录
#mkdir /data/rocketmq_data/broker-a
#chown  -R mqtest.root /data/rocketmq_data/broker-a

broker-b-6.0-test配置类似,broker-b-6.0-test直接root用户启动

2.启动服务

nameserver
# cat start_nameserver.sh
#!/bin/sh
#
HOMEDIR=/usr/local/rocketMQ
# Start nameserver
nohup sh $HOMEDIR/bin/mqnamesrv > $HOMEDIR/logs/nameserver.log  2>&1 &
echo "Start Name Server and Broker a master Successfully, ${ADDR}"
 
#bash start_nameserver.sh
broker-a
su - mqtest
# cat start_broker.sh
#!/bin/sh
#
HOMEDIR=/usr/local/rocketMQ
ADDR=192.168.115.11:9876
# Broker a master
nohup sh $HOMEDIR/bin/mqbroker -n ${ADDR} -c $HOMEDIR/conf/2m-2s-sync/broker-a.properties > $HOMEDIR/logs/broker-a.log 2>&1 &
echo "Start Name Server and Broker a master and Broker b slave Successfully, ${ADDR}"
 
bash start_broker.sh

3.登入控制台查看

http://192.168.115.12:3000/rocket-console/cluster/list.do

wKioL1kR5HehGJwBAACfX06ks9g884.png-wh_50

四、测试消息发送

1.创建topic

# /usr/local/rocketMQ/bin/mqadmin updateTopic -n 192.168.115.11:9876 -c fjhb6_test -t TopicTest

wKiom1kR5IvhZqe8AAAb6F6ovPU174.png-wh_50

2.发送消息

# export NAMESRV_ADDR=192.168.115.11:9876
# bash /usr/local/rocketMQ/bin/tools.sh com.alibaba.rocketmq.example.quickstart.Producer

wKioL1kR5LmTk4AaAAEtJSXv8jE135.png-wh_50

wKioL1kR5Z6CelxNAACq_oLQsXQ438.png-wh_50