RocketMQ 安装部署及运行

RocketMQ 官方文档中说明的安装先决条件包括:

  • 64bit OS, Linux/Unix/Mac is recommended
  • 64bit JDK 1.8+
  • Maven 3.2.x
  • Git

虽然推荐的操作系统是 Linux/Unix/Mac,实际上 Windows 下也是可以安装部署的,本文演示 RocketMQ 在 Windows 10 和 Mac 中的安装部署及运行。

Windows 10

为简单起见,直接下载 binary release,本文使用 4.2.0 版本

1 解压到本地目录

2 设置系统环境变量 ROCKETMQ_HOME 指向 RocketMQ 的安装目录
此步非常重要,否则无法启动 NameServer


为了方便后续在命令提示符(cmd)窗口快速使用 RocketMQ 的命令,还需要将 %ROCKETMQ_HOME%\bin 添加到系统环境变量 Path 中。

3 启动 NameServer
在命令提示符(cmd)窗口中执行命令 mqnamesrv.cmd
启动日志如果有 The Name Server boot success 打印则表示 NameServer 启动成功,暂时忽略启动日志中的警告,注意一旦命令提示符(cmd)窗口关闭则 NameServer 停止运行。

Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release
Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
The Name Server boot success. serializeType=JSON

4 启动 Broker
重新开启一个命令提示符(cmd)窗口,执行命令 mqbroker.cmd -n localhost:9876,注意只要没有报错日志应该就是启动成功了,如果启动成功则不会打印任何日志,不要关闭命令提示符(cmd)窗口。需要注意的是必须先启动 NameServer 再启动 Broker,Broker 要在 NameServer 上注册。

5 验证 RocketMQ 是否正常运行

有两种验证方法:

(1) 运行官方提供的快速启动示例

首先,重新开启一个命令提示符(cmd)窗口,执行命令 set NAMESRV_ADDR=localhost:9876 设置环境变量,也可以像第 2 步一样将 NAMESRV_ADDR 添加到系统环境变量中;

其次,执行命令 tools.cmd org.apache.rocketmq.example.quickstart.Producer,运行官方示例中的消息生产者,可以看到消息全部成功发送,以下截取了部分消息发布日志

22:26:06.213 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework
22:26:06.224 [main] DEBUG i.n.c.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 16
22:26:06.238 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Buffer.address: available
22:26:06.238 [main] DEBUG i.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available
22:26:06.239 [main] DEBUG i.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available
22:26:06.240 [main] DEBUG i.n.util.internal.PlatformDependent0 - direct buffer constructor: available
22:26:06.240 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true
22:26:06.240 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.<init>(long, int): available
22:26:06.241 [main] DEBUG io.netty.util.internal.Cleaner0 - java.nio.ByteBuffer.cleaner(): available
22:26:06.242 [main] DEBUG i.n.util.internal.PlatformDependent - Platform: Windows
22:26:06.242 [main] DEBUG i.n.util.internal.PlatformDependent - Java version: 8
22:26:06.242 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noUnsafe: false
22:26:06.242 [main] DEBUG i.n.util.internal.PlatformDependent - sun.misc.Unsafe: available
22:26:06.243 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noJavassist: false
22:26:06.327 [main] DEBUG i.n.util.internal.PlatformDependent - Javassist: available
22:26:06.328 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\Ji\AppData\Local\Temp (java.io.tmpdir)
22:26:06.328 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model)
22:26:06.329 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false
22:26:06.329 [main] DEBUG i.n.util.internal.PlatformDependent - io.netty.maxDirectMemory: 1040187392 bytes
22:26:06.342 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false
22:26:06.342 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512
22:26:06.347 [main] DEBUG i.n.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available
22:26:06.600 [main] DEBUG i.n.util.internal.ThreadLocalRandom - -Dio.netty.initialSeedUniquifier: 0x2f0e8a555da48856 (took 0 ms)
22:26:06.621 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: unpooled
22:26:06.622 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 65536
22:26:06.623 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384
22:26:06.639 [NettyClientSelector_1] DEBUG i.n.u.i.JavassistTypeParameterMatcherGenerator - Generated: io.netty.util.internal.__matchers__.org.apache.rocketmq.remoting.protocol.RemotingCommandMatcher
22:26:06.652 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacity.default: 32768
22:26:06.652 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2
22:26:06.653 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16
22:26:06.656 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
22:26:06.667 [NettyClientWorkerThread_1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.bytebuf.checkAccessible: true
22:26:06.673 [NettyClientWorkerThread_1] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple
22:26:06.673 [NettyClientWorkerThread_1] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.maxRecords: 4
22:26:06.675 [NettyClientWorkerThread_1] DEBUG i.n.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@395ad0f
SendResult [sendStatus=SEND_OK, msgId=0A000007093C5CAD80860F1D20380000, offsetMsgId=0A00000700002A9F0000000000000000, messageQueue=MessageQueue [topic=TopicTest, brokerName=LAPTOP-C375ASPB, queueId=3], queueOffset=0]
SendResult [sendStatus=SEND_OK, msgId=0A000007093C5CAD80860F1D20880001, offsetMsgId=0A00000700002A9F00000000000000B2, messageQueue=MessageQueue [topic=TopicTest, brokerName=LAPTOP-C375ASPB, queueId=0], queueOffset=0]
SendResult [sendStatus=SEND_OK, msgId=0A000007093C5CAD80860F1D208F0002, offsetMsgId=0A00000700002A9F0000000000000164, messageQueue=MessageQueue [topic=TopicTest, brokerName=LAPTOP-C375ASPB, queueId=1], queueOffset=0]
SendResult [sendStatus=SEND_OK, msgId=0A000007093C5CAD80860F1D20990003, offsetMsgId=0A00000700002A9F0000000000000216, messageQueue=MessageQueue [topic=TopicTest, brokerName=LAPTOP-C375ASPB, queueId=2], queueOffset=0]
SendResult [sendStatus=SEND_OK, msgId=0A000007093C5CAD80860F1D209F0004, offsetMsgId=0A00000700002A9F00000000000002C8, messageQueue=MessageQueue [topic=TopicTest, brokerName=LAPTOP-C375ASPB, queueId=3], queueOffset=1]
SendResult [sendStatus=SEND_OK, msgId=0A000007093C5CAD80860F1D20A50005, offsetMsgId=0A00000700002A9F000000000000037A, messageQueue=MessageQueue [topic=TopicTest, brokerName=LAPTOP-C375ASPB, queueId=0], queueOffset=1]
SendResult [sendStatus=SEND_OK, msgId=0A000007093C5CAD80860F1D20AB0006, offsetMsgId=0A00000700002A9F000000000000042C, messageQueue=MessageQueue [topic=TopicTest, brokerName=LAPTOP-C375ASPB, queueId=1], queueOffset=1]
SendResult [sendStatus=SEND_OK, msgId=0A000007093C5CAD80860F1D20B20007, offsetMsgId=0A00000700002A9F00000000000004DE, messageQueue=MessageQueue [topic=TopicTest, brokerName=LAPTOP-C375ASPB, queueId=2], queueOffset=1]
SendResult [sendStatus=SEND_OK, msgId=0A000007093C5CAD80860F1D20B60008, offsetMsgId=0A00000700002A9F0000000000000590, messageQueue=MessageQueue [topic=TopicTest, brokerName=LAPTOP-C375ASPB, queueId=3], queueOffset=2]
SendResult [sendStatus=SEND_OK, msgId=0A000007093C5CAD80860F1D20BD0009, offsetMsgId=0A00000700002A9F0000000000000642, messageQueue=MessageQueue [topic=TopicTest, brokerName=LAPTOP-C375ASPB, queueId=0], queueOffset=2]
......

最后,执行命令 tools.cmd org.apache.rocketmq.example.quickstart.Consumer,运行官方示例中的消息消费者,可以看到消息全部成功消费,以下截取了部分消息消费日志

22:28:56.473 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework
22:28:56.476 [main] DEBUG i.n.c.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 16
22:28:56.490 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Buffer.address: available
22:28:56.490 [main] DEBUG i.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available
22:28:56.491 [main] DEBUG i.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available
22:28:56.491 [main] DEBUG i.n.util.internal.PlatformDependent0 - direct buffer constructor: available
22:28:56.491 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true
22:28:56.492 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.<init>(long, int): available
22:28:56.493 [main] DEBUG io.netty.util.internal.Cleaner0 - java.nio.ByteBuffer.cleaner(): available
22:28:56.493 [main] DEBUG i.n.util.internal.PlatformDependent - Platform: Windows
22:28:56.493 [main] DEBUG i.n.util.internal.PlatformDependent - Java version: 8
22:28:56.493 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noUnsafe: false
22:28:56.494 [main] DEBUG i.n.util.internal.PlatformDependent - sun.misc.Unsafe: available
22:28:56.494 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noJavassist: false
22:28:56.580 [main] DEBUG i.n.util.internal.PlatformDependent - Javassist: available
22:28:56.581 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\Ji\AppData\Local\Temp (java.io.tmpdir)
22:28:56.582 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model)
22:28:56.582 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false
22:28:56.582 [main] DEBUG i.n.util.internal.PlatformDependent - io.netty.maxDirectMemory: 1040187392 bytes
22:28:56.595 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false
22:28:56.595 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512
22:28:56.600 [main] DEBUG i.n.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available
22:28:57.080 [main] DEBUG i.n.util.internal.ThreadLocalRandom - -Dio.netty.initialSeedUniquifier: 0x1e52632a543f7abb (took 0 ms)
22:28:57.104 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: unpooled
22:28:57.105 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 65536
22:28:57.106 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384
22:28:57.122 [NettyClientSelector_1] DEBUG i.n.u.i.JavassistTypeParameterMatcherGenerator - Generated: io.netty.util.internal.__matchers__.org.apache.rocketmq.remoting.protocol.RemotingCommandMatcher
22:28:57.135 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacity.default: 32768
22:28:57.136 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2
22:28:57.136 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16
22:28:57.137 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
22:28:57.146 [NettyClientWorkerThread_1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.bytebuf.checkAccessible: true
22:28:57.149 [NettyClientWorkerThread_1] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple
22:28:57.149 [NettyClientWorkerThread_1] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.maxRecords: 4
22:28:57.150 [NettyClientWorkerThread_1] DEBUG i.n.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@4aed4bcc
Consumer Started.
ConsumeMessageThread_7 Receive New Messages: [MessageExt [queueId=2, storeSize=178, queueOffset=1, sysFlag=0, bornTimestamp=1530627967154, bornHost=/10.0.0.7:55776, storeTimestamp=1530627967156, storeHost=/10.0.0.7:10911, msgId=0A00000700002A9F00000000000004DE, commitLogOffset=1246, bodyCRC=988340972, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message [topic=TopicTest, flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=250, CONSUME_START_TIME=1530628137407, UNIQ_KEY=0A000007093C5CAD80860F1D20B20007, WAIT=true, TAGS=TagA}, body=16]]]
ConsumeMessageThread_15 Receive New Messages: [MessageExt [queueId=3, storeSize=178, queueOffset=2, sysFlag=0, bornTimestamp=1530627967158, bornHost=/10.0.0.7:55776, storeTimestamp=1530627967161, storeHost=/10.0.0.7:10911, msgId=0A00000700002A9F0000000000000590, commitLogOffset=1424, bodyCRC=710410109, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message [topic=TopicTest, flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=250, CONSUME_START_TIME=1530628137410, UNIQ_KEY=0A000007093C5CAD80860F1D20B60008, WAIT=true, TAGS=TagA}, body=16]]]
ConsumeMessageThread_9 Receive New Messages: [MessageExt [queueId=1, storeSize=179, queueOffset=2, sysFlag=0, bornTimestamp=1530627967171, bornHost=/10.0.0.7:55776, storeTimestamp=1530627967173, storeHost=/10.0.0.7:10911, msgId=0A00000700002A9F00000000000006F4, commitLogOffset=1780, bodyCRC=193412630, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message [topic=TopicTest, flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=250, CONSUME_START_TIME=1530628137415, UNIQ_KEY=0A000007093C5CAD80860F1D20C3000A, WAIT=true, TAGS=TagA}, body=17]]]
ConsumeMessageThread_16 Receive New Messages: [MessageExt [queueId=1, storeSize=179, queueOffset=3, sysFlag=0, bornTimestamp=1530627967196, bornHost=/10.0.0.7:55776, storeTimestamp=1530627967198, storeHost=/10.0.0.7:10911, msgId=0A00000700002A9F00000000000009C0, commitLogOffset=2496, bodyCRC=216726031, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message [topic=TopicTest, flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=250, CONSUME_START_TIME=1530628137411, UNIQ_KEY=0A000007093C5CAD80860F1D20DC000E, WAIT=true, TAGS=TagA}, body=17]]]
......

(2) 关闭 Broker 和 NameServer

首先,执行命令 mqshutdown.cmd broker 关闭 Broker,如果有 Broker 运行则会打印关闭的 Broker 所在线程,如:

killing broker
成功: 已终止 PID 为 3960 的进程。
Done!

其次,执行命令 `` 关闭 NameServer,如果有 NameServer 运行则会打印关闭的 NameServer 所在线程,如:

killing name server
成功: 已终止 PID 为 19504 的进程。
Done!

Mac

上一篇:RocketMQ 介绍及核心概念
下一篇:RocketMQ Console 的安装及运行

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,560评论 4 361
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,104评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,297评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,869评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,275评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,563评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,833评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,543评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,245评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,512评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,011评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,359评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,006评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,062评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,825评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,590评论 2 273
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,501评论 2 268

推荐阅读更多精彩内容