RocketMq双主双从的安装

1.原理图
2.安装步骤RocketMq双主双从的安装_第1张图片
  (1) 下载
    Apache:
         https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.2.0/rocketmq-all-4.2.0-bin-release.zip
    Alibba:
         https://github.com/alibaba/RocketMQ/releases

  (2) 解压
         unzip rocketmq-all-4.2.0-bin-release.zip -d /software/rocketmq

   (3) 配置hosts(给namesrv用)        
         vim /etc/hosts        
         添加如下内容        
         192.168.240.167 rocketmq1        
         192.168.240.168 rocketmq2 

  (4)  配置环境变量       
         vim /etc/profile        
         添加如下内容        
         export ROCKETMQ_HOME=/root/svr/rocketmq        
         export PATH=$PATH::$ROCKETMQ_HOME/bin        
         执行变更        
         source /etc/profile 

(5)配置2m-2s-sync
        vim /software/rocketmq/conf/2m-2s-sync/broker-a.properties(master)           
        修改内容如下       
           brokerClusterName=tl-rocketmq-cluster
           brokerName=broker-a
           brokerId=0
           namesrvAddr=rocketmq1:9876;rocketmq2:9876
           defaultTopicQueueNums=4
           autoCreateTopicEnable=true
           autoCreateSubscriptionGroup=true
           listenPort=10911
           deleteWhen=04
           fileReservedTime=120
           mapedFileSizeCommitLog=1073741824
           mapedFileSizeConsumeQueue=300000
           destroyMapedFileIntervalForcibly=120000
           redeleteHangedFileInterval=120000
           diskMaxUsedSpaceRatio=88
           storePathRootDir=/software/rocketmq/data/store/master/
           storePathCommitLog=/root/svr/rocketmq/data/store/master/commitlog
           maxMessageSize=65536
           flushCommitLogLeastPages=4
           flushConsumeQueueLeastPages=2
           flushCommitLogThoroughInterval=10000
           flushConsumeQueueThoroughInterval=60000
           checkTransactionMessageEnable=false
           sendMessageThreadPoolNums=128
           pullMessageThreadPoolNums=128
           brokerRole=SYNC_MASTER
           flushDiskType=SYNC_FLUSH
 
           vim /software/rocketmq/conf/2m-2s-sync/broker-b-s.properties(salve)
           修改如下配置
           brokerClusterName=tl-rocketmq-cluster
           brokerName=broker-b
           brokerId=1
           namesrvAddr=rocketmq1:9876;rocketmq2:9876
           defaultTopicQueueNums=4
           autoCreateTopicEnable=true
           autoCreateSubscriptionGroup=true
           listenPort=10921
           deleteWhen=04
           fileReservedTime=120
           mapedFileSizeCommitLog=1073741824
           mapedFileSizeConsumeQueue=300000
           destroyMapedFileIntervalForcibly=120000
           redeleteHangedFileInterval=120000
           diskMaxUsedSpaceRatio=88
           storePathRootDir=/software/rocketmq/data/store/slave/
           storePathCommitLog=/root/svr/rocketmq/data/store/slave/commitlog
           maxMessageSize=65536
           flushCommitLogLeastPages=4
           flushConsumeQueueLeastPages=2
           flushCommitLogThoroughInterval=10000
           flushConsumeQueueThoroughInterval=60000
           checkTransactionMessageEnable=false
           sendMessageThreadPoolNums=128
           pullMessageThreadPoolNums=128
           brokerRole=SLAVE
           flushDiskType=SYNC_FLUSH
   同理修改另一台服务上的broker-a-s.properties,broker-b.properties

(6).创建存储&日志文件  
 mkdir /software/rocketmq/data mkdir /software/rocketmq/data/store/commitlog mkdir /software/rocketmq/data/store/consumequeue mkdir /software/rocketmq/data/store/index mkdir /software/logs cd /software/rocketmq/conf&&sed -i 's#${user.home}#/software/rocketmq#g' *.xml
(7) 启动     
cd /software/rocketmq/bin目录下执行命令 sh mqnamesrv & sh mqbroker -c /software/rocketmq/conf/2m-2s-sync/broker-a.properties& sh mqbroker -c /software/rocketmq/conf/2m-2s-sync/broker-b-s.properties
(8) 测试
jps 
RocketMq双主双从的安装_第2张图片
 sh mqadmin clusterlist -n 192.168.240.167:9876
 export NAMESRV_ADDR='rocketmq1:9876;rocketmq2:9876'
测试发送端
 sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
测试消费端
 sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer

(9)  停止
sh mqshutdown broker
sh mqshutdown namesrv

(10) 问题(虚拟机下面启动需要修改如下文件)
runbroker.sh,runserver.sh下面修改(具体的数值自行调整)
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m"

你可能感兴趣的:(第三方必备环境搭建)