阿里的rocketmq
RocketMQ是一款分布式、队列模型的消息中间件,具有以下特点:
1、支持严格的消息顺序;
2、支持Topic与Queue两种模式;
3、亿级消息堆积能力;
4、比较友好的分布式特性;
5、同时支持Push与Pull方式消费消息;
https://github.com/alibaba/RocketMQ/releases 最新版本
在生产环境部署Broker,请参考以下软硬件要求
https://github.com/alibaba/RocketMQ/wiki/system_requirements
安装
第一步:安装jdk、修改主机名、添加hosts
1
2
3
4
5
|
# jdk环境变量,具体怎么安装这里不再阐述 root@rocketmq-master2:~ # java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode) |
1
2
3
|
# 主机名,具体如何修改这里不再阐述 root@rocketmq-master2:~ # hostname
rocketmq-master2 |
1
2
3
4
5
6
7
8
9
10
11
|
# hosts文件修改 root@rocketmq-master2:~ # cat /etc/hosts
127.0.0.1 localhost 127.0.1.1 MQnameserver 192.168.1.157 mqnameserver1 192.168.1.158 mqnameserver2 192.168.1.157 rocketmq-master1 192.168.1.158 rocketmq-master2 root@rocketmq-master2:~ # ping mqnameserver1
PING mqnameserver1 (192.168.1.157) 56(84) bytes of data. 64 bytes from mqnameserver1 (192.168.1.157): icmp_req=1 ttl=64 time =0.122 ms
|
第二步:下载安装包并上传服务器/usr/local 下面(这个路径随便写,我比较喜欢放到这里)
源码的安装包下载地址为:https://github.com/alibaba/RocketMQ/releases
编译好的下载包地址为:http://download.csdn.net/detail/xinsir88/9772820
第三步:解压并删除原有程序包
1
2
|
unzip alibaba-rocketmq3.5.8.zip rm -rf alibaba-rocketmq3.5.8.zip |
第四步:对解压好的目录做一个超链接
1
|
ln -s alibaba-rocketmq rocketmq3.5.8
|
第五步:修改环境变量并使环境变量生效
在/etc/profile文件中添加如下代码
1
2
3
|
# 这里的路径根据自己安装的路径进行对应修改 export ROCKETMQ_HOME= /usr/local/rocketmq3 .5.8
export PATH=$PATH::$ROCKETMQ_HOME /bin
|
执行下面命令使之修改生效
1
|
source /etc/profile
|
第六步:修改broker A的配置文件,注释原先所有配置,添加如下内容
文件路径:/usr/local/rocketmq3.5.8/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
|
brokerClusterName=AdpMqCluster brokerName=broker-a brokerId=0 namesrvAddr=mqnameserver1:9876;mqnameserver2:9876 defaultTopicQueueNums=4 autoCreateTopicEnable= true
autoCreateSubscriptionGroup= true
listenPort=10911 deleteWhen=04 fileReservedTime=120 mapedFileSizeCommitLog=1073741824 mapedFileSizeConsumeQueue=50000000 destroyMapedFileIntervalForcibly=120000 redeleteHangedFileInterval=120000 diskMaxUsedSpaceRatio=88 storePathRootDir= /Disk/data/rocketmq/store
storePathCommitLog= /Disk/data/rocketmq/store/commitlog
maxMessageSize=65536 flushCommitLogLeastPages=4 flushConsumeQueueLeastPages=2 flushCommitLogThoroughInterval=10000 flushConsumeQueueThoroughInterval=60000 brokerRole=ASYNC_MASTER flushDiskType=ASYNC_FLUSH checkTransactionMessageEnable= false
sendMessageThreadPoolNums=128 pullMessageThreadPoolNums=128 |
第七步:修改brokerB的配置文件,注释原先所有配置,添加如下内容
文件路径:/usr/local/rocketmq3.5.8/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
|
brokerClusterName=AdpMqCluster brokerName=broker-b brokerId=1 namesrvAddr=mqnameserver1:9876;mqnameserver2:9876 defaultTopicQueueNums=4 autoCreateTopicEnable= true
autoCreateSubscriptionGroup= true
listenPort=10911 deleteWhen=04 fileReservedTime=120 mapedFileSizeCommitLog=1073741824 mapedFileSizeConsumeQueue=50000000 destroyMapedFileIntervalForcibly=120000 redeleteHangedFileInterval=120000 diskMaxUsedSpaceRatio=88 storePathRootDir= /Disk/data/rocketmq/store
storePathCommitLog= /Disk/data/rocketmq/store/commitlog
maxMessageSize=65536 flushCommitLogLeastPages=4 flushConsumeQueueLeastPages=2 flushCommitLogThoroughInterval=10000 flushConsumeQueueThoroughInterval=60000 brokerRole=ASYNC_MASTER flushDiskType=ASYNC_FLUSH checkTransactionMessageEnable= false
sendMessageThreadPoolNums=128 pullMessageThreadPoolNums=128 |
第八步:分别修改启动nameserver和broker时候设定的内存大小(根据个人的机器配置进行修改)
分别修改两台主机的runserver.sh和runbroker.sh文件
runserver.sh文件修改
1
2
|
39 #JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:PermSize=128m -XX:MaxPermSize=320m"
40 JAVA_OPT= "${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:PermSize=64m -XX:MaxPermSize=128m"
|
runbroker.sh文件修改
1
2
|
39 #JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:PermSize=128m -XX:MaxPermSize=320m"
40 JAVA_OPT= "${JAVA_OPT} -server -Xmx1g -Xmx1g -Xmn250m -XX:PermSize=64m -XX:MaxPermSize=128m"
|
第九步:分别启动两台主机的NameServer和broker
启动顺序:NameServer A ---> NameServer B --->broker A ---> broker B
1
2
3
4
|
# 启动NameServer命令 root@rocketmq-master1: /usr/local/rocketmq3 .5.8 /bin # pwd
/usr/local/rocketmq3 .5.8 /bin
root@rocketmq-master1: /usr/local/rocketmq3 .5.8 /bin # nohup sh mqnamesrv &
|
1
2
3
4
|
# 启动Broker A命令 root@rocketmq-master1: /usr/local/rocketmq3 .5.8 /bin # pwd
/usr/local/rocketmq3 .5.8 /bin
nohup sh mqbroker -c .. /conf/2m-noslave/broker-a .properties > /dev/null 2>&1 &
|
1
2
3
4
|
# 启动Broker B命令 root@rocketmq-master2: /usr/local/rocketmq3 .5.8 /bin # pwd
/usr/local/rocketmq3 .5.8 /bin
nohup sh mqbroker -n 192.168.1.157:9876 -c .. /conf/2m-noslave/broker-b .properties > /dev/null 2>&1 &
|
第十步:分别检查是否成功启动,检查命令:jps 如果发现有Nameserver和Broker进程在问题基本不大,可以写代码进行测试了
NameServer A
1
2
3
4
|
root@rocketmq-master1: /usr/local/rocketmq3 .5.8 /conf/2m-noslave # jps
3586 NamesrvStartup 4021 Jps 3663 BrokerStartup |
NameServer B
1
2
3
4
|
root@rocketmq-master2: /usr/local/rocketmq3 .5.8 /bin # jps
1290 NamesrvStartup 1706 Jps 1323 BrokerStartup |
呜谢:
感谢重要参考文档: