rocketmq 同步双写

简介: 配置域名192.168.241.101 paascloud-rocketmq-001192.

配置域名

192.168.241.101 paascloud-rocketmq-001
192.168.241.102 paascloud-rocketmq-002

下载

wget http://ftp.jaist.ac.jp/pub/apache/rocketmq/4.2.0/rocketmq-all-4.2.0-bin-release.zip
scp rocketmq-all-4.2.0-bin-release.zip root@192.168.241.101:/root

解压

unzip rocketmq-all-4.2.0-bin-release.zip -d /usr/local/rocketmq

配置环境变量

vim /etc/profile
export ROCKETMQ_HOME=/usr/local/rocketmq
export PATH=$PATH::$ROCKETMQ_HOME/bin
# source /etc/profile

修改配置

broker-a.properties

brokerClusterName=paascloud-rocketmq-cluster
brokerName=broker-a
brokerId=0
namesrvAddr=paascloud-rocketmq-001:9876;paascloud-rocketmq-002:9876;
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10911
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88
storePathRootDir=/usr/local/rocketmq/data/master/store
storePathCommitLog=/usr/local/rocketmq/data/master/store/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
brokerRole=SYNC_MASTER
flushDiskType=SYNC_FLUSH

broker-a-s.properties

brokerClusterName=paascloud-rocketmq-cluster
brokerName=broker-a
brokerId=1
namesrvAddr=paascloud-rocketmq-001:9876;paascloud-rocketmq-002:9876;
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10921
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88
storePathRootDir=/usr/local/rocketmq/data/slave/store
storePathCommitLog=/usr/local/rocketmq/data/slave/store/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
brokerRole=SLAVE
flushDiskType=SYNC_FLUSH

broker-b.properties

brokerClusterName=paascloud-rocketmq-cluster
brokerName=broker-b
brokerId=0
namesrvAddr=paascloud-rocketmq-001:9876;paascloud-rocketmq-002:9876;
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10911
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88
storePathRootDir=/usr/local/rocketmq/data/master/store
storePathCommitLog=/usr/local/rocketmq/data/master/store/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
brokerRole=SYNC_MASTER
flushDiskType=SYNC_FLUSH

broker-b-s.properties

brokerClusterName=paascloud-rocketmq-cluster
brokerName=broker-b
brokerId=1
namesrvAddr=paascloud-rocketmq-001:9876;paascloud-rocketmq-002:9876;
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10921
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88
storePathRootDir=/usr/local/rocketmq/data/slave/store
storePathCommitLog=/usr/local/rocketmq/data/slave/store/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
brokerRole=SLAVE
flushDiskType=SYNC_FLUSH

创建存储&日志文件

# mkdir -p /usr/local/rocketmq/data/master/store/commitlog
# mkdir -p /usr/local/rocketmq/data/slave/store/commitlog
# mkdir -p /usr/local/rocketmq/data/master/store/consumequeue
# mkdir -p /usr/local/rocketmq/data/slave/store/consumequeue
# mkdir -p /usr/local/rocketmq/data/master/store/index
# mkdir -p /usr/local/rocketmq/data/slave/store/index
# mkdir -p /usr/local/rocketmq/logs

修改日志配置文件

cd /usr/local/rocketmq/conf && sed -i 's#${user.home}#/usr/local/rocketmq#g' *.xml

修改启动脚本参数

vim /usr/local/rocketmq/bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m"
vim /usr/local/rocketmq/bin/runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

启动服务

  1. 启动NameServer A 192.168.241.101
 nohup sh /usr/local/rocketmq/bin/mqnamesrv &
  1. 启动NameServer A 192.168.241.101
 nohup sh /usr/local/rocketmq/bin/mqnamesrv &
  1. 启动BrokerServer A-master 192.168.241.101
nohup sh mqbroker -c /usr/local/rocketmq/conf/2m-2s-sync/broker-a.properties&
  1. 启动BrokerServer A-slave 192.168.241.101
nohup sh mqbroker -c /usr/local/rocketmq/conf/2m-2s-sync/broker-a-s.properties&
  1. 启动BrokerServer B-master 192.168.241.102
nohup sh mqbroker -c /usr/local/rocketmq/conf/2m-noslave/broker-b.properties&
  1. 启动BrokerServer B-slave 192.168.241.102
nohup sh mqbroker -c /usr/local/rocketmq/conf/2m-noslave/broker-b-s.properties&

是否启动成功

这里写图片描述

# netstat -ntlp
# jps
# tail -f -n 500 /usr/local/rocketmq/logs/rocketmqlogs/broker.log
# tail -f -n 500 /usr/local/rocketmq/logs/rocketmqlogs/namesrv.log

查看集群监控状态

# sh /usr/local/rocketmq/bin/mqadmin clusterlist -n 192.168.241.101:9876

这里写图片描述

停止服务

# sh /usr/local/rocketmq/bin/mqshutdown namesrv
# sh /usr/local/rocketmq/bin/mqshutdown broker

清理数据

# rm -rf /usr/local/rocketmq/data/master
# rm -rf /usr/local/rocketmq/data/slave
# mkdir -p /usr/local/rocketmq/data/master/store/commitlog
# mkdir -p /usr/local/rocketmq/data/slave/store/commitlog
# mkdir -p /usr/local/rocketmq/data/master/store/consumequeue
# mkdir -p /usr/local/rocketmq/data/slave/store/consumequeue
# mkdir -p /usr/local/rocketmq/data/master/store/index
# mkdir -p /usr/local/rocketmq/data/slave/store/index

rocketmq-console-ng

rocketmq-console-ng.bat

@echo off  
java -jar rocketmq-console-ng-1.0.0.jar --server.port=12581 --rocketmq.config.namesrvAddr=192.168.241.101:9876;192.168.241.102:9876;  
@pause

效果图
这里写图片描述

参考文章

https://www.jianshu.com/p/9d4e0ff358c6

相关实践学习
消息队列RocketMQ版:基础消息收发功能体验
本实验场景介绍消息队列RocketMQ版的基础消息收发功能,涵盖实例创建、Topic、Group资源创建以及消息收发体验等基础功能模块。
消息队列 MNS 入门课程
1、消息队列MNS简介 本节课介绍消息队列的MNS的基础概念 2、消息队列MNS特性 本节课介绍消息队列的MNS的主要特性 3、MNS的最佳实践及场景应用 本节课介绍消息队列的MNS的最佳实践及场景应用案例 4、手把手系列:消息队列MNS实操讲 本节课介绍消息队列的MNS的实际操作演示 5、动手实验:基于MNS,0基础轻松构建 Web Client 本节课带您一起基于MNS,0基础轻松构建 Web Client
目录
相关文章
|
1月前
|
消息中间件 监控 Java
RocketMQ 同步发送、异步发送和单向发送,如何选择?
本文详细分析了 RocketMQ 中同步发送、异步发送和单向发送三种消息发送方式的原理、优缺点及适用场景。同步发送可靠性高但延迟较大,适合订单系统等场景;异步发送非阻塞且延迟低,适用于实时数据处理等场景;单向发送高效但可靠性低,适用于日志收集等场景。文章还提供了示例代码和核心源码分析,帮助读者更好地理解每种发送方式的特点。
188 4
|
28天前
|
存储 消息中间件 安全
JUC组件实战:实现RRPC(Java与硬件通过MQTT的同步通信)
【10月更文挑战第9天】本文介绍了如何利用JUC组件实现Java服务与硬件通过MQTT的同步通信(RRPC)。通过模拟MQTT通信流程,使用`LinkedBlockingQueue`作为消息队列,详细讲解了消息发送、接收及响应的同步处理机制,包括任务超时处理和内存泄漏的预防措施。文中还提供了具体的类设计和方法实现,帮助理解同步通信的内部工作原理。
JUC组件实战:实现RRPC(Java与硬件通过MQTT的同步通信)
|
4月前
|
消息中间件 传感器 负载均衡
消息队列 MQ使用问题之如何配置一主一从的同步复制模式
消息队列(MQ)是一种用于异步通信和解耦的应用程序间消息传递的服务,广泛应用于分布式系统中。针对不同的MQ产品,如阿里云的RocketMQ、RabbitMQ等,它们在实现上述场景时可能会有不同的特性和优势,比如RocketMQ强调高吞吐量、低延迟和高可用性,适合大规模分布式系统;而RabbitMQ则以其灵活的路由规则和丰富的协议支持受到青睐。下面是一些常见的消息队列MQ产品的使用场景合集,这些场景涵盖了多种行业和业务需求。
消息队列 MQ使用问题之如何配置一主一从的同步复制模式
|
4月前
|
消息中间件 运维 RocketMQ
MetaQ/RocketMQ 原理问题之slave broker是从master同步信息的问题如何解决
MetaQ/RocketMQ 原理问题之slave broker是从master同步信息的问题如何解决
|
5月前
|
消息中间件 存储 Java
后端开发Spring框架之消息介绍 同步异步 JMS AMQP MQTT Kafka介绍
后端开发Spring框架之消息介绍 同步异步 JMS AMQP MQTT Kafka介绍
39 0
|
数据库
淘东电商项目(43) -MQ与Logstash实现数据库同步到ES的区别
淘东电商项目(43) -MQ与Logstash实现数据库同步到ES的区别
112 0
|
NoSQL 关系型数据库 MySQL
同步 MySQL 数据至 ES/Redis/MQ 等的五种方式
同步 MySQL 数据至 ES/Redis/MQ 等的五种方式
559 0
|
canal SQL 关系型数据库
10.【canal】canal从入门到放弃-mysql+canal+rocketmq实现数据库同步-canal简单使用
【canal】canal从入门到放弃-mysql+canal+rocketmq实现数据库同步-canal简单使用
10.【canal】canal从入门到放弃-mysql+canal+rocketmq实现数据库同步-canal简单使用
|
canal 关系型数据库 MySQL
9.【canal】canal从入门到放弃-mysql+canal+rocketmq实现数据库同步-canal安装
canal从入门到放弃-mysql+canal+rocketmq实现数据库同步-canal安装
9.【canal】canal从入门到放弃-mysql+canal+rocketmq实现数据库同步-canal安装
|
canal 消息中间件 关系型数据库
8.【canal】canal从入门到放弃-mysql+canal+rocketmq实现数据库同步-mysql安装
canal从入门到放弃-mysql+canal+rocketmq实现数据库同步-mysql安装
8.【canal】canal从入门到放弃-mysql+canal+rocketmq实现数据库同步-mysql安装