centos中安装rabbitmq作服务端,在宿主机客户端程序无法访问,显示连接超时

Rain_sun 2014-12-09 10:51:16
我在windows系统中用vmware虚拟机另装了个centos 7.0 系统。

做操作如下:

1. 我在虚拟机上部署了RabbitMQ 服务端,开放默认端口5672,已安装网页管理插件, 在虚拟机内置浏览器能够正常访问网页管理;
2. 我在主机上,用JAVA程序作为客户端,通过设置setHost(ip地址), setPort(端口号) 尝试推送消息到RabbitMQ, 一直碰到上述问题。

虚拟机中已做设置如下:
1. 关闭防火墙,关闭selinux
2. 网络连接方式已尝试过bridged、NAT、host-only

在主机上做过如下操作:
1. 终端ping过虚拟机上三种方式下的ip地址,均可以ping通
2. 在浏览器端使用ip:port的方式尝试访问虚拟机,显示连接超时
3. 在Java程序中,尝试连接虚拟机中的程序服务端,显示连接超时报错如下:

Exception in thread "main" java.net.ConnectException: Connection timed out: connect

请问,有什么设置我是没注意到的吗?
...全文
1455 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
人参米 2016-04-25
  • 打赏
  • 举报
回复
连接代码: public class Reqv { private final static String QUEUE_NAME = "hello"; public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("10.10.6.246"); factory.setUsername("guest"); factory.setPassword("guest"); factory.setPort(15672); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); System.out.println("
  • Waiting for messages. To exit press CTRL+C"
  • ); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(QUEUE_NAME, true, consumer); while(true){ QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String message = new String(delivery.getBody()); System.out.println(" [x] Received '" + message + "'"); } } } --------------------------------------------------------------------------------------------------- 报错信息: Exception in thread "main" java.io.IOException at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106) at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102) at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:360) at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:516) at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:533) at com.mq.test.Reqv.main(Reqv.java:28) Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; reason: java.net.SocketTimeoutException: Timeout during Connection negotiation at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67) at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33) at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343) at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:313) ... 3 more Caused by: java.net.SocketTimeoutException: Timeout during Connection negotiation at com.rabbitmq.client.impl.AMQConnection.handleSocketTimeout(AMQConnection.java:566) at com.rabbitmq.client.impl.AMQConnection.access$500(AMQConnection.java:59) at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:541)
人参米 2016-04-25
  • 打赏
  • 举报
回复
楼主最后是怎么解决的? 我也出现了类似的问题,解决了二天了还是没有头绪。 我浏览器可以正常连接rabbitMQ,就是用Java连接的时候出现和你一样的问题。
Rain_sun 2015-01-04
  • 打赏
  • 举报
回复
引用 14 楼 micropentium6 的回复:
I am glad you figured it out! Sometimes shit happens, don't blame too much on yourself. You are gaining experience here. Just make sure it won't happen again...
Thank you! now i am beginning to learn about Docker.
  • 打赏
  • 举报
回复
引用 13 楼 Rain_Sun 的回复:
[quote=引用 12 楼 micropentium6 的回复:] java.net.SocketTimeoutException: Timeout during Connection negotiation this looks like a java rabbitmq library issue. please double check if rabbitmq is working. If so, you will have to figure out the problem in your java code.
thank you very much! the problem has been solved for some time. it turns out the port which rabbitmq listens to is different from the one the rabbitmq web management plugin listens to. how foolish i am. [/quote] I am glad you figured it out! Sometimes shit happens, don't blame too much on yourself. You are gaining experience here. Just make sure it won't happen again...
Rain_sun 2014-12-22
  • 打赏
  • 举报
回复
引用 12 楼 micropentium6 的回复:
java.net.SocketTimeoutException: Timeout during Connection negotiation this looks like a java rabbitmq library issue. please double check if rabbitmq is working. If so, you will have to figure out the problem in your java code.
thank you very much! the problem has been solved for some time. it turns out the port which rabbitmq listens to is different from the one the rabbitmq web management plugin listens to. how foolish i am.
  • 打赏
  • 举报
回复
java.net.SocketTimeoutException: Timeout during Connection negotiation this looks like a java rabbitmq library issue. please double check if rabbitmq is working. If so, you will have to figure out the problem in your java code.
Rain_sun 2014-12-12
  • 打赏
  • 举报
回复
引用 10 楼 micropentium6 的回复:
well, iptables was never in my consideration since you said up front that iptables on VM has been turned off. let me summarize "what you did wrong": 1. rabbitmq was not configured right so it only listened on the localhost; 2. iptables was not configured right so it blocked the connection from host; removing the entire chain from iptables is not recommended. You should add this exception to the iptables instead.
Thank you for your help! I ran the command 'service iptables stop' to stop the firewall and the 'service iptables status' to check out the status of firewall, and the returning message showed that it was already inactive. Was i wrong? As for the iptables, i had already add the exception on port 5672 long before i ran the command 'iptables -F'. i wonder if it could start with the rules i set up instead of the built-in file in the vm? i searched on the internet for solutions, but in vain. by now, the program binding on the port 5672 can be accessed. but the rabbitmq-java-clients both in the host and in the vm still couldnt connect to the server, it said there was exception. Java is also a new thing to me, and i have tried to solve it out all the afternoon. Would you mind giving me some hint or some link material about learning RabbitMQ? here is the java code and the exception message. i have worked on the exception information for some time, still feel confused about it. Recever: package com.lubby.test; import com.rabbitmq.client.AMQP; import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.Connection; import com.rabbitmq.client.Channel; import com.rabbitmq.client.QueueingConsumer; public class Recv { private final static String QUEUE_NAME = "hello"; public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("192.168.41.130"); // factory.setPort(5672); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); System.out.println("
  • Waiting for messages. To exit press CTRL+C"
  • ); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(QUEUE_NAME, true, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String message = new String(delivery.getBody()); System.out.println(" [x] Received '" + message + "'"); } } } Sender: package com.lubby.test; import java.io.IOException; import com.rabbitmq.client.AMQP; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.MessageProperties; public class SendDemo01 { private final static String QUEUE_NAME = "hello"; public static void main(String[] args) throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("192.168.41.130"); factory.setPort(5672); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); String message = "Hello World"; channel.basicPublish("", QUEUE_NAME, null, message.getBytes()); System.out.println(" Sent: '" + message + "'"); channel.close(); connection.close(); } } ERROR MESSAGE: Exception in thread "main" java.io.IOException at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106) at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102) at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:348) at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:617) at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:639) at com.lubby.test.Recv.main(Recv.java:18) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) Caused by: com.rabbitmq.client.ShutdownSignalException: connection error at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67) at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33) at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343) at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:294) ... 8 more Caused by: java.net.SocketTimeoutException: Timeout during Connection negotiation at com.rabbitmq.client.impl.AMQConnection.handleSocketTimeout(AMQConnection.java:585) at com.rabbitmq.client.impl.AMQConnection.access$600(AMQConnection.java:65) at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:560) at java.lang.Thread.run(Thread.java:745)
  • 打赏
  • 举报
回复
引用 8 楼 Rain_Sun 的回复:
it works after running the arguments iptables -F and iptables -X in the vm terminal, but i am still confused about what i did wrong all these days. About the two arguments, i will figure it out why they could make such big difference to my work. And what dose the message i posted in the last comment mean? where did i neglect? Thank you!
well, iptables was never in my consideration since you said up front that iptables on VM has been turned off. let me summarize "what you did wrong": 1. rabbitmq was not configured right so it only listened on the localhost; 2. iptables was not configured right so it blocked the connection from host; removing the entire chain from iptables is not recommended. You should add this exception to the iptables instead.
Rain_sun 2014-12-11
  • 打赏
  • 举报
回复
引用 6 楼 micropentium6 的回复:
#telnet 192.168.41.130 5672
it works after running the arguments iptables -F and iptables -X in the vm terminal, but i am still confused about what i did wrong all these days. About the two arguments, i will figure it out why they could make such big difference to my work. And what dose the message i posted in the last comment mean? where did i neglect? Thank you!
Rain_sun 2014-12-11
  • 打赏
  • 举报
回复
it works after running the arguments iptables -F and iptables -X in the vm terminal, but i am still confused about what i did wrong all these days. About the two arguments, i will figure it out why they could make such big difference to my work. And what dose the message i posted in the last comment mean? where did i neglect? Thank you!
Rain_sun 2014-12-11
  • 打赏
  • 举报
回复
引用 6 楼 micropentium6 的回复:
if you do the following from the host, what's the return from: #telnet 192.168.41.130 5672
it return the message: 正在连接192.168.41.130...无法打开到主机的连接。在端口 5672: 连接失败
  • 打赏
  • 举报
回复
引用 2 楼 Rain_Sun 的回复:
[quote=引用 1 楼 micropentium6 的回复:] make sure you can ping from VM to the host and from the host to VM if it works, on your windows system telnet your_vm_ip 5672 if both procedures are successful, then the problem is isolated on RabbitMQ itself
Ping from vm to the host and from the host to vm are turned out to be successful, but the next step you mentioned "telnet vm_ip port" runs to fail. Could you please tell what i should? Thank you![/quote] that probably means your RabbitMQ is listening on localhost only. You can verify that by #netstat -ntpl | grep 5672 see if RabbitMQ is bound to 127.0.0.1
  • 打赏
  • 举报
回复
引用 5 楼 Rain_Sun 的回复:
[quote=引用 3 楼 micropentium6 的回复:] that probably means your RabbitMQ is listening on localhost only. You can verify that by #netstat -ntpl | grep 5672 see if RabbitMQ is bound to 127.0.0.1
I have tried deleting the binding ip in the rabbitmq.config file, so it can be allowed to be accessed both by 127.0.0.1:5672 and 192.168.41.130:5672 in the vm. but sadly, it is still not accessable in the host. and as for the argument "#netstat -ntpl | grep 5672", it returns the result as following sentence: tcp 0 0 192.168.41.130:5672 0.0.0.0:* LISTEN [/quote] if you do the following from the host, what's the return from: #telnet 192.168.41.130 5672
Rain_sun 2014-12-10
  • 打赏
  • 举报
回复
引用 3 楼 micropentium6 的回复:
that probably means your RabbitMQ is listening on localhost only. You can verify that by #netstat -ntpl | grep 5672 see if RabbitMQ is bound to 127.0.0.1
I have tried deleting the binding ip in the rabbitmq.config file, so it can be allowed to be accessed both by 127.0.0.1:5672 and 192.168.41.130:5672 in the vm. but sadly, it is still not accessable in the host. and as for the argument "#netstat -ntpl | grep 5672", it returns the result as following sentence: tcp 0 0 192.168.41.130:5672 0.0.0.0:* LISTEN
Rain_sun 2014-12-09
  • 打赏
  • 举报
回复
引用 1 楼 micropentium6 的回复:
make sure you can ping from VM to the host and from the host to VM if it works, on your windows system telnet your_vm_ip 5672 if both procedures are successful, then the problem is isolated on RabbitMQ itself
Ping from vm to the host and from the host to vm are turned out to be successful, but the next step you mentioned "telnet vm_ip port" runs to fail. Could you please tell what i should? Thank you!
  • 打赏
  • 举报
回复
make sure you can ping from VM to the host and from the host to VM if it works, on your windows system telnet your_vm_ip 5672 if both procedures are successful, then the problem is isolated on RabbitMQ itself

18,773

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 专题技术讨论区
社区管理员
  • 专题技术讨论区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧