2011-01-13 155 views
4

無法連接到Tomcat JMX實例連接到Tomcat JMX服務器無法

好吧,我現在我堅持 - 我試着與Tomcat的配置JMX如下

$CATALINA_BASE/setenv.sh

CATALINA_OPTS="-Dcom.sun.management.jmxremote.port=18070 -Dcom.sun.management.jmxremote.password.file=$CATALINA_BASE/conf/jmxremote.password -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.access.file=$CATALINA_BASE/conf/jmxremote.access" 
export CATALINA_OPTS 

$CATALINA_BASE/conf/jmxremote.password

monitorRole monitorpass 
    controlRole controlpass 

$CATALINA_BASE/conf/jmxremote.access

monitorRole readonly 
    controlRole readwrite 

我用來訪問Tomcat JMX服務器的客戶端工具與Tomcat實例在同一臺機器上運行。當我啓動tomcat我可以看到,也有一些是在聽端口18070,但是當我嘗試連接,我收到以下錯誤

Exception in thread "main" java.lang.SecurityException: Authentication failed! Credentials required 
      at com.sun.jmx.remote.security.JMXPluggableAuthenticator.authenticationFailure(JMXPluggableAuthenticator.java:193) 
      at com.sun.jmx.remote.security.JMXPluggableAuthenticator.authenticate(JMXPluggableAuthenticator.java:145) 
      at sun.management.jmxremote.ConnectorBootstrap$AccessFileCheckerAuthenticator.authenticate(ConnectorBootstrap.java:185) 
      at javax.management.remote.rmi.RMIServerImpl.doNewClient(RMIServerImpl.java:213) 

我連接使用下面的代碼位

  try { 
       url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:18070/jmxrmi"); 
       jmxc = JMXConnectorFactory.connect(url,null); 
       mbsc = jmxc.getMBeanServerConnection();    
      } catch (MalformedURLException e) { 
       throw new Exception(methodName + ":" + e); 
      } catch (IOException e) { 
       throw new Exception(methodName + ":" + "Failed to connect to the Tomcat Server " + e); 
      } 

它的工作原理很好,如果我設置com.sun.management.jmxremote.authenticate = true爲false。除此之外,它只是失敗。客戶端工具與tomcat實例在同一臺機器上運行,因此防火牆不應該存在任何問題。任何線索

回答

3

JMXServiceURL url = ...; 
Map env = ...; 
String[] creds = {"monitorRole", "mrpasswd"}; 
env.put(JMXConnector.CREDENTIALS, creds); 
JMXConnector cc = JMXConnectorFactory.connect(url, env); 
MBeanServerConnection mbsc = cc.getMBeanServerConnection(); 

http://blogs.oracle.com/lmalventosa/entry/jmx_authentication_authorization

應該幫助

+0

哦,我不知道,我不得不提供從客戶端的憑據。我認爲Tomcat會從密碼文件中讀取它們。我會嘗試上面的例子謝謝。 – ziggy 2011-01-13 14:00:28