rocketmq集群搭建

上一章讲解了rocketmq的消息发送与接收,那么这篇文章讲解如何安装rocketmq

单机搭建

1. 安装包准备

上传apache-rocketmq.tar.gz至/opt目录

http://download.csdn.net/download/xxzblog/10124706

机器ip:192.168.1.101

2. 安装

1
2
3
4
5
cd /opt
tar -xzf apache-rocketmq.tar.gz
mv apache-rocketmq rocketmq
mkdir /opt/rocketmq/logs
cd /opt/rocketmq/bin && dos2unix *

3. 环境配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cp /opt/rocketmq/conf/broker.conf /opt/rocketmq/conf/broker.properties
echo "brokerIP1=192.168.1.101" > /opt/rocketmq/conf/broker.properties
vi /opt/rocketmq/mqnamesrv-start.sh
export ROCKETMQ_HOME=/opt/rocketmq
nohup sh /opt/rocketmq/bin/mqnamesrv > /opt/rocketmq/logs/mqnamesrv.log 2>&1 &
:x
chmod u+x /opt/rocketmq/mqnamesrv-start.sh
vi /opt/rocketmq/mqbroker-start.sh
export ROCKETMQ_HOME=/opt/rocketmq
nohup sh /opt/rocketmq/bin/mqbroker -n 192.168.1.101:9876 -c /opt/rocketmq/conf/broker.properties > /opt/rocketmq/logs/mqbroker.log 2>&1 &
:x
chmod u+x /opt/rocketmq/mqbroker-start.sh

集群搭建

1, 2同单机一样

本文配置2m-noslave,机器ip:192.168.1.101,192.168.1.102

3.环境配置

/opt/rocketmq/conf/2m-noslave/broker-a.properties

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#所属集群名字
brokerClusterName=DefaultCluster
#broker名字,注意此处不同的配置文件填写的不一样
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=192.168.1.101:9876;192.168.1.102:9876
#关键
brokerIP1=192.168.1.101
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口
listenPort=10911
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=48
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#这里是我的 日志配置
#存储路径
storePathRootDir=/opt/rocketmq/store
#commitLog 存储路径
storePathCommitLog=/opt/rocketmq/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/opt/rocketmq/store/consumequeue
#消息索引存储路径
storePathIndex=/opt/rocketmq/store/index
#checkpoint 文件存储路径
storeCheckpoint=/opt/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/opt/rocketmq/store/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

/opt/rocketmq/conf/2m-noslave/broker-b.properties

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#所属集群名字
brokerClusterName=DefaultCluster
#broker名字,注意此处不同的配置文件填写的不一样
brokerName=broker-b
#0 表示 Master,>0 表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=192.168.1.101:9876;192.168.1.102:9876
#关键
brokerIP1=192.168.1.102
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口
listenPort=10911
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认48小时
fileReservedTime=48
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#这里是我的 日志配置
#存储路径
storePathRootDir=/opt/rocketmq/store
#commitLog 存储路径
storePathCommitLog=/opt/rocketmq/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/opt/rocketmq/store/consumequeue
#消息索引存储路径
storePathIndex=/opt/rocketmq/store/index
#checkpoint 文件存储路径
storeCheckpoint=/opt/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/opt/rocketmq/store/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

启动nameserver脚本[两台机器]

1
2
cd /opt/rocketmq/bin
nohup sh mqnamesrv &

启动BrokerServer

192.168.1.101

1
nohup sh /opt/rocketmq/bin/mqbroker -c /opt/rocketmq/conf/2m-noslave/broker-a.properties > /opt/rocketmq/logs/mqbroker.log 2>&1 &

192.168.1.102

1
nohup sh /opt/rocketmq/bin/mqbroker -c /opt/rocketmq/conf/2m-noslave/broker-b.properties > /opt/rocketmq/logs/mqbroker.log 2>&1 &

备注:可以执行对os的优化/opt/rocketmq/bin/os.sh

rocketmq-console搭建

1.安装包准备

上传rocketmq-console-ng-1.0.0.jar至/opt/rocketmq-console

http://download.csdn.net/download/xxzblog/10124810

2. 启动脚本

1
2
3
4
vi /opt/rocketmq-console/start.sh
nohup java -jar rocketmq-console-ng-1.0.0.jar --server.port=12581 --rocketmq.config.namesrvAddr=192.168.1.101:9876,192.168.1.102:9876 >/opt/rocketmq-console/run.log 2>&1 &
:x
chmod u+x /opt/rocketmq-console/start.sh

3. 执行脚本

1
/opt/rocketmq-console/start.sh

4. 验证是否成功

1
浏览器打开:http://127.0.0.1:12581

整个rocketmq搭建就结束了