下载地址:https://github.com/alibaba/RocketMQ
转载请注明来源:http://blog.csdn.net/loongshawn/article/details/51086876
相关文章:
0 RocketMQ简介
0.1 介绍
RocketMQ是一个消息中间件。消息中间件中有两个角色:消息生产者和消息消费者。RocketMQ里同样有这两个概念,消息生产者负责创建消息并发送到RocketMQ服务器,RocketMQ服务器会将消息持久化到磁盘,消息消费者从RocketMQ服务器拉取消息并提交给应用消费。
0.2 特点
RocketMQ是一款分布式、队列模型的消息中间件,具有以下特点:
- 支持严格的消息顺序
- 支持Topic与Queue两种模式
- 亿级消息堆积能力
- 比较友好的分布式特性
- 同时支持Push与Pull方式消费消息
- 历经多次天猫双十一海量消息考验
0.3 部署结构
上图所示为RocketMQ的部署结构,图中Meta字样为RocketMQ早期代号。
1 RocketMQ 消息队列单机部署
1.1 系统配置环境
主机:Linux
内存:8G
硬盘:250G
CPU:4核
1.2 需要用到的软件包和文档
目前在Github上可下载最新的安装包alibaba-rocketmq-3.2.6.tar
下载地址:https://github.com/alibaba/RocketMQ
历史版本说明文档:Metaq原理与应用.docx
备注:RocketMQ早起在淘宝内部叫Metaq,去年改名为RocketMQ,不过该文档是针对历史版本的Metaq,仅供参考和熟悉一些概念。
1.3 服务器java环境
$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.4 rocketmq服务端安装
解压alibaba-rocketmq-3.2.6.tar
tar xvf alibaba-rocketmq-3.1.8.tar.gz -C /opt/
配置rocketmq的环境变量,在/etc/profile最后添加
export ROCKETMQ_HOME=/opt/alibaba-rocketmq
export PATH=$JAVA_HOME/bin:$ROCKETMQ_HOME/bin:$PATH
使rocketmq的环境变量生效
source /etc/profile
给下列命令可执行权限
cd /opt/alibaba-rocketmq/bin/;
chmod +x mqadmin mqbroker mqfiltersrv mqshutdown mqnamesrv
修改脚本内存
runbroker.sh #JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m -XX:PermSize=128m -XX:MaxPermSize=320m" 内存至少1G
runserver.sh
新建日志文件夹
cd /opt/alibaba-rocketmq
mkdir log
启动nameserver
nohup mqnamesrv 1>/opt/alibaba-rocketmq/log/ng.log 2>/opt/alibaba-rocketmq/log/ng-err.log &
查看启动状态
$ps aux|grep java
125233 12248 21.1 0.9 7151512 75844 pts/1 Sl 11:37 0:01 /opt/java/jdk1.8.0_45/bin/java -server -Xms4g -Xmx4g -Xmn2g -XX:PermSize=128m -XX:MaxPermSize=320m -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:+DisableExplicitGC -verbose:gc -Xloggc:/home/xiaolong.xiao/rmq_srv_gc.log -XX:+PrintGCDetails -XX:-OmitStackTraceInFastThrow -Djava.ext.dirs=/opt/alibaba-rocketmq/bin/../lib -cp .:/opt/alibaba-rocketmq/bin/../conf:.:/opt/java/jdk1.8.0_45/lib/dt.jar:/opt/java/jdk1.8.0_45/lib/tools.jar com.alibaba.rocketmq.namesrv.NamesrvStartup
验证nameserver是否启动
$tail -f /opt/alibaba-rocketmq/log/ng.log
The Name Server boot success.
启动broker,在启动borker之前需要指定nameserver地址,其中10.125.1.186为所在服务器IP
export NAMESRV_ADDR=10.125.1.186:9876
nohup mqbroker >/opt/alibaba-rocketmq/log/mq.log &
验证mqbroker是否启动
tail -f /opt/alibaba-rocketmq/log/mq.log
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=320m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
The broker[e010125001186.bja, 10.125.1.186:10911] boot success. and name server is 10.125.1.186:9876
最后配置防火墙
nameserver端口为9876
broker端口为10911
lokkit -p 9876:tcp -p 10911:tcp
关闭nameserver broker执行的命令
mqshutdown namesrv
mqshutdown broker
关闭nameserver
mqshutdown namesrv
The mqnamesrv(12248) is running...
Send shutdown request to mqnamesrv(12248) OK
关闭broker
$mqshutdown broker
The mqbroker(13634) is running...
Send shutdown request to mqbroker(13634) OK
安装成功显示结果: