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

发布于 2024-10-17 11:20:58 字数 1959 浏览 1 评论 0原文

我使用以下代码启动我们的 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 服务器(请参阅 此处解释原因)

I am starting our JMX server using the following code:

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

On our application startup we are getting:

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

This works in windows but fails on linux. There is nothing bound to 8291. (I verified this with a netstat -anp )

Does anybody know why this is failing?

FYI. We are starting a custom JMX server because of the firewall (see here for explanation why)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞旧 2024-10-24 11:20:58

找到一条可能对您有帮助的注释

借助 Sun 的 JMX Remote JMX RI,
未使用主机名/ip-addr 段
限制目标IP地址/名称,
正如它应该的那样。它必须只匹配任何
该主机的有效 IP 地址/名称
(包括 localhost 或 127.0.0.1),
然后它会监听 IPADDR_ANY。
您将必须进行自定义编码(或
使用 IP 过滤或防火墙
产品)限制收听
地址。

因此,您似乎只需将 0.0.0.0 替换为 localhost,它仍然会侦听所有网络接口。

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

Found 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.

So it looks like you could just replace 0.0.0.0 with localhost and it would still listen on all network interfaces.

BTW, I tried your code with this change, but now I get another exception (a different one though).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文