RocketMQ4.7.1双主双从集群搭建
导读
上一集我们已经学会了SpringBoot整合RocketMQ点我直达,今天我们来搭建双主双从高性能MQ服务集群。
简介
主从架构
Broker角色,Master提供读写,Slave只支持读,Consumer不用配置,当Master不可用或者繁忙的时候,Consumer会自动切换到Slave节点进行读取。双主双从,同步复制,异步刷盘。
集群配置(4台机器)
- 两台部署Broker-Master和NameServer
- 两台部署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(从)
搭建
安装依赖项
上传相应文件及安装目录
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