1.到apache官网下载binary zip包: apache官网
2.解压zip包:
unzip rocketmq-all-4.9.0-bin-release.zip
3.进入解压后的文件夹,启动 Name Server:
nohup sh bin/mqnamesrv &
启动后会有日志输出到nohup.out文件上,可以到上面去看看是否启动成功:
tail -100f nohup.out
有以下日志说明启动成功:
- 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
4.启动broker:
nohup sh bin/mqbroker -n localhost:9876 &
同样日志也是输出到nohup.out文件上,不改配置一般启动都会报以下错误:
- Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, 8589934592, 0) failed; error='Cannot allocate memory' (errno=12)
- #
- # There is insufficient memory for the Java Runtime Environment to continue.
- # Native memory allocation (mmap) failed to map 8589934592 bytes for committing reserved memory.
- # An error report file with more information is saved as:
- # /usr/sofe/rocketmq/rocketmq-all-4.9.0-bin-release/hs_err_pid6029.log
- Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, 8589934592, 0) failed; error='Cannot allocate memory' (errno=12)
- #
- # There is insufficient memory for the Java Runtime Environment to continue.
- # Native memory allocation (mmap) failed to map 8589934592 bytes for committing reserved memory.
出现该错误是因为内存配置太大了,修改下当前目录下/bin/runbroker.sh启动配置的java内存即可:
JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -Xmn1g"
再次启动出现以下说明成功了:
The broker[localhost.localdomain, 192.168.37.128:10911] boot success. serializeType=JSON and name server is localhost:9876
5.停掉rocketmq
- sh bin/mqshutdown broker
- sh bin/mqshutdown namesrv
6.测试是否可以发送和接受消息:
- 在发送和接收消息之前,客户需要识别名称服务器的地址。 RocketMQ有多种方法可以在客户端设置名称服务器地址。其中之一是修改环境变量namesrv_addr:
-
- export NAMESRV_ADDR=localhost:9876
测试发送:
- sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
-
-
测试接收:
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
以上Apache官网有rocketmq文档可以看:https://rocketmq.apache.org/docs/4.x/introduction/02quickstart