现在,我需要从本地计算机连接该应用程序,但是我不知道远程计算机的JMX端口号。在哪里可以找到它?或者,是否必须使用某些VM参数重新启动该应用程序以指定端口号?
默认情况下,除非您在此页面上指定参数,否则JMX不会在端口上发布:如何激活JMX…
-Dcom.sun.management.jmxremote-Dcom.sun.management.jmxremote.port=9010-Dcom.sun.management.jmxremote.local.only=false-Dcom.sun.management.jmxremote.authenticate=false
如果您正在运行,则应该能够访问这些系统属性中的任何一个,以查看是否已设置它们:
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)); }}根据服务器的连接方式,您可能还必须指定以下参数。作为初始JMX连接的一部分,jconsole连接到RMI端口,以确定JMX服务器在哪个端口上运行。最初启动启用JMX的应用程序时,它将查找自己的主机名,以确定在该初始RMI事务中返回什么地址。如果您的主机名不在
/etc/hosts或设置为不正确的接口地址,则可以使用以下命令覆盖它:
-Djava.rmi.server.hostname=<IP address>
顺便说一句,我的SimpleJMX软件包允许您定义JMX服务器和RMI端口,或者将它们都设置为同一端口。上面定义
com.sun.management.jmxremote.port的端口实际上是RMI端口。这告诉客户端JMX服务器在哪个端口上运行。



