1.安裝JDKjava
須要先卸載系統默認的OPENJDK,安裝 JDK1.8 64位的版本。node
卸載open-jdklinux
rpm -qa|grep java架構
查到open jdk的安裝。異步
使用命令async
rpm -e --nodeps ***spa
卸載。code
安裝 jdk1.8 server
tar -zxvf jdk-8u191-linux-x64.tar.gz 解壓JDKblog
編輯
/etc/profile
在最後增長配置
export JAVA_HOME=/work/jdk1.8.0_191
export PATH=$JAVA_HOME/bin:$PATH
rocketmq 集羣搭建
1.部署架構
咱們有兩臺節點
IP爲 10.87.134.74,10.87.134.75,兩臺機器均運行NAMESERVER.
在74 上部署BROKER A MASTER,BROKER B SLAVE
在75 上部署BROKER A SLAVE,BROKER B MASTER
2.修改內存配置
在默認狀況下 rocketmq 配置運行內存比較大,若是機器內存不夠能夠作些調整。
編輯 bin 目錄下的runbroker.sh文件
JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -Xmn1g"
編輯 bin 目錄下的 runserver.sh 文件
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
3.準備集羣配置文件
咱們安裝的主從異步模式
程序解壓後在conf 有以下的配置文件
編輯節點74 的配置文件
編輯broker-a.properties 內容:
brokerClusterName=DefaultCluster brokerName=broker-a brokerId=0 deleteWhen=04 fileReservedTime=48 brokerRole=ASYNC_MASTER flushDiskType=ASYNC_FLUSH listenPort=6001 autoCreateTopicEnable=true namesrvAddr=10.87.134.74:9876;10.87.134.75:9876 storePathRootDir=/work/rocketmq-4.5.1/store/broker-a storePathCommitLog=/work/rocketmq-4.5.1/store/broker-a/commitlog storePathConsumeQueue=/work/rocketmq-4.5.1/store/broker-a/consumequeue storePathIndex=/work/rocketmq-4.5.1/store/broker-a/index storeCheckpoint=/work/rocketmq-4.5.1/store/broker-a/checkpoint abortFile=/work/rocketmq-4.5.1/store/broker-a/abort
編輯broker-b-s.properties 文件內容
brokerClusterName=DefaultCluster brokerName=broker-b brokerId=1 deleteWhen=04 fileReservedTime=48 brokerRole=SLAVE flushDiskType=ASYNC_FLUSH listenPort=7001 autoCreateTopicEnable=true namesrvAddr=10.87.134.74:9876;10.87.134.75:9876 storePathRootDir=/work/rocketmq-4.5.1/store/broker-b storePathCommitLog=/work/rocketmq-4.5.1/store/broker-b/commitlog storePathConsumeQueue=/work/rocketmq-4.5.1/store/broker-b/consumequeue storePathIndex=/work/rocketmq-4.5.1/store/broker-b/index storeCheckpoint=/work/rocketmq-4.5.1/store/broker-b/checkpoint abortFile=/work/rocketmq-4.5.1/store/broker-b/abort
編輯75 配置文件
編輯 broker-b.properties 文件
terName=DefaultCluster brokerName=broker-b brokerId=0 deleteWhen=04 fileReservedTime=48 brokerRole=ASYNC_MASTER flushDiskType=ASYNC_FLUSH listenPort=7001 autoCreateTopicEnable=true namesrvAddr=10.87.134.74:9876;10.87.134.75:9876 storePathRootDir=/work/rocketmq-4.5.1/store/broker-b storePathCommitLog=/work/rocketmq-4.5.1/store/broker-b/commitlog storePathConsumeQueue=/work/rocketmq-4.5.1/store/broker-b/consumequeue storePathIndex=/work/rocketmq-4.5.1/store/broker-b/index storeCheckpoint=/work/rocketmq-4.5.1/store/broker-b/checkpoint abortFile=/work/rocketmq-4.5.1/store/broker-b/abort
編輯 broker-a-s.properties 文件
brokerClusterName=DefaultCluster brokerName=broker-a brokerId=1 deleteWhen=04 fileReservedTime=48 brokerRole=SLAVE flushDiskType=ASYNC_FLUSH listenPort=6001 autoCreateTopicEnable=true namesrvAddr=10.87.134.74:9876;10.87.134.75:9876 storePathRootDir=/work/rocketmq-4.5.1/store/broker-a storePathCommitLog=/work/rocketmq-4.5.1/store/broker-a/commitlog storePathConsumeQueue=/work/rocketmq-4.5.1/store/broker-a/consumequeue storePathIndex=/work/rocketmq-4.5.1/store/broker-a/index storeCheckpoint=/work/rocketmq-4.5.1/store/broker-a/checkpoint abortFile=/work/rocketmq-4.5.1/store/broker-a/abort
listenPort:是broker 對外監聽的端口。
咱們須要建立如下的目錄:
store/broker-a
store/broker-a/commitlog
store/broker-a/consumequeue
store/broker-a/index 目錄
在兩個節點上分別建立 broker-a,broker-b的目錄。
4.啓動rocketmq ,並檢查是否正確。
1.啓動nameserver
在兩個節點上分別執行:
nohup sh /work/rocketmq-4.5.1/bin/mqnamesrv >/work/rocketmq-4.5.1/logs/mqnamesrv.log 2>&1 &
2.按照下面的順序執行
1.啓動broker-a (節點1)
nohup sh /work/rocketmq-4.5.1/bin/mqbroker -c /work/rocketmq-4.5.1/conf/2m2sasync/broker-a.properties > /work/rocketmq-4.5.1/logs/broker-a.log 2>&1 &
2.啓動broker-a-s (節點2)
nohup sh /work/rocketmq-4.5.1/bin/mqbroker -c /work/rocketmq-4.5.1/conf/2m2sasync/broker-a-s.properties > /work/rocketmq-4.5.1/logs/broker-a-s.log 2>&1 &
3.啓動broker-b (節點2)
nohup sh /work/rocketmq-4.5.1/bin/mqbroker -c /work/rocketmq-4.5.1/conf/2m2sasync/broker-b.properties > /work/rocketmq-4.5.1/logs/broker-b.log 2>&1 &
4.啓動broker-b-s (節點1)
nohup sh /work/rocketmq-4.5.1/bin/mqbroker -c /work/rocketmq-4.5.1/conf/2m2sasync/broker-b-s.properties > /work/rocketmq-4.5.1/logs/broker-b-s.log 2>&1 &
3. 查看節點配置是否正確
執行命令 ./bin/mqadmin clusterList -n 10.87.134.75:9876
出現4個這樣的配置說明,大功告成了。
5.注意事項
故障1
在啓動 broker 時報以下錯誤。
ERROR: Please set the JAVA_HOME variable in your environment, We need java(x64)! !!
解決辦法:
註釋上面三行,增長 JAVA_HOME便可。