rocketmq 4.x 双主双从同步读写

文章标题写的是多M多S同步双写集群安装,但是看具体参数配置,写的是异步复制Master
brokerRole=ASYNC_MASTER
flushDiskType=SYNC_FLUSH

#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
brokerId      #0 表示 Master,>0 表示 Slave
brokerRole    #Broker 的角色
               #- ASYNC_MASTER 异步复制Master
               #- SYNC_MASTER 同步双写Master
               #- SLAVE
brokerIP1     #本机提供服务的IP地址   
补充一个配置:    slaveReadEnable=true  #建议开启,默认关闭

#Broker 对外服务的监听端口
listenPort=10911


brokerRole=SYNC_MASTER

#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH

改进的地方:
brokerRole=SYNC_MASTER(使用同步双写)
flushDiskType=SYNC_FLUSH(同步刷盘)
listenPort=10911(#Broker对外服务的监听端口)

Name Server使用端口:9876
broker使用端口:10911

采用的主机:

192.168.2.163 rocketmq-nameserver1
192.168.2.165 rocketmq-nameserver2
192.168.2.163 rocketmq-master1
192.168.2.164 rocketmq-master2
192.168.2.162 rocketmq-slave1
192.168.2.165 rocketmq-slave2

vim /etc/hosts

192.168.2.163  rocketmq-nameserver1
192.168.2.165  rocketmq-nameserver2
192.168.2.163  rocketmq-master1
192.168.2.164  rocketmq-master2
192.168.2.162  rocketmq-slave1
192.168.2.165  rocketmq-slave2
# 所有角色上安装
# 上传jdk-8u231-linux-x64.tar.gz 
# mkdir /opt/server -p
# tar zvxf jdk-8u231-linux-x64.tar.gz -C /opt/server

# vim /etc/profile.d/java.sh

#!/bin/bash

export JAVA_HOME=/opt/server/jdk1.8.0_231
export JRE_HOME=${JAVA_HOME}/jre  
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib  
export PATH=${JAVA_HOME}/bin:$PATH

# source /etc/profile.d/java.sh

# unzip rocketmq-all-4.7.1-bin-release.zip
# mv rocketmq-all-4.7.1-bin-release  /opt/server/rocketmq
#安装包bin下文件没有执行权限
# chmod +x /opt/server/rocketmq/bin/*

# 创建数据存储目录
# mkdir -p /opt/data/rocketmq/data/store/commitlog
# 创建日志目录
# mkdir -p /opt/var/logs/rocketmq/
# 修改日志目录
# cd /opt/server/rocketmq/conf 
# sed -i  's#${user.home}/logs#/opt/var/logs/rocketmq#g' *.xml
# 查看修改
# grep logs *.xml
# 主机内存大的话这个可以不用修改


# 所有节点修改JVM(JVM调优,内存不够时设置小点)
# vim /opt/server/rocketmq/bin/runserver.sh
,默认是4g 
JAVA_OPT=”JAVAOPT−server−Xms128m−Xmx256m−Xmn256m−XX:PermSize=128m−XX:MaxPermSize=320m”runbroker.sh
这个文件原来是这样的
JAVAOPT=”JAVAOPT−server−Xms128m−Xmx256m−Xmn256m−XX:PermSize=128m−XX:MaxPermSize=320m”runbroker.sh
这个文件原来是这样的JAVAOPT=”{JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g”

根据实际情况修改: 
JAVA_OPT=”${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m”

# vim /opt/server/rocketmq/conf/plain_acl.yml
globalWhiteRemoteAddresses:

accounts:
- accessKey: RocketMQ
  secretKey: 12345678
  whiteRemoteAddress:
  admin: false
  defaultTopicPerm: PUB|SUB
  defaultGroupPerm: PUB|SUB
  topicPerms:
  - test-topicA=PUB|SUB
  groupPerms:
  # the group should convert to retry topic
  - test-groupA=PUB|SUB
# 两台主机先做Name Server

# nohup /opt/server/rocketmq/bin/mqnamesrv &
# 验证
# cat nohup.out 
The Name Server boot success.
# netstat -anlp |grep 9876
tcp        0      0 :::9876                     :::*                        LISTEN      23750/java

# 开机启动

echo "nohup /opt/server/rocketmq/bin/mqnamesrv &" >> /etc/rc.local

# cat /etc/rc.local
# RocketMQ nameserver
nohup /opt/server/rocketmq/bin/mqnamesrv &

163主机操作

# vim /opt/server/rocketmq/conf/2m-2s-async/broker-a.properties
brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
brokerIP1=192.168.2.163
namesrvAddr=192.168.2.163:9876;192.168.2.165:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10911
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=50000000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88

storePathRootDir=/opt/data/rocketmq/data/store
storePathCommitLog=/opt/data/rocketmq/data/store/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000

checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128

brokerRole=ASYNC_MASTER
flushDiskType=SYNC_FLUSH

aclEnable=true
# 启动master1
# nohup /opt/server/rocketmq/bin/mqbroker -c /opt/server/rocketmq/conf/2m-2s-async/broker-a.properties &
# netstat -anlp|grep java         
tcp        0      0 :::10911                    :::*                        LISTEN      24220/java          
tcp        0      0 :::10912                    :::*                        LISTEN      24220/java

# 开机启动(nameserver必须为启动状态,建议手动启动)

echo "nohup /opt/server/rocketmq/bin/mqbroker -c /opt/server/rocketmq/conf/2m-2s-async/broker-a.properties &" >> /etc/rc.local

# cat /etc/rc.local
# RocketMQ master
nohup /opt/server/rocketmq/bin/mqbroker -c /opt/server/rocketmq/conf/2m-2s-async/broker-a.properties &

162主机操作

Broker-a Master Acl需要增加slave的白名单,重启Master (在192.168.2.163主机上操作)
# vim /opt/server/rocketmq/conf/plain_acl.yml
globalWhiteRemoteAddresses:
- 192.168.2.162


# 修改slave1(192.168.2.162)配置
# vim /opt/server/rocketmq/conf/2m-2s-async/broker-a.properties
brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=1
brokerIP1=192.168.2.162
namesrvAddr=192.168.2.163:9876;192.168.2.165:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10911
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=50000000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88

storePathRootDir=/opt/data/rocketmq/data/store
storePathCommitLog=/opt/data/rocketmq/data/store/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000

checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128

brokerRole=SLAVE
flushDiskType=SYNC_FLUSH

aclEnable=true

# 启动salve1
# nohup /opt/server/rocketmq/bin/mqbroker -c /opt/server/rocketmq/conf/2m-2s-async/broker-a.properties &

# netstat -anlp|grep java
tcp        0      0 :::10911                    :::*                        LISTEN      23774/java          
tcp        0      0 :::10912                    :::*                        LISTEN      23774/java

# 开机启动(nameserver必须为启动状态,建议手动启动)

echo "nohup /opt/server/rocketmq/bin/mqbroker -c /opt/server/rocketmq/conf/2m-2s-async/broker-a.properties &" >> /etc/rc.local

# cat /etc/rc.local
nohup /opt/server/rocketmq/bin/mqbroker -c /opt/server/rocketmq/conf/2m-2s-async/broker-a.properties &

165主机操作

# 修改master2(192.168.2.165)配置
# vim /opt/server/rocketmq/conf/2m-2s-async/broker-b.properties
brokerClusterName=DefaultCluster
brokerName=broker-b
brokerId=0
brokerIP1=192.168.2.165
namesrvAddr=192.168.2.163:9876;192.168.2.165:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10911
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=50000000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88

storePathRootDir=/opt/data/rocketmq/data/store
storePathCommitLog=/opt/data/rocketmq/data/store/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000

checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128

brokerRole=ASYNC_MASTER
flushDiskType=SYNC_FLUSH

aclEnable=true

# 启动master2
# nohup /opt/server/rocketmq/bin/mqbroker -c /opt/server/rocketmq/conf/2m-2s-async/broker-b.properties &

# 验证
# cat nohup.out 
The Name Server boot success.
load config properties file OK, /opt/server/rocketmq/conf/2m-2s-async/broker-a.properties
The broker[broker-a, 172.25.2.102:10911] boot success.
# netstat -anlp|grep java         
tcp        0      0 :::10911                    :::*                        LISTEN      24220/java          
tcp        0      0 :::10912                    :::*                        LISTEN      24220/java

# 开机启动(nameserver必须为启动状态,建议手动启动)
echo "nohup /opt/server/rocketmq/bin/mqbroker -c /opt/server/rocketmq/conf/2m-2s-async/broker-b.properties &" >> /etc/rc.local

# cat /etc/rc.local
nohup /opt/server/rocketmq/bin/mqbroker -c /opt/server/rocketmq/conf/2m-2s-async/broker-b.properties &

164主机操作

Brocker-b Master Acl需要增加slave的白名单,重启Master  (在192.168.2.165主机上操作)
# vim /opt/server/rocketmq/conf/plain_acl.yml
globalWhiteRemoteAddresses:
- 192.168.2.164


# 修改slave2(192.168.2.164)配置
# vim /opt/server/rocketmq/conf/2m-2s-async/broker-b.properties
brokerClusterName=DefaultCluster
brokerName=broker-b
brokerId=1
brokerIP1=192.168.2.164
namesrvAddr=192.168.2.163:9876;192.168.2.165:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10911
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=50000000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88

storePathRootDir=/opt/data/rocketmq/data/store
storePathCommitLog=/opt/data/rocketmq/data/store/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000

checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128

brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH

aclEnable=true

# 启动salve2
# nohup /opt/server/rocketmq/bin/mqbroker -c /opt/server/rocketmq/conf/2m-2s-async/broker-b.properties &

# 验证
# cat nohup.out 
load config properties file OK, /opt/server/rocketmq/conf/2m-2s-async/broker-b.properties
The broker[broker-b, 192.168.2.164:10911] boot success. and name server is 192.168.2.163:9876;192.168.2.165:9876
# netstat -anlp|grep java
tcp        0      0 :::10911                    :::*                        LISTEN      23774/java          
tcp        0      0 :::10912                    :::*                        LISTEN      23774/java

# 开机启动(nameserver必须为启动状态,建议手动启动)

echo "nohup /opt/server/rocketmq/bin/mqbroker -c /opt/server/rocketmq/conf/2m-2s-async/broker-b.properties &" >> /etc/rc.local

# cat /etc/rc.local
nohup /opt/server/rocketmq/bin/mqbroker -c /opt/server/rocketmq/conf/2m-2s-async/broker-b.properties &

注:服务停止直接采用kill java 进程的方法

RocketMQ Console部署

从github上克隆源码后,找到rocketmq-console,修改application.properties配置文件,具体修改内容如下:
1.
server.address=0.0.0.0
server.port=9999
2.
rocketmq.config.namesrvAddr=172.25.2.101:9876;172.25.2.102:987
3.
rocketmq.config.accessKey=RocketMQ
rocketmq.config.secretKey=12345678

修改logback.xml文件,
/opt/var/logs/consolelogs/

然后再编译打包(运行在163主机上)
nohup java -jar /opt/server/rocketmq-console/rocketmq-console-ng-2.0.0.jar >/dev/null &

访问地址:
http://192.168.2.163:9999

posted @ 2021-04-08 13:24  哈喽哈喽111111  阅读(397)  评论(0编辑  收藏  举报