我用的是JDK11 /usr/lib/jvm/java-11-openjdk-amd64
上面是官方的快速启动用例
我下载的版本是4.8.0
1.no such directory
执行这条命令时发现 cd distribution/target/apache-rocketmq
no such directory
谷歌之后知道新的目录应该是:
/opt/rocketmq/distribution/target/rocketmq-4.8.0-SNAPSHOT/rocketmq-4.8.0-SNAPSHOT
2.Please set the JAVA_HOME variable in your environment, We need java(x64)!
一共有三个bash 都改成下图所示的样子
这三个bash路径是 bin/runserver.sh bin/runbroker.sh bin/tools.sh
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
#[ ! -e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)!"
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
也就是注释掉原先的 JAVA_HOME 并且新写一个
前两个问题都很好解决,但是之后的两个问题都要查好久我这里给出了我的解决方案希望大家踩坑的时候可以看到以便节约时间
3.is not supported. Use -classpath instead. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
大致的意思是JVM启动失败然后退出了,默认参数都是JDK8的我用的11所以需要改下参数
runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
#JAVA_OPT="${JAVA_OPT} -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:-UseParNewGC"
JAVA_OPT="${JAVA_OPT} -verbose:gc -Xlog:gc:${GC_LOG_DIR}/rmq_srv_gc_%p_%t.log"
#JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m"
JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow"
JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages"
#JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib"
#JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"
runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"
JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRUPolicyMSPerMB=0"
JAVA_OPT="${JAVA_OPT} -verbose:gc -Xlog:gc:${GC_LOG_DIR}/rmq_broker_gc_%p_%t.log"
#JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m"
JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow"
JAVA_OPT="${JAVA_OPT} -XX:+AlwaysPreTouch"
JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=15g"
JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages -XX:-UseBiasedLocking"
#JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib"
#JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"
tools.sh
AVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn64m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m"
#JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${BASE_DIR}/lib:${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext"
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"
解决了这一步之后我开心的输入命令sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
启动一下生产者的测试用例
然后报了这个错误
Could not find or load main class org.apache.rocketmq.example.quickstart.Producer
为什么找不到类呢
转头想起来JPS看下启动了哪些线程
发现就一个jps
运行这个命令nohup sh bin/mqnamesrv &
Error: Unable to initialize main class org.apache.rocketmq.namesrv.NamesrvStartup
Caused by: java.lang.NoClassDefFoundError: org/apache/rocketmq/srvutil/ShutdownHookThread
[1]+ Exit 1 nohup sh bin/mqnamesrv
发现好像根本没有启动起来
classpath需要改一下
export CLASSPATH=${BASE_DIR}/lib/rocketmq-namesrv-4.8.0.jar:${BASE_DIR}/lib/*:${BASE_DIR}/conf:${CLASSPATH}
然后再跑一下测试用例的生产者消费者都没有问题了
Broker 怎么都启动不起来
删掉~/store即可
org.apache.rocketmq.client.exception.MQClientException: No route info of this topic: TopicTest
大概率是没关掉防火墙 关掉防火墙就可以了
但是如果用的阿里云主机也要开放端口 9876 10911 10909即可