gpt4 book ai didi

java - 在 0.0.0.0 上启动自定义 JMX 服务器时出错

转载 作者:太空狗 更新时间:2023-10-29 12:38:03 24 4
gpt4 key购买 nike

我正在使用以下代码启动我们的 JMX 服务器:

Integer port = 8291;
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://0.0.0.0:"+ (port+100) +"/jndi/rmi://0.0.0.0:"+ port +"/jmxrmi");

在我们的应用程序启动时,我们得到:

Caused by: java.rmi.ConnectException: Connection refused to host: 0.0.0.0; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at com.sun.jndi.rmi.registry.RegistryContext.bind(RegistryContext.java:120)
... 53 more
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:193)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at java.net.Socket.connect(Socket.java:475)
at java.net.Socket.<init>(Socket.java:372)
at java.net.Socket.<init>(Socket.java:186)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterS

这在 Windows 上有效,但在 Linux 上失败。 8291 没有任何限制。(我用 netstat -anp 验证了这一点)

有人知道为什么会失败吗?

仅供引用。由于防火墙的原因,我们正在启动自定义 JMX 服务器(请参阅 here 以了解原因)

最佳答案

找到 a note which might help you :

With Sun's JMX Remote JMX RI, the hostname/ip-addr segment is not used to limit the target IP address/name, as it should. It must just match any valid IP address/name for this host (including localhost or 127.0.0.1), and it will then listen to IPADDR_ANY. You will have to do custom coding (or use an IP filtering or firewall product) to limit the listen addresses.

所以看起来您可以将 0.0.0.0 替换为 localhost,它仍然会监听所有网络接口(interface)。

顺便说一句,我尝试了您的代码进行此更改,但现在我遇到了另一个异常(虽然不同)。

关于java - 在 0.0.0.0 上启动自定义 JMX 服务器时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5010217/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com