搭建rocketMQ

下载并编译

1. 下载源码包https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.4.0/rocketmq-all-4.4.0-source-release.zip

2. 解压unzip rocketmq-all-4.4.0-source-release.zip

3. 进入目录cd rocketmq-all-4.4.0/

4. 打包mvn -Prelease-all -DskipTests clean install -U

5. 进入目录cd distribution/target/apache-rocketmq

 

Start Name Server

1. 后台启动nohup sh bin/mqnamesrv &

2. 观察日志tail -f ~/logs/rocketmqlogs/namesrv.log,可以看到启动成功日志

 

Start broker

1. 启动nohup sh bin/mqbroker -n localhost:9876 &

2. 查看日志tail -f nohup.out

  The broker[page-virtual-machine, 172.17.0.1:10911] boot success. serializeType=JSON and name server is localhost:9876

 

Send & Receive Messages

1. 设置环境变量:export NAMESRV_ADDR=localhost:9876

2. 发送消息:sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer

3. 接收消息:sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer

 

Shutdown Servers

1. sh bin/mqshutdown broker

2. sh bin/mqshutdown namesrv

 

为方便查看,可以搭建管理页面

1. 下载https://github.com/apache/rocketmq-externals

2. 进入rocketmq-console目录

3. 打包mvn clean package -Dmaven.test.skip=true

4. 启动java -jar target/rocketmq-console-ng-1.0.1.jar

5. 查看管理界面http://localhost:8080

 

 

遇到的问题:

1. Error: Could not find or load main class org.apache.rocketmq.namesrv.NamesrvStartup

distribution目录下的bin启动位置和distribution目录下的target下的bin启动位置搞错

2. 启动broker时,报:Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, 8589934592, 0) failed; error='Cannot allocate memory' (errno=12)

  分配的内存不够,修改runbroker.sh,JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -Xmn2g"

管理页面:

1. 

[2019-11-22 15:12:44.412] ERROR op=global_exception_handler_print_error
java.lang.NullPointerException: null
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:213)
    at com.google.common.base.Splitter.splitToList(Splitter.java:416)
    at org.apache.rocketmq.console.service.impl.OpsServiceImpl.homePageInfo(OpsServiceImpl.java:43)
    at org.apache.rocketmq.console.controller.OpsController.homePage(OpsController.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:220)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)

 

修改application.properties文件中的配置为rocketmq.config.namesrvAddr=localhost:9876

 

3. 宿主机无法访问虚拟机的管理页面,是因为没放开端口,切换到root下执行

iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

 

posted @ 2019-11-18 20:25  到三国卖栗子  阅读(868)  评论(0编辑  收藏  举报