1.下载解压
安装版本要跟项目依赖版本一致 (这里用4.3.0)
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-broker</artifactId>
<version>4.3.0</version>
</dependency>
下载地址:http://mirror.bit.edu.cn/apache/rocketmq/
mkdir -p /data/rocketmq
cd /data/rocketmq
wget http://mirror.bit.edu.cn/apache/rocketmq/4.3.0/rocketmq-all-4.3.0-bin-release.zip
unzip rocketmq-all-4.3.0-bin-release.zip
2.创建节点路径
10.51.52.27(rocketmq-nameserver-1):
mkdir -p /data/rocketmq/store/{rootdir-a-m,commitlog-a-m,rootdir-b-s,commitlog-b-s}
10.51.52.27(rocketmq-nameserver-2):
mkdir -p /data/rocketmq/store/{rootdir-b-m,commitlog-b-m,rootdir-a-s,commitlog-a-s}
3.修改配置文件
修改之前先备份~以防意外
cd /data/rocketmq/rocketmq-all-4.3.0-bin-release;
cp -r conf/ conf.bak/
本文采用双主双从异步复制,默认的rocketmq已经为我们配置了相应配置目录
cd /data/rocketmq/rocketmq-all-4.3.0-bin-release/conf/2m-2s-async;
10.51.52.28 xc-rocket-mq-cluster 角色:broker-a-master & broker-b-slave
vim broker-a.properties (10.51.52.28)
brokerClusterName=xc-rocket-mq-cluster
brokerName=xc-rocketmq-nameserver-1
brokerIP1=10.51.52.28
#brokerId 0 表示 Master,>0 表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=10.51.52.27:9876;10.51.52.28:9876
# Broker 对外服务的监听端口
listenPort=10911
# 删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=72
#Broker role有3种:SYNC MASTER、ASYNC MASTER、SLAVE。关键词SYNC和ASYNC表示Master和Slave之间同步消息的机制,SYNC即同步更新,指当Slave和Master消息同步完成后,再返回发送成功的状态。ASYNC即异步更新,master与slave有短暂消息延迟,毫秒级。本文在此使用了异步复制集群模式,线上环境推荐使用同步双写模式,即SYNC_MASTER
brokerRole=ASYNC_MASTER
# 刷盘方式 ASYNC_FLUSH 异步刷盘
flushDiskType=ASYNC_FLUSH
#存储路径
storePathRootDir=/data/rocketmq/store/rootdir-a-m
storePathCommitLog=/data/rocketmq/store/commitlog-a-m
# 是否允许 Broker 自动创建Topic
autoCreateTopicEnable=true
# 是否允许 Broker 自动创建订阅组
autoCreateSubscriptionGroup=true
vim broker-b-s.properties (10.51.52.28)
brokerClusterName=xc-rocket-mq-cluster
brokerName=xc-rocketmq-nameserver-2
brokerId=1
listenPort=10921
deleteWhen=04
fileReservedTime=72
namesrvAddr=10.51.52.27:9876;10.51.52.28:9876
brokerRole=SLAVE
storePathRootDir=/data/rocketmq/store/rootdir-b-s
storePathCommitLog=/data/rocketmq/store/commitlog-b-s
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
flushDiskType=ASYNC_FLUSH
10.51.52.27 rocketmq-nameserver-2 角色:broker-b-master & broker-a-slave
vim broker-b.properties (10.51.52.27)
brokerClusterName=xc-rocket-mq-cluster
brokerName=xc-rocketmq-nameserver-2
brokerIP1=10.51.52.27
brokerId=0
listenPort=10911
namesrvAddr=10.51.52.27:9876;10.51.52.28:9876
deleteWhen=04
fileReservedTime=72
brokerRole=ASYNC_MASTER
storePathRootDir=/data/rocketmq/store/rootdir-b-m
storePathCommitLog=/data/rocketmq/store/commitlog-b-m
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
flushDiskType=ASYNC_FLUSH
vim broker-a-s.properties (10.51.52.27)
brokerClusterName=xc-rocket-mq-cluster
brokerName=xc-rocketmq-nameserver-1
listenPort=10921
namesrvAddr=10.51.52.27:9876;10.51.52.28:9876
brokerId=1
deleteWhen=04
fileReservedTime=72
brokerRole=SLAVE
storePathRootDir=/data/rocketmq/store/rootdir-a-s
storePathCommitLog=/data/rocketmq/store/commitlog-a-s
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
flushDiskType=ASYNC_FLUSH
4.修改启动脚本参数
先备份
cd /data/rocketmq/rocketmq-all-4.3.0-bin-release/bin
cp runbroker.sh runbroker.sh.default
调一下JVM,包括nameserver 和 broker。限于自己机器的配置,参数调小一下。但Rocketmq最少的堆是1g,否则无法启动。两台机器执行相同的操作。
JAVA_OPT="$ -server -Xms16g -Xmx16g -Xmn8g -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=1g"
5.服务启动
1.启动nameserver,两台机器操作相同
nohup sh /data/rocketmq/rocketmq-all-4.3.0-bin-release/bin/mqnamesrv > /data/rocketmq/store/mqnamesrv.log 2>&1 &
- 启动broker。两台机器不一样,这里一个一个去启动
<1> 10.51.52.28 xc-rocket-mq-cluster
启动broker_a(master)
nohup sh /data/rocketmq/rocketmq-all-4.3.0-bin-release/bin/mqbroker -c /opt/apps/rocketmq/conf/2m-2s-async/broker-a.properties > /data/rocketmq/store/broker-a-m.log 2>&1 &
启动broker_b_slave
nohup sh /data/rocketmq/rocketmq-all-4.3.0-bin-release/bin/mqbroker -c /opt/apps/rocketmq/conf/2m-2s-async/broker-b-s.properties > /data/rocketmq/store/broker-b-s.log 2>&1 &
<2> 10.51.52.27 rocketmq-nameserver-2
启动broker-b(master)
nohup sh /data/rocketmq/rocketmq-all-4.3.0-bin-release/bin/mqbroker -c /opt/apps/rocketmq/conf/2m-2s-async/broker-b.properties > /data/rocketmq/store/broker-b-m.log 2>&1 &
启动broker_a_slave
nohup sh /data/rocketmq/rocketmq-all-4.3.0-bin-release/bin/mqbroker -c /opt/apps/rocketmq/conf/2m-2s-async/broker-a-s.properties > /data/rocketmq/store/broker-a-s.log 2>&1 &
先启动nameserver,再启动broker,两台机器的启动顺序:启动nameserver->启动broker master->启动broker slave,done
都启动完毕之后可以jps看一下
[yepikai@vyz-xiangcheng2-1 rocketmq]$ jps
31520 QuorumPeerMain
28657 Jps
3858 BrokerStartup
3958 BrokerStartup
31704 NamesrvStartup
31358 QuorumPeerMain
查看服务启动后的机器状态
[yepikai@vyz-xiangcheng2-1 bin]$ ./mqadmin clusterList --namesrvAddr=10.51.52.27:9876
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
#Cluster Name #Broker Name #BID #Addr #Version #InTPS(LOAD) #OutTPS(LOAD) #PCWait(ms) #Hour #SPACE
xc-rocket-mq-cluster xc-rocketmq-nameserver-1 0 10.51.52.28:10911 V4_3_0 0.00(0,0ms) 0.00(0,0ms) 0 441078.33 0.0763
xc-rocket-mq-cluster xc-rocketmq-nameserver-1 1 10.51.52.27:10921 V4_3_0 0.00(0,0ms) 0.00(0,0ms) 0 441078.33 0.0925
xc-rocket-mq-cluster xc-rocketmq-nameserver-2 0 10.51.52.27:10911 V4_3_0 0.00(0,0ms) 0.00(0,0ms) 0 441078.33 0.0925
xc-rocket-mq-cluster xc-rocketmq-nameserver-2 1 10.51.52.28:10921 V4_3_0 0.00(0,0ms) 0.00(0,0ms) 0 441078.33 0.0763
6.服务关闭
关闭nameserver:
/data/rocketmq/rocketmq-all-4.3.0-bin-release/bin/mqshutdown namesrv
关闭broker:
/data/rocketmq/rocketmq-all-4.3.0-bin-release/bin/mqshutdown broker
7.部署rocketmq-console
略...