docker安装rocketmq遇到的坑(外部无法连接)

docker安装rocketmq遇到的坑

跟着网上的教程在虚拟机的docker安装了RocketMQ,安装了NameServer和Broker以及控制台,在本机上也成功访问了控制台,但是使用java程序连接RocketMQ测试连接不上,出现了错误

org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout
	at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendDefaultImpl(DefaultMQProducerImpl.java:640)
	at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:1310)
	at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:1256)
	at org.apache.rocketmq.client.producer.DefaultMQProducer.send(DefaultMQProducer.java:339)
	at com.hzy.rocketmq.rocketmqtransaction.client.RocketMQClient.defaultMQProducer(RocketMQClient.java:48)
	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.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:363)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:307)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:414)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:843)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
2019-05-30 11:10:57.343	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
  INFO	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
 3952 	at com.hzy.rocketmq.rocketmqtransaction.RocketmqTransactionApplication.main(RocketmqTransactionApplication.java:10)
--- [lientSelector_1] RocketmqRemoting                         : closeChannel: close the connection to remote address[] result: true

连接超时,初步猜测
可能原因一:是端口之类的东西没开放,但是查看centos上网路防火墙也未开启,排除端口未开放问题;
可能原因二:broker已经启动成功,可能注册的ip有误
①查看管理页面的集群列表:http://172.xxx.xxx.251:8080/#/cluster,发现broker的地址是10.244.0.11,这个是服务器内网地址
在这里插入图片描述

原因可以参考:https://blog.csdn.net/huang_550/article/details/90693656
我遇到的问题是原因二。
那就需要进入容器去修改容器里面的配置和重启容器,这里使用的是的是Rocket4.4.0。

问题解决:

1. 启动NameServer容器

docker run -d -p 9876:9876 -v /root/data/namesrv/logs:/root/logs -v /root/data/namesrv/store:/root/store --name rmqnamesrv -e "MAX_POSSIBLE_HEAP=100000000" rocketmqinc/rocketmq:4.4.0 sh mqnamesrv

2.启动broker

docker run -d -p 10911:10911 -p 10909:10909 -v /root/data/broker/logs:/root/logs -v /root/data/broker/store:/root/store --name rmqbroker --link rmqnamesrv:namesrv -e "NAMESRV_ADDR=namesrv:9876" -e "MAX_POSSIBLE_HEAP=200000000" rocketmqinc/rocketmq:4.4.0 sh mqbroker  -c ../conf/broker.conf

说明:关于安装和启动可以参考https://blog.csdn.net/javahighness/article/details/90708210
需要注意的是启动broker的时候后面加入参数 -c …/conf/broker.conf,这样后面进入容器修改的配置才有效

3.进入容器,修改了配置

docker exec -it --user root rmqbroker bash
cd ../conf
vi broker.conf

修改结果:
docker安装rocketmq遇到的坑(外部无法连接)_第1张图片

**注意:**这里rmqbroker是我的容器名称,要使用root权限进入,不然可能无法修改broker.conf文件,在文件中添加 brokerIP1 = xxx.xxx.xxx.xxx等号后面是docker宿主的出网地址,比如docker安装在虚拟机上,那就是你连接虚拟机时的地址

4.重启broker,再启动控制台
访问控制台可以看到修改成功后地址变化
docker安装rocketmq遇到的坑(外部无法连接)_第2张图片
问题解决参考:https://www.cnblogs.com/pc-m/p/11046848.html

你可能感兴趣的:(docker安装rocketmq遇到的坑(外部无法连接))