简体   繁体   English

如何找到默认的 JMX 端口号?

[英]How to find the default JMX port number?

I am running a Java application on Java 6 VM on a remote Windows XP, on which I can run jvisualvm.exe to connect to the running application automatically.我在远程 Windows XP 上的 Java 6 VM 上运行 Java 应用程序,我可以在其上运行 jvisualvm.exe 以自动连接到正在运行的应用程序。

Now I need to connect that application from my local computer, but I don't know the JMX port number of the remote computer.现在我需要从本地计算机连接该应用程序,但我不知道远程计算机的 JMX 端口号。 Where can I find it?我在哪里可以找到它? Or, must I restart that application with some VM parameters to specify the port number?或者,我是否必须使用一些 VM 参数重新启动该应用程序以指定端口号?

After reading the question How to find the JMX port in a server , I executed the command on the remote computer在阅读了如何在服务器中查找 JMX 端口的问题后,我在远程计算机上执行了命令

netstat -apn

but got nothing.但一无所获。

Now I need to connect that application from my local computer, but I don't know the JMX port number of the remote computer.现在我需要从本地计算机连接该应用程序,但我不知道远程计算机的 JMX 端口号。 Where can I find it?我在哪里可以找到它? Or, must I restart that application with some VM parameters to specify the port number?或者,我是否必须使用一些 VM 参数重新启动该应用程序以指定端口号?

By default JMX does not publish on a port unless you specify the arguments from this page: How to activate JMX...默认情况下,JMX 不会在端口上发布,除非您从此页面指定参数: 如何激活 JMX...

-Dcom.sun.management.jmxremote # no longer required for JDK6
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.local.only=false # careful with security implications
-Dcom.sun.management.jmxremote.authenticate=false # careful with security implications

If you are running you should be able to access any of those system properties to see if they have been set:如果您正在运行,您应该能够访问任何这些系统属性以查看它们是否已设置:

if (System.getProperty("com.sun.management.jmxremote") == null) {
    System.out.println("JMX remote is disabled");
} else [
    String portString = System.getProperty("com.sun.management.jmxremote.port");
    if (portString != null) {
        System.out.println("JMX running on port "
            + Integer.parseInt(portString));
    }
}

Depending on how the server is connected, you might also have to specify the following parameter.根据服务器的连接方式,您可能还必须指定以下参数。 As part of the initial JMX connection, jconsole connects up to the RMI port to determine which port the JMX server is running on.作为初始 JMX 连接的一部分,jconsole 连接到 RMI 端口以确定 JMX 服务器在哪个端口上运行。 When you initially start up a JMX enabled application, it looks its own hostname to determine what address to return in that initial RMI transaction.当您最初启动启用 JMX 的应用程序时,它会查看自己的主机名以确定在该初始 RMI 事务中返回的地址。 If your hostname is not in /etc/hosts or if it is set to an incorrect interface address then you can override it with the following:如果您的主机名不在/etc/hosts或者它被设置为不正确的接口地址,那么您可以使用以下内容覆盖它:

-Djava.rmi.server.hostname=<IP address>

As an aside, my SimpleJMX package allows you to define both the JMX server and the RMI port or set them both to the same port.顺便说一句,我的SimpleJMX 包允许您定义JMX 服务器RMI 端口或将它们设置为相同的端口。 The above port defined with com.sun.management.jmxremote.port is actually the RMI port.上面用com.sun.management.jmxremote.port定义的端口其实就是RMI端口。 This tells the client what port the JMX server is running on.这告诉客户端 JMX 服务器正在运行的端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM