Skip to content

RocketMQ 之安装(Windows)

官方文档:https://rocketmq.apache.org/docs/quick-start/

Github: https://github.com/apache/rocketmq

Github Docker: https://github.com/apache/rocketmq-docker

DockerHub: https://hub.docker.com/r/apache/rocketmq/tags

Windows 下的安装

在 windows 上安装 RocketMQ 一般只作为新手入门玩一玩。 因为 RocketMQ 的存储设计,包括分页设计,设计上都是基于 Linux 上的。所以生产服务器推荐使用 Linux.

解压及运行前环境

使用运行版本(Binary)。运行前确保:已经有 jdk1.8 (默认支持 jdk1.8,如果要使用高版本的 jdk,需要修改启动脚本才能启动成功。)

配置环境变量

bash
ROCKETMQ_HOME="C:\Programs\rocketmq-4.9.2"
NAMESRV_ADDR="localhost:9876"

注意事项

请在 JDK 1.8 上运行。

修改虚拟机内存

RocketMQ 默认的虚拟机内存较大,启动 Broker 如果因为内存不足失败,需要编辑如下两个配置文件,修改 JVM 内存大小。

但是这个也仅仅是在测试环境中,RocketMQ 在生产上最低要求至少 8G 内存(官方推荐)才能确保 RocketMQ 的效果

编辑 runbroker.sh 和 runserver.sh 修改默认 JVM 大小(windows 上对应 cmd 文件)

vi runbroker.sh --broker 的配置

vi runserver.sh --nameServer 的配置

JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

启动脚本有坑,需要修改

当 JDK 安装在有空格的目录下,需要添加引号。这是官方启动脚本里的坑! runserver.cmd

bash
rem change memory
set "JAVA_OPT=%JAVA_OPT% -server -Xms512m -Xmx512m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
set "JAVA_OPT=%JAVA_OPT% -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:-UseParNewGC"
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"
rem 注意这里:If the JAVA_HOME path contains Spaces, add double quotation marks.
set "JAVA_OPT=%JAVA_OPT% -Djava.ext.dirs="%BASE_DIR%lib;%JAVA_HOME%\jre\lib\ext""
set "JAVA_OPT=%JAVA_OPT% -cp "%CLASSPATH%""

runbroker.cmd

bash
rem change memory
set "JAVA_OPT=%JAVA_OPT% -server -Xms512m -Xmx512m"
set "JAVA_OPT=%JAVA_OPT% -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRUPolicyMSPerMB=0 -XX:SurvivorRatio=8"
set "JAVA_OPT=%JAVA_OPT% -verbose:gc -Xloggc:%USERPROFILE%\mq_gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy"
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"
rem 注意这里:If the JAVA_HOME path contains Spaces, add double quotation marks.
set "JAVA_OPT=%JAVA_OPT% -Djava.ext.dirs="%BASE_DIR%lib;%JAVA_HOME%\jre\lib\ext""
rem 注意这里:If the CLASSPATH path contains Spaces, add double quotation marks.
set "JAVA_OPT=%JAVA_OPT% -cp "%CLASSPATH%""

启动

RocketMQ 的物理架构中,都是需要先启动 NameServer 再启动 Broker 的。所以启动顺序一定不要搞反了。

以 powershell 为例。

启动 NAMESERVER

bash
mqnamesrv.cmd

PS C:\Users\mengweijin> mqnamesrv.cmd
Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release
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

启动 BROKER

bash
mqbroker.cmd -n 127.0.0.1:9876 autoCreateTopicEnable=true

PS C:\Users\mengweijin> mqbroker.cmd -n 127.0.0.1:9876 autoCreateTopicEnable=true
The broker[DESKTOP-MDDFCRT, 192.168.5.1:10911] boot success. serializeType=JSON and name server is 127.0.0.1:9876

安装 rocketmq-dashboard

Github:https://github.com/apache/rocketmq-dashboard

DockerHub: https://hub.docker.com/r/apacherocketmq/rocketmq-dashboard/tags

Run with docker

bash
docker pull apacherocketmq/rocketmq-dashboard:latest

docker run -d --name rocketmq-dashboard --restart=always -e "JAVA_OPTS=-Drocketmq.namesrv.addr=127.0.0.1:9876" -p 8080:8080 -t apacherocketmq/rocketmq-dashboard:latest
docker run -d --name rocketmq-dashboard --restart=always -e "JAVA_OPTS=-Drocketmq.namesrv.addr=192.168.8.115:9876" -p 8089:8080 -t apacherocketmq/rocketmq-dashboard:latest