欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Windows搭建RocketMQ集群

程序员文章站 2022-07-14 23:26:25
...

在上一篇文章的基础上
修改配置
在conf文件夹下你就会发现2m-2s-sync文件夹
修改boker-a.properties

brokerClusterName=ItcastCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
namesrvAddr=127.0.0.1:9876;127.0.0.1:9877
brokerIP1=127.0.0.1
brokerIp2=127.0.01
listenPort=10911
autoCreateTopicEnable=true

修改boker-a-s.properties

brokerClusterName=ItcastCluster
brokerName=broker-a-s
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
namesrvAddr=127.0.0.1:9876;127.0.0.1:9877
brokerIP1=127.0.0.1
brokerIp2=127.0.01
listenPort=10711
autoCreateTopicEnable=true

修改boker-b.properties

brokerClusterName=ItcastCluster
brokerName=broker-b
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
namesrvAddr=127.0.0.1:9876;127.0.0.1:9877
brokerIP1=127.0.0.1
brokerIp2=127.0.01
listenPort=10811
autoCreateTopicEnable=true

修改boker-b-s.properties

brokerClusterName=ItcastCluster
brokerName=broker-b-s
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
namesrvAddr=127.0.0.1:9876;127.0.0.1:9877
brokerIP1=127.0.0.1
brokerIp2=127.0.01
listenPort=10611
autoCreateTopicEnable=true

新建namesrv配置
Windows搭建RocketMQ集群
在namesrv-a.properties添加

listenPort=9876

在namesrv-b.properties添加

listenPort=9877

修改启动命令
修改runbroker.cmd
-server -Xms256m -Xmx256m -Xmn128m

set "JAVA_OPT=%JAVA_OPT% -server -Xms256m -Xmx256m -Xmn128m"
set "JAVA_OPT=%JAVA_OPT% -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRUPolicyMSPerMB=0 -XX:SurvivorRatio=8"
set "JAVA_OPT=%JAVA_OPT% -verbose:gc -Xloggc:%USERPROFILE%\mq_gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy"
set "JAVA_OPT=%JAVA_OPT% -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m"
set "JAVA_OPT=%JAVA_OPT% -XX:-OmitStackTraceInFastThrow"
set "JAVA_OPT=%JAVA_OPT% -XX:+AlwaysPreTouch"
set "JAVA_OPT=%JAVA_OPT% -XX:MaxDirectMemorySize=15g"
set "JAVA_OPT=%JAVA_OPT% -XX:-UseLargePages -XX:-UseBiasedLocking"
set "JAVA_OPT=%JAVA_OPT% -Djava.ext.dirs=%BASE_DIR%lib"
set "JAVA_OPT=%JAVA_OPT% -cp %CLASSPATH%"

修改runserver.cmd
-Xms256m -Xmx256m -Xmn256m


set "JAVA_OPT=%JAVA_OPT% -server -Xms256m -Xmx256m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
set "JAVA_OPT=%JAVA_OPT% -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:-UseParNewGC"
set "JAVA_OPT=%JAVA_OPT% -verbose:gc -Xloggc:"%USERPROFILE%\rmq_srv_gc.log" -XX:+PrintGCDetails"
set "JAVA_OPT=%JAVA_OPT% -XX:-OmitStackTraceInFastThrow"
set "JAVA_OPT=%JAVA_OPT% -XX:-UseLargePages"
set "JAVA_OPT=%JAVA_OPT% -Djava.ext.dirs=%BASE_DIR%lib"
set "JAVA_OPT=%JAVA_OPT% -cp "%CLASSPATH%""

配置环境变量

key = ROCKETMQ_HOME
 
    D:\rocketmq-all-4.3.2-bin-release

启动

mqnamesrv.cmd -c ../conf/2m-2s-sync/namesrv-a.properties
mqnamesrv.cmd -c ../conf/2m-2s-sync/namesrv-b.properties
mqbroker.cmd -c ../conf/2m-2s-sync/broker-a.properties
mqbroker.cmd -c ../conf/2m-2s-sync/broker-a-s.properties
mqbroker.cmd -c ../conf/2m-2s-sync/broker-b.properties
mqbroker.cmd -c ../conf/2m-2s-sync/broker-b-s.properties

启动 RocketMQ 集群报错

java.lang.RuntimeException: Lock failed,MQ already started
	at org.apache.rocketmq.store.DefaultMessageStore.start(DefaultMessageStore.java:214)
	at org.apache.rocketmq.broker.BrokerController.start(BrokerController.java:827)
	at org.apache.rocketmq.broker.BrokerStartup.start(BrokerStartup.java:64)
	at org.apache.rocketmq.broker.BrokerStartup.main(BrokerStartup.java:58)

原因:
学习阶段,将 broker 的 master 和 slave 节点放在同一台机器上,配置的storePath相同导致的,修改配置文件,改为不同的路径即可解决。
解决:
在每个properties添加路径

#存储路径
storePathRootDir=D:\RocketMq\store\broker-a
#commitLog 存储路径
storePathCommitLog=D:\RocketMq\store\broker-a\commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=D:\RocketMq\store\broker-a\consumequeue
#消息索引存储路径
storePathIndex=D:\RocketMq\store\broker-a\index
#checkpoint 文件存储路径
storeCheckpoint=D:\RocketMq\store\broker-a\checkpoint
#abort 文件存储路径
abortFile=D:\RocketMq\store\broker-a\abort
#存储路径
storePathRootDir=D:\RocketMq\store\broker-a-s
#commitLog 存储路径
storePathCommitLog=D:\RocketMq\store\broker-a-s\commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=D:\RocketMq\store\broker-a-s\consumequeue
#消息索引存储路径
storePathIndex=D:\RocketMq\store\broker-a-s\index
#checkpoint 文件存储路径
storeCheckpoint=D:\RocketMq\store\broker-a-s\checkpoint
#abort 文件存储路径
abortFile=D:\RocketMq\store\broker-a-s\abort

结果
Windows搭建RocketMQ集群
Windows搭建RocketMQ集群

相关标签: java 分布式