【问题标题】:Connection to Tomcat JMX server failing连接到 Tomcat JMX 服务器失败
【发布时间】:2011-01-13 13:21:04
【问题描述】:

无法连接到 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 实例在同一台机器上运行,因此防火墙应该没有任何问题。任何线索

【问题讨论】:

    标签: java tomcat jakarta-ee jmx


    【解决方案1】:

    这个

    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

    应该有帮助

    【讨论】:

    • 哦,我不知道我必须从客户端提供凭据。我以为 Tomcat 会从密码文件中读取它们。我会试试上面的例子谢谢。
    • 但这就是威胁 - 可以读取和操作 VM 的客户端应该被授权这样做。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 2016-06-12
    • 1970-01-01
    相关资源
    最近更新 更多