簡體   English   中英

這個用於 RMI JMX 連接的 Java 代碼有什么問題?

[英]What is wrong with this Java code for a RMI JMX connection?

這個用於 RMI JMX 連接的 Java 代碼有什么問題? 我顯然沒有嘗試連接到本地主機,但錯誤暗示我是。 在遠程服務器上,我在端口 1099(無身份驗證)上啟用了 JMX 選項。

這是我的 groovy 腳本:

import javax.management.remote.*;    
JMXServiceURL u = 
 new JMXServiceURL("service:jmx:rmi://10.222.244.185:9999/jndi/rmi://10.222.244.185:1099/jmxrmi");    
JMXConnector c = JMXConnectorFactory.connect(u);

這是我得到的錯誤:

C:\Temp>groovy jmx.gv
Caught: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Conn
ection refused to host: 10.222.244.185; nested exception is:
        java.net.ConnectException: Connection refused: connect]
java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection r
efused to host: 10.222.244.185; nested exception is:
        java.net.ConnectException: Connection refused: connect]
        at jmx.run(jmx.gv:5)
Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 10.222.244.185; nested except
ion is:
        java.net.ConnectException: Connection refused: connect]
        at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:101)
        at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185)
        ... 1 more
Caused by: java.rmi.ConnectException: Connection refused to host: 10.222.244.185; nested exception is:
        java.net.ConnectException: Connection refused: connect
        at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:97)
        ... 2 more
Caused by: java.net.ConnectException: Connection refused: connect
        ... 3 more

這是著名的java.rmi.server.hostname問題。 通常是由某些Linux發行版中的/ etc / hosts配置錯誤引起的。 127.0.0.1應該映射到localhost,而您的真實主機名應該映射到您的真實IP地址。 有關其他解決方案,請參見RMI常見問題解答中的項目A.1。

編輯:既然您已經編輯了問題中的IP地址,則很有可能您正在查找的JMX服務根本不在該IP地址上運行。

您的代碼以某種方式嘗試連接到127.0.0.1而不是遠程

Connection refused to host: 127.0.0.1; nested exception is:

我懷疑您正在執行的代碼與有問題的代碼不同。 確保所執行的代碼是什么。

這是更多的配置問題,您必須明確提及您將如何訪問存根。 嘗試通過 JVM 參數設置 jmxremote 選項。 以下選項可能會解決您的問題。 我為自己的項目嘗試了同樣的方法。

-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=8091
-Dcom.sun.management.jmxremote.rmi.port=8091
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM