RocketMQ 5.0本地源码启动3Nameserve+2broker集群

这里是weihubeats,觉得文章不错可以关注公众号小奏技术,文章首发。拒绝营销号,拒绝标题党

背景

由于RocketMQ 5.x主从同步的方式改动非常大,集群部署的方式也改动很大,所以打算本地启动一个小集群,进行debug研究源码学习

RocketMQ版本

  • 5.1.0

集群

打算本地启动3个Nameserve + 2个broker

Nameserve

controller内嵌在Nameserve中,也是三个

由于是本地启动多个controller+Nameserve,所以我们需要将端口打散,避免端口冲突

controller的端口如何配置

实际Nameserve的端口很容易知道是listenPort这个配置
但是controller 得端口具体是怎么配置的,官方也没有详细的文档说明,这里我们直接看源码吧

    • DLedgerConfig

这里的this.peers就是我们配置的controllerDLegerPeers

n0-127.0.0.1:9878;n1-10.100.10.200:9878;n2-10.100.9.21:9878

selfId就是我们配置的controllerDLegerSelfId

所以可以确定的是controller端口就是直接在controller最后面配置的
比如我们配置为

controllerDLegerPeers = n0-127.0.0.1:9870;n1-127.0.0.1:9871;n2-127.0.0.1:9872
controllerDLegerSelfId = n0

他会通过controllerDLegerPeerscontrollerDLegerSelfId解析出你用n0-127.0.0.1:9870 9870这个端口

Nameserve 配置

  • namesrv-n0.conf
enableControllerInNamesrv = true







#controller config


controllerDLegerGroup = group1


enableElectUncleanMaster = true


controllerDLegerPeers = n0-127.0.0.1:9870;n1-127.0.0.1:9871;n2-127.0.0.1:9872


controllerDLegerSelfId = n0
listenPort = 9000
  • namesrv-n1.conf
enableControllerInNamesrv = true







#controller config


controllerDLegerGroup = group1


enableElectUncleanMaster = true


controllerDLegerPeers = n0-127.0.0.1:9870;n1-127.0.0.1:9871;n2-127.0.0.1:9872


controllerDLegerSelfId = n1
listenPort = 9001
  • namesrv-n2.conf
enableControllerInNamesrv = true







#controller config


controllerDLegerGroup = group1


enableElectUncleanMaster = true


controllerDLegerPeers = n0-127.0.0.1:9870;n1-127.0.0.1:9871;n2-127.0.0.1:9872


controllerDLegerSelfId = n2
listenPort = 9002

idea启动参数

  • Program arguments
org.apache.rocketmq.namesrv.NamesrvStartup -c /Users/xiaozou/Desktop/sofe/java/rocketmq/distribution/conf/controller/local/namesrv-n0.conf

  • Envo
ROCKETMQ_HOME=/Users/xiaozou/Desktop/sofe/java/rocketmq/distribution






注意我们需要勾选允许启动多个实例

启动三个Nameserve

依次改用不同的启动参数启动三个nameserver

org.apache.rocketmq.namesrv.NamesrvStartup -c /Users/xiaozou/Desktop/sofe/java/rocketmq/distribution/conf/controller/local/namesrv-n0.conf

org.apache.rocketmq.namesrv.NamesrvStartup -c /Users/xiaozou/Desktop/sofe/java/rocketmq/distribution/conf/controller/local/namesrv-n1.conf

org.apache.rocketmq.namesrv.NamesrvStartup -c /Users/xiaozou/Desktop/sofe/java/rocketmq/distribution/conf/controller/local/namesrv-n2.conf

通过SyncStateSet查看集群状态

我们以源码方式运行MQAdminStartup

getControllerMetaData -a localhost:9870

运行结果如下

可以看到我们成功启动了3个节点的集群

broker+proxy 配置

这里本地要启动一主一从,proxy内置在broker中
先看看配置文件

  • broker-a-n0
brokerClusterName = xiaozou

brokerName = broker-a

brokerId = -1

brokerRole = SLAVE

deleteWhen = 04

fileReservedTime = 48

enableControllerMode = true



#fetchNamesrvAddrByAddressServer = true

#fetchControllerAddrByDnsLookup = true

controllerAddr = 127.0.0.1:9870;127.0.0.1:9871;127.0.0.1:9872

#namesrvAddr = 127.0.0.1:9000;127.0.0.1:9001;127.0.0.1:9002


allAckInSyncStateSet=true
listenPort=30911

storePathRootDir=/Users/xiaozou/Desktop/sofe/rocketmq-file/rmqstore/node00/store

autoCreateTopicEnable=false
autoCreateSubscriptionGroup=false
enablePropertyFilter=true
slaveReadEnable=true
waitTimeMillsInSendQueue=1000
  • rmq-proxy-n0.json
{

  "rocketMQClusterName": "xiaozou",

  "namesrvAddr": "127.0.0.1:9000;127.0.0.1:9001;127.0.0.1:9002",

  "grpcServerPort": 8081,
  "remotingListenPort": 8080

}

  • broker-a-n1
brokerClusterName = xiaozou

brokerName = broker-a

brokerId = -1

brokerRole = SLAVE

deleteWhen = 04

fileReservedTime = 48

enableControllerMode = true



#fetchNamesrvAddrByAddressServer = true

#fetchControllerAddrByDnsLookup = true

controllerAddr = 127.0.0.1:9870;127.0.0.1:9871;127.0.0.1:9872

#namesrvAddr = 127.0.0.1:9000;127.0.0.1:9001;127.0.0.1:9002

enableElectUncleanMaster = true

allAckInSyncStateSet=true
listenPort=30916

storePathRootDir=/Users/xiaozou/Desktop/sofe/rocketmq-file/rmqstore/node10/store

autoCreateTopicEnable=false
autoCreateSubscriptionGroup=false
enablePropertyFilter=true
slaveReadEnable=true
waitTimeMillsInSendQueue=1000
  • rmq-proxy-n1.json
{

  "rocketMQClusterName": "xiaozou",

  "namesrvAddr": "127.0.0.1:9000;127.0.0.1:9001;127.0.0.1:9002",

  "grpcServerPort": 8082,
  "remotingListenPort": 8083
}

启动 proxy+broker

  • Program arguments
org.apache.rocketmq.proxy.ProxyStartup

-bc

/Users/xiaozou/Desktop/sofe/java/rocketmq/distribution/conf/controller/local/broker-a-n0.conf
-pc

/Users/xiaozou/Desktop/sofe/java/rocketmq/distribution/conf/controller/local/rmq-proxy-n0.json
-pm

Local

  • Environment variables
ROCKETMQ_HOME=/Users/xiaozou/Desktop/sofe/java/rocketmq/distribution






第二个broker的配置

  • Program arguments
org.apache.rocketmq.proxy.ProxyStartup

-bc

/Users/xiaozou/Desktop/sofe/java/rocketmq/distribution/conf/controller/local/broker-a-n1.conf
-pc

/Users/xiaozou/Desktop/sofe/java/rocketmq/distribution/conf/controller/local/rmq-proxy-n1.json
-pm

Local

Environment variables 保持和之前一致

看到如下log就是我们启动成功了

启动 dashboard 查看集群

这里我们在本地启动一个dashboard

可以看到我们的broker是一主一从

我们新建一个topic试试

可以看到也是没问题的,至此我们的本地集群就搭建完成了

总结

我们本次以源码的方式启动了3个Nameserve+2个broker
其中还包含3个controller+2个proxy
后续我们需要debug观测RocketMQ集群的源代码就非常方便了

© 版权声明
THE END
喜欢就支持一下吧
点赞0

Warning: mysqli_query(): (HY000/3): Error writing file '/tmp/MYECUFUn' (Errcode: 28 - No space left on device) in /www/wwwroot/583.cn/wp-includes/class-wpdb.php on line 2345
admin的头像-五八三
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

图形验证码
取消
昵称代码图片