RocketMQ4.7.1雙主雙從集羣搭建

導讀

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

簡介

主從架構

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

集羣配置(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,不把啓動內存設置小點,服務跑不起來~git

修改,1十、130spring

切換
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"

修改,1十、120、130、140vim

切換
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,花了半小時~~如下內容都是連續滴app

雙主雙從控制檯配置

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
相關文章
相關標籤/搜索