jmx无法连接到localhost

时间:2014-04-22 03:45:22

标签: java-ee tomcat jmx

尝试连接简单的JMX监控。托管应用程序和监视工具位于同一服务器上。尝试连接错误时

  

00:30:54,610致命http-8080-6 SiteListener:makeJmxConnection:99 -   java.io.IOException:无法检索RMIServer存根:   javax.naming.ServiceUnavailableException [根异常是   java.rmi.ConnectException:连接拒绝主机:localhost;   嵌套异常是:java.net.ConnectException:连接被拒绝]     在javax.management.remote.rmi.RMIConnector.connect(未知来源)     在javax.management.remote.JMXConnectorFactory.connect(未知   来源)at   com.m.a.s.SiteListener.makeJmxConnection(SiteListener.java:93)at   com.m.a.s.SiteListener.getMBeanConnect(SiteListener.java:73)at at   com.m.a.s.SiteListener.contextInitialized(SiteListener.java:51)at   org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)     在   org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)     在   org.apache.catalina.core.StandardContext.reload(StandardContext.java:3228)     在   org.apache.catalina.manager.ManagerServlet.reload(ManagerServlet.java:918)     在   org.apache.catalina.manager.HTMLManagerServlet.reload(HTMLManagerServlet.java:545)     在   org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:121)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:617)at   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:558)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)     在   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)     在   org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:588)     在   org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:489)     在java.lang.Thread.run(未知来源)引起:   javax.naming.ServiceUnavailableException [根异常是   java.rmi.ConnectException:连接拒绝主机:localhost;   嵌套异常是:java.net.ConnectException:连接被拒绝]     at com.sun.jndi.rmi.registry.RegistryContext.lookup(Unknown Source)     at com.sun.jndi.toolkit.url.GenericURLContext.lookup(Unknown Source)     在javax.naming.InitialContext.lookup(未知来源)at   javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(未知   来源)at   javax.management.remote.rmi.RMIConnector.findRMIServer(未知来源)     ... 26更多引起:java.rmi.ConnectException:连接被拒绝   主持人:localhost;嵌套异常是:java.net.ConnectException:   连接拒绝了   sun.rmi.transport.tcp.TCPEndpoint.newSocket(未知来源)at   sun.rmi.transport.tcp.TCPChannel.createConnection(未知来源)at   sun.rmi.transport.tcp.TCPChannel.newConnection(未知来源)at   sun.rmi.server.UnicastRef.newCall(未知来源)at   sun.rmi.registry.RegistryImpl_Stub.lookup(未知来源)......还有31个   引起:java.net.ConnectException:拒绝连接   java.net.PlainSocketImpl.socketConnect(Native Method)at   java.net.AbstractPlainSocketImpl.doConnect(未知来源)at   java.net.AbstractPlainSocketImpl.connectToAddress(未知来源)at   java.net.AbstractPlainSocketImpl.connect(未知来源)at   java.net.SocksSocketImpl.connect(未知来源)at   java.net.Socket.connect(未知来源)at   java.net.Socket.connect(未知来源)at   java.net.Socket。(未知来源)at   java.net.Socket。(未知来源)at   sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(未知   来源)at   sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(未知   来源)......还有36个

在服务器上,打开访问权限

 private static void startJmxServer() throws MalformedURLException, IOException {

        Map<String, Object> props = new HashMap<String, Object>();
        RemouteAuthentificator auth = new RemouteAuthentificator();
        props.put("jmx.remote.authenticator", auth);

        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:22414/MServer");
        MBeanServer mbeanSrv = ManagementFactory.getPlatformMBeanServer();
        JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, props, mbeanSrv);
        server.start();
        log.info("JMX RMI Agent has been bound on address: " + url);
    }

在Tomcat下的管理工具中,尝试连接

static private MBeanServerConnection makeJmxConnection(String objectName)
    {
    // objectName = “MServer:name=Settings”;
        MBeanServerConnection mConnect = null;
        try
        {
            String[] credentials = new String[] {"server", "password"};
            Map<String, String[]> props = new HashMap<String, String[]>();
            props.put("jmx.remote.credentials", credentials);

            JMXServiceURL url = new JMXServiceURL(“service:jmx:rmi:///jndi/rmi://localhost:22414/MServer”);
            jmxc = JMXConnectorFactory.connect(url, props);
            mConnect = jmxc.getMBeanServerConnection();
            mbeanName = new ObjectName(objectName);
        }
        catch(Exception e)
        {
            log.fatal("", e);
        }

        return mConnect;
    }

并试图通过外部IP连接。结果是一样的。

1 个答案:

答案 0 :(得分:0)

我不知道你在哪里设置你的号码。你在哪里这么短的代码

String host = "localhost";  // or some x.y.z
int port = setyourPortNumber;
String url = "service:jmx:rmi:///jndi/rmi://localhost:22414/MServer"; // where you get services

我希望它可以帮助你理解