标签:
一、RocketMQ简介:
RocketMQ是一款分布式、队列模型的消息中间件,具有以下特点:
1、支持严格的消息顺序;
2、支持Topic与Queue两种模式;
3、亿级消息堆积能力;
4、比较友好的分布式特性;
5、同时支持Push与Pull方式消费消息;
官网链接:
rocketmq下载地址: https://github.com/alibaba/RocketMQ/releases
rocketmq github: https://github.com/alibaba/RocketMQ
RocketMQ集群安装:
RocketMQ有多种集群的方式,这里是双master的集群.
优点:优点:配置简单,消息也不会丢(异步刷盘丢失少量消息,同步刷盘一条不丢)性能最高
一、前期准备
主机(两台)为centOs6.5系统,ip对应主机名如下:
10.10.10.23 rocketmq-master1 #ip和主机名 10.10.10.24 rocketmq-master2
所需软件:
jdk1.6.0_45.tar.gz #jdk软件 alibaba-rocketmq-3.2.6.tar.gz #mq软件包
hosts信息添加:(两台主机均的添加hosts)
# vim /etc/hosts 10.10.10.23 mqnameserver1 #ip对应brokerName 10.10.10.24 mqnameserver2 10.10.10.23 rocketmq-master1 #ip对应主机名 10.10.10.24 rocketmq-master2 #ip对应主机名
二、安装:
1.>安装JDK
1 jdk1.6.0_45.tar.gz #软件包 2 #tar -zxvf jdk1.6.0_45.tar.gz -C /apps/product/ 3 #ln -s /apps/product/jdk1.6.0_45 java 4 5 #环境变量配置 6 #vim /etc/profile 7 JAVA_HOME=/apps/product/java 8 CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar 9 PATH=$JAVA_HOME/bin:$PATH 10 export JAVA_HOME CLASSPATH PATH 11 12 source /etc/profile 13 查看jdk版本:java -version
2.>RocketMQ安装: (mq版本:3.2.6)
1 >>tar -zxvf alibaba-rocketmq-3.2.6.tar.gz -C /apps/product/ 2 >>cd /apps/product/ 3 >>mv alibaba-rocketmq-3.2.6 rocketmq 4 5 环境变量设置: 6 >>vim /etc/profile 7 JAVA_HOME=/apps/product/java 8 CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar 9 PATH=$JAVA_HOME/bin:$PATH 10 ROCKETMQ_HOME=/apps/product/rocketmq 11 export JAVA_HOME CLASSPATH PATH ROCKETMQ_HOME 12 13 >>source /etc/profile 14 15 >>useradd admin 16 >>cd /apps/product/rocketmq/bin && sh os.sh
3.RocketMQ配置:
部署Broker:消息中转角色,负责存储消息,转发消息
Broker配置参数:
1.>获取Broker的默认配置
sh mqbroker -m
2.>Broker启动时,如何加载配置
生成Broker默认配置模版
sh mqbroker -m >broker.p
3.>修改配置文件.
broker.p
4.>加载修改过的配置文件
nohup sh mqbroker -c broker.p #将broker.p文件复制到broker-a.properties文件,并可以添加其他配置.
(1)、Master1服务器(10.10.10.23)
1 vim /apps/product/rocketmq/conf/2m-noslave/broker-a.properties 2 3 namesrvAddr=10.10.10.23:9876;10.10.10.24:9876 4 brokerIP1=10.10.10.23 5 brokerName=rocketmq-master1 6 brokerClusterName=DefaultCluster 7 brokerId=0 8 autoCreateTopicEnable=true 9 autoCreateSubscriptionGroup=true 10 rejectTransactionMessage=false 11 fetchNamesrvAddrByAddressServer=false 12 storePathRootDir=/root/store 13 storePathCommitLog=/root/store/commitlog 14 flushIntervalCommitLog=1000 15 flushCommitLogTimed=false 16 deleteWhen=04 17 fileReservedTime=72 18 diskMaxUsedSpaceRatio=88 19 maxTransferBytesOnMessageInMemory=262144 20 maxTransferCountOnMessageInMemory=32 21 maxTransferBytesOnMessageInDisk=65536 22 maxTransferCountOnMessageInDisk=8 23 accessMessageInMemoryMaxRatio=40 24 messageIndexEnable=true 25 messageIndexSafe=false 26 haMasterAddress= 27 brokerRole=ASYNC_MASTER 28 flushDiskType=ASYNC_FLUSH 29 cleanFileForciblyEnable=true 30 sendMessageThreadPoolNums=128 31 pullMessageThreadPoolNums=128
(2)、Master2服务器(10.10.10.24)
1 vim /apps/product/rocketmq/conf/2m-noslave/broker-b.properties 2 3 namesrvAddr=10.10.10.24:9876;10.10.10.23:9876 4 brokerIP1=10.10.10.24 5 brokerName=rocketmq-master2 6 brokerClusterName=DefaultCluster 7 brokerId=0 8 autoCreateTopicEnable=true 9 autoCreateSubscriptionGroup=true 10 rejectTransactionMessage=false 11 fetchNamesrvAddrByAddressServer=false 12 storePathRootDir=/root/store 13 storePathCommitLog=/root/store/commitlog 14 flushIntervalCommitLog=1000 15 flushCommitLogTimed=false 16 deleteWhen=04 17 fileReservedTime=72 18 diskMaxUsedSpaceRatio=88 19 maxTransferBytesOnMessageInMemory=262144 20 maxTransferCountOnMessageInMemory=32 21 maxTransferBytesOnMessageInDisk=65536 22 maxTransferCountOnMessageInDisk=8 23 accessMessageInMemoryMaxRatio=40 24 messageIndexEnable=true 25 messageIndexSafe=false 26 haMasterAddress= 27 brokerRole=ASYNC_MASTER 28 flushDiskType=ASYNC_FLUSH 29 cleanFileForciblyEnable=true 30 sendMessageThreadPoolNums=128 31 pullMessageThreadPoolNums=128
(3)、runbroker.sh参数调整
vim /apps/product/rocketmq/bin/runbroker.sh runbroker.sh需要根据内存大小进行适当地调整 JAVA_OPT_1="-server-Xms8g -Xmx8g -Xmn2g -XX:PermSize=1g -XX:MaxPermSize=1g"
服务启动:
mkdir -p /data/rocketmq/store/commitlog /data/logs #创建日志存放目录 >>cd /apps/product/rocketmq/conf && sed -i ‘s#${user.home}#/data#g‘ *.xml #更改为data目录
(1)、启动NameServer【两台启动方式相同】
> cd /apps/product/rocketmq/bin
> nohup sh mqnamesrv & 或者 nohup sh mqnamesrv > nohup.out 2>&1 &
(2)、启动BrokerServer A【10.10.10.23主机】
cd /apps/product/rocketmq/bin nohup sh mqbroker -c ../conf/2m-noslave/broker-a.properties >/dev/null 2>&1 & 或者 #nohup sh mqbroker -n 10.10.10.23:9876 -c ../conf/2m-noslave/broker-a.properties >/dev/null 2>&1 &
(3)、启动BrokerServer B【10.10.10.24主机】
> cd /apps/product/rocketmq/bin nohup sh mqbroker -c ../conf/2m-noslave/broker-b.properties >/dev/null 2>&1 & # nohup sh mqbroker -n 10.10.10.24:9876 -c ../conf/2m-noslave/broker-b.properties >/dev/null 2>&1 &
(4)、测试:
两台机器分别查看日志信息: tail -100f /data/logs/rocketmqlogs/namesrv.log
tail -100f /data/logs/rocketmqlogs/broker.log
#netstat -ntlp #查看端口号
# jps #查看服务
标签:
原文地址:http://www.cnblogs.com/saneri/p/5066265.html