Rocketmq mac/linux 安装笔记

从零手写实现 mq

Quick Start

quick start

需要

64位操作系统,最好是Linux/Unix/Mac;
64位JDK 1.6+;
Maven 3.x
Git
Screen

JDK

ruby 复制代码
houbinbindeMacBook-Pro:aliyun-ons-client-java houbinbin$ java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

下载和安装

  • 下载 RocketMQ

从这里下载:https://github.com/alibaba/RocketMQ/releases,当前版本标签为 3.5.8

shell 复制代码
$ ls
RocketMQ-3.5.8		RocketMQ-3.5.8.tar.gz
  • 安装
shell 复制代码
$ pwd
/Users/houbinbin/it/tools/rocketMQ/RocketMQ-3.5.8

$ bash install.sh
...

然后我们得到

less 复制代码
 To refactor, move this assembly into a child project and use the flag <useAllReactorProjects>true</useAllReactorProjects> in each moduleSet.
[INFO] Building tar: /Users/houbinbin/IT/tools/rocketMQ/RocketMQ-3.5.8/target/alibaba-rocketmq-broker.tar.gz
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] rocketmq-all 3.5.8 ................................. SUCCESS [ 48.565 s]
[INFO] rocketmq-remoting 3.5.8 ............................ SUCCESS [  1.772 s]
[INFO] rocketmq-common 3.5.8 .............................. SUCCESS [  1.348 s]
[INFO] rocketmq-client 3.5.8 .............................. SUCCESS [  1.522 s]
[INFO] rocketmq-store 3.5.8 ............................... SUCCESS [  0.815 s]
[INFO] rocketmq-srvutil 3.5.8 ............................. SUCCESS [  0.139 s]
[INFO] rocketmq-broker 3.5.8 .............................. SUCCESS [  0.951 s]
[INFO] rocketmq-tools 3.5.8 ............................... SUCCESS [  0.889 s]
[INFO] rocketmq-namesrv 3.5.8 ............................. SUCCESS [  0.373 s]
[INFO] rocketmq-example 3.5.8 ............................. SUCCESS [  0.392 s]
[INFO] rocketmq-filtersrv 3.5.8 ........................... SUCCESS [  0.337 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 59.323 s
[INFO] Finished at: 2017-01-02T18:21:01+08:00
[INFO] Final Memory: 52M/1042M
[INFO] ------------------------------------------------------------------------

环境配置

确保以下环境变量正确设置:JAVA_HOME

现在设置 ROCKETMQ_HOME 环境变量:

bash 复制代码
cd devenv

echo "ROCKETMQ_HOME=`pwd`" >> ~/.bash_profile

立即生效:

bash 复制代码
source ~/.bash_profile

启动 RocketMQ Name Server 和 Broker

确保在 devenv 目录下:

bash 复制代码
$ cd bin
$ pwd
/Users/houbinbin/it/tools/rocketMQ/RocketMQ-3.5.8/devenv/bin
  • 启动 Name Server

    screen bash mqnamesrv

现实是可能会遇到这个:

csharp 复制代码
$ screen bash mqnamesrv
[screen is terminating]

screen is terminating

执行以下命令(暂时提权):

su

使用 screen 命令进入, 运行:

ruby 复制代码
$   bash mqnamesrv

接下来

ini 复制代码
sh-3.2# bash mqnamesrv
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 Name Server boot success. serializeType=JSON

如果您看到 "The Name Server boot success. serializeType=JSON",这表示命名服务器已成功启动。

按下 Ctrl + A,然后按 D 分离会话。

csharp 复制代码
sh-3.2# screen
[detached]

Start Broker 启动 broker

ini 复制代码
sh-3.2# screen
sh-3.2# pwd
/Users/houbinbin/it/tools/rocketMQ/RocketMQ-3.5.8/devenv/bin
sh-3.2# bash mqbroker -n localhost:9876
cp: /var/root/rmq_bk_gc.log: No such file or directory
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.
Java HotSpot(TM) 64-Bit Server VM warning: Cannot open file /var/root/tmpfs/logs/gc.log due to No such file or directory

The broker[houbinbindeMacBook-Pro.local, 192.168.2.102:10911] boot success. serializeType=JSON and name server is localhost:9876

如果您看到类似以下输出:

The broker[lizhanhui-Lenovo, 172.30.30.233:10911] boot success. serializeType=JSON and name server is localhost:9876,则您的 broker 已成功运行。

发送和接收消息

在发送/接收消息之前,我们需要告诉客户端名称服务器的位置。RocketMQ 提供了多种实现方式。 为简单起见,我们使用环境变量 NAMESRV_ADDR

ini 复制代码
$   export NAMESRV_ADDR=localhost:9876

本文由博客一文多发平台 OpenWrite 发布!

相关推荐
ProtonBase23 分钟前
如何从 0 到 1 ,打造全新一代分布式数据架构
java·网络·数据库·数据仓库·分布式·云原生·架构
乐之者v29 分钟前
leetCode43.字符串相乘
java·数据结构·算法
suweijie7684 小时前
SpringCloudAlibaba | Sentinel从基础到进阶
java·大数据·sentinel
公贵买其鹿4 小时前
List深拷贝后,数据还是被串改
java
xlsw_8 小时前
java全栈day20--Web后端实战(Mybatis基础2)
java·开发语言·mybatis
神仙别闹8 小时前
基于java的改良版超级玛丽小游戏
java
黄油饼卷咖喱鸡就味增汤拌孜然羊肉炒饭9 小时前
SpringBoot如何实现缓存预热?
java·spring boot·spring·缓存·程序员
暮湫9 小时前
泛型(2)
java
超爱吃士力架9 小时前
邀请逻辑
java·linux·后端
南宫生9 小时前
力扣-图论-17【算法学习day.67】
java·学习·算法·leetcode·图论