RocketMQ4.7.1雙主雙從叢集搭建

陳彥斌發表於2020-10-30

導讀

  上一集我們已經學會了SpringBoot整合RocketMQ點我直達,今天我們來搭建雙主雙從高效能MQ服務叢集。

簡介

主從架構

  Broker角色,Master提供讀寫,Slave只支援讀,Consumer不用配置,當Master不可用或者繁忙的時候,Consumer會自動切換到Slave節點進行讀取。雙主雙從,同步複製,非同步刷盤

叢集配置(4臺機器)

  1. 兩臺部署Broker-Master和NameServer
  2. 兩臺部署Broker-Slave和NameServer

前置條件

  • Maven
  • Git
  • Jdk1.8
  • RocketMQ 4.7.1
  • 4臺機器,ip分別為如下
    • 192.168.199.110()
    • 192.168.199.120()
    • 192.168.199.130()
    • 192.168.199.140()

搭建

安裝依賴項

  1. jdk:點我直達
  2. maven:點我直達
  3. git安裝:yum install -y git

 

上傳相應檔案及安裝目錄

 

maven編譯

cd /opt/soft/rocketmq-all-4.7.1-source-release


mvn -Prelease-all -DskipTests clean install -U

修改啟動記憶體大小

  因為是本地搭建的4臺虛擬機器,只分配的1G,不把啟動記憶體設定小點,服務跑不起來~

修改,110、130

切換
cd /opt/soft/rocketmq-all-4.7.1-source-release/distribution/target/rocketmq-4.7.1/rocketmq-4.7.1/bin


編輯
vim runserver.sh 



修改引數
原始:
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

修改為:
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

修改,110、120、130、140

切換
cd /opt/soft/rocketmq-all-4.7.1-source-release/distribution/target/rocketmq-4.7.1/rocketmq-4.7.1/bin

編輯
vim runbroker.sh

修改
原始值:
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"

修改為:
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m"

啟動,110,130

切換
cd /opt/soft/rocketmq-all-4.7.1-source-release/distribution/target/rocketmq-4.7.1/rocketmq-4.7.1

守護程式啟動
nohup sh bin/mqnamesrv &

使用:jps,檢視是否啟動成功

192.168.199.110(broker-a,部署nameServer,主)

切換
cd /opt/soft/rocketmq-all-4.7.1-source-release/distribution/target/rocketmq-4.7.1/rocketmq-4.7.1/conf/2m-2s-sync

編輯
vim broker-a.properties

修改為如下配置
namesrvAddr=192.168.199.110:9876;192.168.199.130:9876
brokerClusterName=ybchenCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
切換
cd /opt/soft/rocketmq-all-4.7.1-source-release/distribution/target/rocketmq-4.7.1/rocketmq-4.7.1

守護程式啟動
nohup sh bin/mqbroker -c conf/2m-2s-sync/broker-a.properties &

 

192.168.199.120(broker-b,主)

切換
cd /opt/soft/rocketmq-all-4.7.1-source-release/distribution/target/rocketmq-4.7.1/rocketmq-4.7.1/conf/2m-2s-sync

編輯
vim broker-b.properties

修改為如下配置
namesrvAddr=192.168.199.110:9876;192.168.199.130:9876
brokerClusterName=ybchenCluster
brokerName=broker-b
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
切換
cd /opt/soft/rocketmq-all-4.7.1-source-release/distribution/target/rocketmq-4.7.1/rocketmq-4.7.1

守護程式啟動
nohup sh bin/mqbroker -c conf/2m-2s-sync/broker-b.properties &

 

192.168.199.130(broker-a-s,部署nameServer,從)

切換
cd /opt/soft/rocketmq-all-4.7.1-source-release/distribution/target/rocketmq-4.7.1/rocketmq-4.7.1/conf/2m-2s-sync

編輯
vim broker-a-s.properties

修改為如下配置
namesrvAddr=192.168.199.110:9876;192.168.199.130:9876
brokerClusterName=ybchenCluster
brokerName=broker-a
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
切換
cd /opt/soft/rocketmq-all-4.7.1-source-release/distribution/target/rocketmq-4.7.1/rocketmq-4.7.1

守護程式啟動
nohup sh bin/mqbroker -c conf/2m-2s-sync/broker-a-s.properties &

 

192.168.199.140(broker-b-s,從)

切換
cd /opt/soft/rocketmq-all-4.7.1-source-release/distribution/target/rocketmq-4.7.1/rocketmq-4.7.1/conf/2m-2s-sync

編輯
vim broker-b-s.properties

修改為如下配置namesrvAddr=192.168.199.110:9876;192.168.199.130:9876
brokerClusterName=ybchenCluster
brokerName=broker-b
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
切換
cd /opt/soft/rocketmq-all-4.7.1-source-release/distribution/target/rocketmq-4.7.1/rocketmq-4.7.1

守護程式啟動
nohup sh bin/mqbroker -c conf/2m-2s-sync/broker-b-s.properties &

 

檢視啟動

  做這幾張圖太難了,製作成gif,花了半小時~~以下內容都是連續滴

雙主雙從控制檯配置

192.168.199.110

  在這臺機器上操作,修改配置檔案,並啟動

切換
cd /opt/soft/rocketmq-externals-master/rocketmq-console/src/main/resources


編輯
vim application.properties 

修改為如下配置,指定:rocketmq.config.namesrvAddr
------------------分隔符開始----------------------------------
server.address=0.0.0.0
server.port=8080

### SSL setting
#server.ssl.key-store=classpath:rmqcngkeystore.jks
#server.ssl.key-store-password=rocketmq
#server.ssl.keyStoreType=PKCS12
#server.ssl.keyAlias=rmqcngkey

#spring.application.index=true
spring.application.name=rocketmq-console
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
logging.level.root=INFO
logging.config=classpath:logback.xml
#if this value is empty,use env value rocketmq.config.namesrvAddr  NAMESRV_ADDR | now, you can set it in ops page.default localhost:9876
rocketmq.config.namesrvAddr=192.168.199.110:9876;192.168.199.130:9876
#if you use rocketmq version < 3.5.8, rocketmq.config.isVIPChannel should be false.default true
rocketmq.config.isVIPChannel=
#rocketmq-console's data path:dashboard/monitor
rocketmq.config.dataPath=/tmp/rocketmq-console/data
#set it false if you don't want use dashboard.default true
rocketmq.config.enableDashBoardCollect=true
#set the message track trace topic if you don't want use the default one
rocketmq.config.msgTrackTopicName=
rocketmq.config.ticketKey=ticket

#Must create userInfo file: ${rocketmq.config.dataPath}/users.properties if the login is required
rocketmq.config.loginRequired=false
-----------------分隔符結束-----------------------------------


切換
cd /opt/soft/rocketmq-externals-master/rocketmq-console


maven構建專案
mvn install -Dmaven.test.skip=true


切換
cd /opt/soft/rocketmq-externals-master/rocketmq-console/target


守護程式啟動
nohup java -jar rocketmq-console-ng-2.0.0.jar &

訪問控制檯

安裝包下載

連結: https://pan.baidu.com/s/1s--VdU-jZvCbS9jHvpHoIA  密碼: eq11

 

相關文章