Windows在jdk11环境下运行RocketMQ
0. 环境
- windows11
- jdk11
- rocketmq4.9.4
PS:
其他版本的rocketmq也可以参考此方式,其他版本如果下面方式不行,可自行根据报错注释一些脚本中jvm启动的参数再次尝试
修改jvm启动内存,大家可以根据自己的电脑配置自行斟酌
jdk11环境下,rocketmq启动命令需要修改才能启动,因为rocketmq在runbroker.cmd和runserver.cmd中启动的时候都指定了垃圾回收机制等jvm参数,默认在jdk8上运行是可以的,如果想在jdk11环境下运行需要修改以下参数:
1. 修改%ROCKETMQ_HOME%/bin/runserver.cmd
set CLASSPATH=.;%BASE_DIR%conf;%BASE_DIR%lib\*;%CLASSPATH%
# 1. 修改jvm启动内存
set "JAVA_OPT=%JAVA_OPT% -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
# 2. 注释以下2行
rem set "JAVA_OPT=%JAVA_OPT% -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:-UseParNewGC"
rem set "JAVA_OPT=%JAVA_OPT% -verbose:gc -Xloggc:"%USERPROFILE%\rmq_srv_gc.log" -XX:+PrintGCDetails -XX:+PrintGCDateStamps"
set "JAVA_OPT=%JAVA_OPT% -XX:-OmitStackTraceInFastThrow"
set "JAVA_OPT=%JAVA_OPT% -XX:-UseLargePages"
set "JAVA_OPT=%JAVA_OPT% -cp "%CLASSPATH%""
"%JAVA%" %JAVA_OPT% %*
2. 修改%ROCKETMQ_HOME%/bin/runbroker.cmd
rem ===========================================================================================
rem JVM Configuration
rem ===========================================================================================
# 1. 修改jvm启动内存
set "JAVA_OPT=%JAVA_OPT% -server -Xms256m -Xmx256m"
# 2. 注释以下3行
rem set "JAVA_OPT=%JAVA_OPT% -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRUPolicyMSPerMB=0 -XX:SurvivorRatio=8"
rem set "JAVA_OPT=%JAVA_OPT% -verbose:gc -Xloggc:%USERPROFILE%\mq_gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy"
rem set "JAVA_OPT=%JAVA_OPT% -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m"
set "JAVA_OPT=%JAVA_OPT% -XX:-OmitStackTraceInFastThrow"
set "JAVA_OPT=%JAVA_OPT% -XX:+AlwaysPreTouch"
set "JAVA_OPT=%JAVA_OPT% -XX:MaxDirectMemorySize=15g"
set "JAVA_OPT=%JAVA_OPT% -XX:-UseLargePages -XX:-UseBiasedLocking"
set "JAVA_OPT=%JAVA_OPT% -cp %CLASSPATH%"
"%JAVA%" %JAVA_OPT% %*
3. 配置环境变量
NAMESRV_ADDR = 127.0.0.1:9876
ROCKETMQ_HOME = D:\develop\rocketmq\rocketmq-all-4.9.4-bin-release
4. 启动mqnamesrv.cmd
路径:%ROCKETMQ_HOME %\bin
使用命令行执行以下命令
start mqnamesrv.cmd
5. 启动mqbroker.cmd
路径:%ROCKETMQ_HOME %\bin
使用命令行执行以下命令
start mqbroker.cmd -n localhost:9876 autoCreateTopicEnable=true
6. 启动接收者
start tools.cmd org.apache.rocketmq.example.quickstart.Consumer
7. 启动发送方
start tools.cmd org.apache.rocketmq.example.quickstart.Producer