准备两台服务器或者虚拟机
服务器一:192.***.*.31
服务器二:192.***.*.32
部署模式: 2M-2S-SYNC(两主两从同步写)
相关安装包存储路径:/root/svr/rocketmq
Apache:
https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.2.0/rocketmq-all-4.2.0-bin-release.zip
Github:
https://github.com/apache/rocketmq/
运行: unzip rocketmq-all-4.2.0-bin-release.zip -d /root/svr/rocketmq
命令: vim /etc/hosts
192.***.*.31 rocketmq1
192.***.*.32 rocketmq2
配置环境变量:vim /etc/profile
export ROCKETMQ_HOME=/root/svr/rocketmq
export PATH=$PATH::$ROCKETMQ_HOME/bin
执行:source /etc/profile
命令(master): vim /root/svr/rocketmq/conf/2m-2s-sync/broker-a.properties
brokerClusterName=rocketmq-cluster
brokerName=broker-a
brokerId=0
namesrvAddr=rocketmq1:9876;rocketmq2:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10911
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88
storePathRootDir=/root/svr/rocketmq/data/store
storePathCommitLog=/root/svr/rocketmq/data/store/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
命令(slave) vim /root/svr/rocketmq/conf/2m-2s-sync/broker-b-s.properties
brokerClusterName=rocketmq-cluster
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=1
namesrvAddr=rocketmq1:9876;rocketmq2:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10922
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88
storePathRootDir=/root/svr/rocketmq/data/store2
storePathCommitLog=/root/svr/rocketmq/data/store2/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
#角色
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
mkdir /root/svr/rocketmq/data (也要创建store文件夹)
mkdir /root/svr/rocketmq/data/store/commitlog
mkdir /root/svr/rocketmq/data/store/consumequeue
mkdir /root/svr/rocketmq/data/store/index
mkdir -p /root/svr/rocketmq/logs
cd /root/svr/rocketmq/conf && sed -i 's#${user.home}#/root/svr/rocketmq#g' *.xml
注意logback.*.xml配置文件中${user.home}需要替换自己指定的目录
unbroker.sh,runserver.sh启动参数默认对jvm的堆内存设置比较大(不改启动不起来),如果是虚拟机非线上环境需要改下参数,大小可以根据自己机器来决定
默认大小
-Xms8g -Xmx8g -Xmn4g
改为:
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m"
scp 到其他服务器
scp -r rocketmq/ root@192.***.*.32:/root/svr/
在 /root/svr/rocketmq/bin
目录下执行命令:nohup sh mqnamesrv &
在 /root/svr/rocketmq/bin
目录下执行命令:nohup sh mqbroker -c /root/svr/rocketmq/conf/2m-2s-sync/broker-a.properties&
输入命令jps或者查看rocketmq/logs下日志是否输出正常
sh mqadmin clusterlist -n 192.***.*.31:9876
https://github.com/apache/rocketmq-externals.git
rocketmq.config.namesrvAddr=192.***.*.31:9876
export NAMESRV_ADDR=rocketmq1:9876
测试发送端
> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
测试消费端
> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
在 /root/svr/rocketmq/bin
目录下执行命令或者jps查看进程号 kill -9 pid
sh mqshutdown broker
sh mqshutdown namesrv