码迷,mamicode.com
首页 > 其他好文 > 详细

RocketMQ 2主2从 集群搭建

时间:2018-08-15 13:05:58      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:脚本参数   nbsp   注意   sync   1.7   commit   消费   shel   虚拟   

安装环境

   jdk1.7 

  alibaba-rocketmq-3.2.6.tar.gz

  VM虚拟机redhat6.5-x64:192.168.1.201  192.168.1.202 192.168.1.203  192.168.1.204

  Xshell4

部署方案

IP

主机名

用途

Broker角色

192.168.1.201

broker-a

NameServer,Broker

Master

192.168.1.202

broker-b

NameServer, Broker

Master

192.168.1.203

broker-a-s

NameServer, Broker

Slave

192.168.1.204

broker-b-s

NameServer, Broker

Slave

安装步骤:【两台机器同样操作  以201为例】

步骤一:解压安装文件alibaba-rocketmq-3.2.6.tar.gz

[root@201 rocketmq]# tar -zxvf alibaba-rocketmq-3.2.6.tar.gz -C /usr/local
[root@201 rocketmq]# mv alibaba-rocketmq rocketmq

步骤二:修改配置

  配置一:创建存储路径 用于存储队列 索引 提交日志等信息

[root@201 rocketmq]# mkdir -p /usr/local/rocketmq/store
[root@201 rocketmq]# mkdir -p /usr/local/rocketmq/store/commitlog
[root@201 rocketmq]# mkdir -p /usr/local/rocketmq/store/consumequeue
[root@201 rocketmq]# mkdir -p /usr/local/rocketmq/store/index

配置二:Hosts添加信息

192.168.1.201 rocketmq-nameserver1
192.168.1.202 rocketmq-nameserver2
192.168.1.203 rocketmq-nameserver3
192.168.1.204 rocketmq-nameserver4
192.168.1.201 rocketmq-master1
192.168.1.202 rocketmq-master2
192.168.1.203 rocketmq-slave1
192.168.1.204 rocketmq-slave2

重启网卡:service network restart

相互ping一下,在201机器上ping 192.168.1.202   ping  rocketmq-nameserver2   ping  rocketmq-master2 。 202 203 204机器上也一样。

配置三:RocketMQ配置文件:

同步双写,配置目录:2m-2s-async

异步刷盘,配置目录:2m-2s-sync

 

#201
vim /usr/local/rocketmq/conf/2m-2s-sync/broker-a.properties
#202
vim /usr/local/rocketmq/conf/2m-2s-sync/broker-b.properties
#203
vim /usr/local/rocketmq/conf/2m-2s-sync/broker-a-s.properties
#204
vim /usr/local/rocketmq/conf/2m-2s-sync/broker-b-s.properties
#所属集群名字
brokerClusterName=rocketmq-cluster
#broker名字  broker-a.properties填broker-a  broker-b.properties填broker-b
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=rocketmq-nameserver1:9876 rocketmq-nameserver2:9876 rocketmq-nameserver3:9876 rocketmq-nameserver4:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口
listenPort=10911
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/usr/local/rocketmq/store
#commitLog 存储路径
storePathCommitLog=/usr/local/rocketmq/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/usr/local/rocketmq/store/consumequeue
#消息索引存储路径
storePathIndex=/usr/local/rocketmq/store/index
#checkpoint 文件存储路径
storeCheckpoint=/usr/local/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/usr/local/rocketmq/store/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER  异步复制Master
#- SYNC_MASTER  同步双写Master
#- SLAVE
brokerRole=SYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH  异步刷盘
#- SYNC_FLUSH  同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128
注意:
brokerName:
201 broker-a
202 broker-b
203 broker-a-s
204 broker-b-s
brokerId
201 202 是master 配置brokerId=0
203 204 是slave  配置brokerId=1

brokerRole
201 202是master 配置 brokerRole=SYNC_MASTER
203 204是slave配置 brokerRole=SLAVE
配置四:修改日志配置文件
[root@201 conf]# mkdir -p /usr/local/rocketmq/logs
[root@201 conf]# cd /usr/local/rocketmq/conf && sed -i s#${user.home}#/usr/local/rocketmq#g *.xml

配置五:修改启动脚本参数 Xms和Xmx至少是1G  否则启动不起来  Xmn一般是前者的一半

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

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

步骤三:启动:先启动两台机器的NameServer,再启动两台机器的Borker,关机的时候顺序相反,先关闭两台机器的Broker,再关闭两台机器的Nameserver。在启动 BrokerServer 之前先关闭防火墙.

启动一:NameServer  201 202 203 204
cd /usr/local/rocketmq/bin
nohup sh mqnamesrv &
#查看进程
jps
#查看日志
tail -f -n 500 /usr/local/rocketmq/logs/rocketmqlogs/namesrv.log

#启动二:BrokerServer A 192.168.1.201 
cd /usr/local/rocketmq/bin 
nohup sh mqbroker -c /usr/local/rocketmq/conf/2m-noslave/broker-a.properties >/dev/null 2>&1 & 
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 

#启动三:BrokerServer B 192.168.1.202 
cd /usr/local/rocketmq/bin 
nohup sh mqbroker -c /usr/local/rocketmq/conf/2m-noslave/broker-b.properties >/dev/null 2>&1 & 
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

#启动四:BrokerServer B 192.168.1.203 
cd /usr/local/rocketmq/bin 
nohup sh mqbroker -c /usr/local/rocketmq/conf/2m-noslave/broker-a-s.properties >/dev/null 2>&1 & 
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

#启动五:BrokerServer B 192.168.1.204 
cd /usr/local/rocketmq/bin 
nohup sh mqbroker -c /usr/local/rocketmq/conf/2m-noslave/broker-b-s.properties >/dev/null 2>&1 & 
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

 


 

RocketMQ 2主2从 集群搭建

标签:脚本参数   nbsp   注意   sync   1.7   commit   消费   shel   虚拟   

原文地址:https://www.cnblogs.com/cac2020/p/9480430.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!