首页 > 代码库 > 双RocketMq集群的搭建
双RocketMq集群的搭建
一、双Master RocketMq集群的搭建
1、服务器环境:
序号 | IP | 用户名 | 角色 | 模式 |
1 | 192.168.211.128 | root | nameServer1,brokerServer1 | Master1 |
2 | 192.168.211.129 | root | nameServer2,brokerServer2 | Master1 |
2、添加hosts信息
vim /etc/hosts
IP | NAME |
192.168.211.128 | rocketmq-nameserver1 |
192.168.211.128 | rocketmq-master1 |
192.168.211.129 | rocketmq-nameserver2 |
192.168.211.129 | rocketmq-master2 |
3、上传解压rocketMq到服务器
上传alibaba-rocketmq-3.2.6.tar.gz文件至/usr/local/install
解压tar -zxvf alibaba-rocketmq-3.2.6.tar.gz -C /usr/local/software
4、创建软连接(两台机器)
ln -s alibaba-rocketmq rocketmq
5、创建存储路径(两台机器)
# mkdir /usr/local/software/rocketmq/store
# mkdir /usr/local/software/rocketmq/store/commitlog
# mkdir /usr/local/software/rocketmq/store/consumequeue
# mkdir /usr/local/software/rocketmq/store/index
6、RocketMQ配置文件(两台机器)
# vim /usr/local/software/rocketmq/conf/2m-noslave/broker-a.properties
# vim /usr/local/software/rocketmq/conf/2m-noslave/broker-b.properties
1 将a.properties和b.properties文件中的内容全部清掉(用下面的内容替换掉) 2 #所属集群名字 3 brokerClusterName=rocketmq-cluster 4 #broker名字,注意此处不同的配置文件填写的不一样 例如:在a.properties 文件中写 broker-a 在b.properties 文件中写 broker-b 5 brokerName=broker-a|broker-b 6 #0 表示 Master,>0 表示 Slave 7 brokerId=0 8 #nameServer地址,分号分割 9 namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876 10 #在发送消息时,自动创建服务器不存在的topic,默认创建的队列数 11 defaultTopicQueueNums=4 12 #是否允许 Broker 自动创建Topic,建议线下开启,线上关闭 13 autoCreateTopicEnable=true 14 #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭 15 autoCreateSubscriptionGroup=true 16 #Broker 对外服务的监听端口 17 listenPort=10911 18 #删除文件时间点,默认凌晨 4点 19 deleteWhen=04 20 #文件保留时间,默认 48 小时 21 fileReservedTime=120 22 #commitLog每个文件的大小默认1G 23 mapedFileSizeCommitLog=1073741824 24 #ConsumeQueue每个文件默认存30W条,根据业务情况调整 25 mapedFileSizeConsumeQueue=300000 26 #destroyMapedFileIntervalForcibly=120000 27 #redeleteHangedFileInterval=120000 28 #检测物理文件磁盘空间 29 diskMaxUsedSpaceRatio=88 30 #存储路径 31 storePathRootDir=/usr/local/software/rocketmq/store 32 #commitLog 存储路径 33 storePathCommitLog=/usr/local/software/rocketmq/store/commitlog 34 #消费队列存储路径存储路径 35 storePathConsumeQueue=/usr/local/software/rocketmq/store/consumequeue 36 #消息索引存储路径 37 storePathIndex=/usr/local/software/rocketmq/store/index 38 #checkpoint 文件存储路径 39 storeCheckpoint=/usr/local/software/rocketmq/store/checkpoint 40 #abort 文件存储路径 41 abortFile=/usr/local/software/rocketmq/store/abort 42 #限制的消息大小 43 maxMessageSize=65536 44 #flushCommitLogLeastPages=4 45 #flushConsumeQueueLeastPages=2 46 #flushCommitLogThoroughInterval=10000 47 #flushConsumeQueueThoroughInterval=60000 48 #Broker 的角色 49 #- ASYNC_MASTER 异步复制Master 50 #- SYNC_MASTER 同步双写Master 51 #- SLAVE 52 brokerRole=ASYNC_MASTER 53 #刷盘方式 54 #- ASYNC_FLUSH 异步刷盘 55 #- SYNC_FLUSH 同步刷盘 56 flushDiskType=ASYNC_FLUSH 57 #checkTransactionMessageEnable=false 58 #发消息线程池数量 59 #sendMessageThreadPoolNums=128 60 #拉消息线程池数量 61 #pullMessageThreadPoolNums=128
7、修改日志文件(两台机器)
# mkdir -p /usr/local/software/rocketmq/logs
# cd /usr/local/software/rocketmq/conf && sed -i ‘s#${user.home}#/usr/local/software/rocketmq#g‘ *.xml
8、修改启动脚本参数(修改启动脚本参数两台机器)
8.1、vim /usr/local/software/rocketmq/bin/runbroker.sh
#===========================================================================================
# JVM Configuration
#===========================================================================================
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m -
XX:PermSize=128m -XX:MaxPermSize=320m"
8.2、vim /usr/local/software/rocketmq/bin/runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m -
XX:PermSize=128m -XX:MaxPermSize=320m"
9、启动NameServer(特别注意:在启动 BrokerServer 之前先关闭防火墙)
# cd /usr/local/software/rocketmq/bin
# nohup sh mqnamesrv &
10、启动BrokerServer A【192.168.211.128】
# cd /usr/local/software/rocketmq/bin
# nohup sh mqbroker -c /usr/local/software/rocketmq/conf/2m-noslave/broker-a.properties >/dev/null 2>&1 &
# netstat -ntlp
# jps
# tail -f -n 500 /usr/local/software/rocketmq/logs/rocketmqlogs/broker.log
# tail -f -n 500 /usr/local/software/rocketmq/logs/rocketmqlogs/namesrv.log
11、启动BrokerServer B 【192.168.211.129】
# cd /usr/local/software/rocketmq/bin
# nohup sh mqbroker -c /usr/local/software/rocketmq/conf/2m-noslave/broker-b.properties >/dev/null 2>&1 &
# netstat -ntlp
# jps
# tail -f -n 500 /usr/local/software/rocketmq/logs/rocketmqlogs/broker.log
# tail -f -n 500 /usr/local/software/rocketmq/logs/rocketmqlogs/namesrv.log
12、停止服务
先停止 broker 在停止 namesrv
cd /usr/local/software/rocketmq/bin
# sh mqshutdown broker
# sh mqshutdown namesrv
双RocketMq集群的搭建