开源版 rocketmq 安装教程及问题解决

Attson Lv3

一、安装和启动

环境 (在不同环境下表现会有些差异)

  • Ubuntu 20.04
  • rocketmq 版本 4.8.0
  • jdk11
  • bash

步骤

1. 下载源码包 && 编译

1
2
3
4
5
6
7
8
9
10
11
12
13
apt install maven

git clone https://github.com/apache/rocketmq.git

cd rocketmq

mvn -Prelease-all -DskipTests clean install -U

// build完成后在 distribution/target/rocketmq-4.8.0/rocketmq-4.8.0

// 移动软件包到 /usr/local
mv distribution/target/rocketmq-4.8.0/rocketmq-4.8.0 /usr/local
cd /usr/local/rocketmq-4.8.0/bin

2. 启动 mqnamesrv mqbroker

主要执行程序

  • mqnamesrv
  • mqbroker

启动 mqnamesrv

./mqnamesrv

mqnamesrv 启动成功

启动 mqborker

./mqbroker -n localhost:9876

  • -n, --namesrvAddr 默认 localhost:9876

mqbroker 启动成功

测试服务是否正常

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

Producer 测试成功

Consumer 测试成功

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

3. 安装图形界面

https://github.com/apache/rocketmq-externals.git

rocketmq-console

1
2
3
4
5
mvn clean package -Dmaven.test.skip=true
cd target
mv rocketmq-console-ng-2.0.0.jar /usr/local/
cd /usr/local
java -jar rocketmq-console-ng-2.0.0.jar

成功界面

  • 默认 localhost:8080

常见问题

1. Use -classpath instead:

1
2
3
4
5
root@qjue:/usr/local/rocketmq-4.8.0/bin# ./mqnamesrv
/usr/local/rocketmq-4.8.0/bin/runserver.sh: 70: [[: not found
-Djava.ext.dirs=/usr/lib/jvm/java-1.11.0-openjdk-amd64/jre/lib/ext:/usr/local/rocketmq-4.8.0/bin/../lib:/usr/lib/jvm/java-1.11.0-openjdk-amd64/lib/ext is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

这是因为在java11+ 已经默认移除jre

  • 删除 JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib"
  • 删除 export CLASSPATH=.:${BASE_DIR}/conf:${CLASSPATH}
  • 增加 export CLASSPATH=${BASE_DIR}/lib/rocketmq-namesrv-4.5.0.jar:${BASE_DIR}/lib/*:${BASE_DIR}/conf:${CLASSPATH}

2. 启动broker失败 Not enough space || Cannot allocate memory

默认申请的内存大于本机器的可用内存

找到对应的执行文件 runserver.sh || runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

  • 修改一下相关配置 JAVA_OPT="${JAVA_OPT} -server -Xms521m -Xmx521m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

3. -Xloggc is deprecated.

// broker -> rmq_broker_gc_%p_%t.log
// server -> rmq_srv_gc_%p_%t.log

  • 删除 JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:${GC_LOG_DIR}/rmq_broker_gc_%p_%t.log
  • 增加 JAVA_OPT="${JAVA_OPT} -Xlog:gc*:file=${GC_LOG_DIR}/rmq_broker_gc_%p_%t.log:time,tags:filecount=5,filesize=30M"

4. 启动broker失败 Could not create the Java Virtual Machine

1
2
3
4
5
root@qjue:/usr/local/rocketmq-4.8.0/bin# ./mqbroker -n localhost:9876
[0.001s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:/dev/shm/rmq_broker_gc_%p_%t.log instead.
Unrecognized VM option 'PrintGCDateStamps'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
  • 删除 runbroker JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m"

5. 启动 tools Producer 失败 connect to null failed tool.sh

  • tool.sh export部分 增加export NAMESRV_ADDR=localhost:9876

6. [[: not found

[[: not found 是因为 mqnamesrv.sh 使用sh 启动了 runserver.sh sh 不支持 "if [[ "

  • mqnamesrv.sh sh ${ROCKETMQ_HOME}/bin/runserver.sh 修改成 bash ${ROCKETMQ_HOME}/bin/runserver.sh
  • 标题: 开源版 rocketmq 安装教程及问题解决
  • 作者: Attson
  • 创建于 : 2021-06-15 23:20:01
  • 更新于 : 2024-08-14 18:51:33
  • 链接: https://attson.github.io/p/rocketmq.html
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
 评论