搭建 Apache RocketMQ 单机环境

Posted 搜云库技术团队

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搭建 Apache RocketMQ 单机环境相关的知识,希望对你有一定的参考价值。

本文快速入门,RocketMQ消息系统的安装部署,发送,和接收消息的详细说明。

环境需要

64位操作系统,建议使用Linux / Unix /

  • CentOs7.3

  • 64bit JDK 1.8+

  • Maven 3.2.x

JDK Maven 的安装自行 Google 或者去我博客 http://www.ymq.io 搜索安装

下载和构建

下载4.2.0源码版本: https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.2.0/rocketmq-all-4.2.0-source-release.zip

下载4.2.0二进制版本: http://rocketmq.apache.org/release_notes/release-notes-4.2.0/

现在执行以下命令来解压4.2.0源码版本并构建二进制文件

 
   
   
 
  1. & unzip rocketmq-all-4.2.0-source-release.zip

  2. & cd rocketmq-all-4.2.0/

  3. & mvn -Prelease-all -DskipTests clean install -U

  4. & mv distribution/target/apache-rocketmq /opt/apache-rocketmq

编译成功的响应

 
   
   
 
  1. [INFO] Reactor Summary:

  2. [INFO]

  3. [INFO] Apache RocketMQ 4.2.0 .............................. SUCCESS [04:21 min]

  4. [INFO] rocketmq-remoting 4.2.0 ............................ SUCCESS [ 25.561 s]

  5. [INFO] rocketmq-common 4.2.0 .............................. SUCCESS [  4.533 s]

  6. [INFO] rocketmq-client 4.2.0 .............................. SUCCESS [  5.804 s]

  7. [INFO] rocketmq-store 4.2.0 ............................... SUCCESS [  5.239 s]

  8. [INFO] rocketmq-srvutil 4.2.0 ............................. SUCCESS [  2.177 s]

  9. [INFO] rocketmq-filter 4.2.0 .............................. SUCCESS [  1.262 s]

  10. [INFO] rocketmq-broker 4.2.0 .............................. SUCCESS [  3.129 s]

  11. [INFO] rocketmq-tools 4.2.0 ............................... SUCCESS [  1.995 s]

  12. [INFO] rocketmq-namesrv 4.2.0 ............................. SUCCESS [  1.322 s]

  13. [INFO] rocketmq-logappender 4.2.0 ......................... SUCCESS [  1.549 s]

  14. [INFO] rocketmq-openmessaging 4.2.0 ....................... SUCCESS [  1.560 s]

  15. [INFO] rocketmq-example 4.2.0 ............................. SUCCESS [  1.242 s]

  16. [INFO] rocketmq-filtersrv 4.2.0 ........................... SUCCESS [  0.680 s]

  17. [INFO] rocketmq-test 4.2.0 ................................ SUCCESS [  3.047 s]

  18. [INFO] rocketmq-distribution 4.2.0 ........................ SUCCESS [ 27.005 s]

  19. [INFO] ------------------------------------------------------------------------

  20. [INFO] BUILD SUCCESS

  21. [INFO] ------------------------------------------------------------------------

  22. [INFO] Total time: 06:09 min

  23. [INFO] Finished at: 2018-02-01T15:51:26+08:00

  24. [INFO] Final Memory: 73M/411M

  25. [INFO] ------------------------------------------------------------------------

Start Name Server

默认 RocketMQ Server 内存需要很大的

 
   
   
 
  1. vi /bin/runserver.sh

 
   
   
 
  1. JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

我修改成

 
   
   
 
  1. JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

 
   
   
 
  1. & cd /opt/apache-rocketmq

  2. & nohup sh bin/mqnamesrv > /dev/null 2>&1 &

  3. & tail -f ~/logs/rocketmqlogs/namesrv.log

会看到如下响应信息

 
   
   
 
  1. 2018-02-01 16:15:16 INFO main - The Name Server boot success...

Start Broker

默认 RocketMQ Broker 内存需要很大的

 
   
   
 
  1. vi /bin/runbroker.sh

 
   
   
 
  1. JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"

我修改成

 
   
   
 
  1. JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m"

启动Broker

 
   
   
 
  1. & nohup sh bin/mqbroker -n localhost:9876 > /dev/null 2>&1 &

  2. & tail -f ~/logs/rocketmqlogs/broker.log

会看到如下响应信息

 
   
   
 
  1. 2018-02-01 17:37:48 INFO main - The broker[node1, 192.168.252.121:10911] boot success...

查看进程

 
   
   
 
  1. [root@node1 apache-rocketmq]# jps

  2. 2374 BrokerStartup

  3. 2350 NamesrvStartup

 
   
   
 
  1. [root@node1 apache-rocketmq]# netstat -ntlp

  2. Active Internet connections (only servers)

  3. Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name          

  4. tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1508/master        

  5. tcp6       0      0 :::9876                 :::*                    LISTEN      2350/java                    

  6. tcp6       0      0 ::1:25                  :::*                    LISTEN      1508/master        

  7. tcp6       0      0 :::10909                :::*                    LISTEN      2374/java          

  8. tcp6       0      0 :::10911                :::*                    LISTEN      2374/java          

  9. tcp6       0      0 :::10912                :::*                    LISTEN      2374/java          

  10. [root@node1 apache-rocketmq]#

发送并接受 消息

Send & Receive Messages

发送消息

 
   
   
 
  1. export NAMESRV_ADDR=localhost:9876

  2. sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer

响应

 
   
   
 
  1. SendResult [sendStatus=SEND_OK, msgId= ...

消费消息

 
   
   
 
  1. sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer

响应

 
   
   
 
  1. ConsumeMessageThread_%d Receive New Messages: [MessageExt...

停止服务

停止 broker

 
   
   
 
  1. > sh bin/mqshutdown broker

  2. The mqbroker(36695) is running...

  3. Send shutdown request to mqbroker(36695) OK

停止 namesrv

 
   
   
 
  1. > sh bin/mqshutdown namesrv

  2. The mqnamesrv(36664) is running...

  3. Send shutdown request to mqnamesrv(36664) OK

Contact

  • 出处:http://www.ymq.io/2018/01/29/MongoDB-2

  • 版权归作者所有,转载请注明出处


以上是关于搭建 Apache RocketMQ 单机环境的主要内容,如果未能解决你的问题,请参考以下文章

RocketMQ 4.5.1 单机环境搭建以及生产消费测试

RocketMQ单机环境搭建

RocketMQ单机环境搭建

15 Centos单机搭建Rocketmq运行环境

RocketMq: Linux环境-单机部署和主从集群部署

RocketMQ 可视化环境搭建和基础代码使用