简体   繁体   English

如何确定当前正在使用的远程RMI服务器端口

[英]How to determine remote RMI server port currently in use

I have a java process running (on java 7) on some remote server that I want to monitor using Java Mission Control. 我有一个Java进程正在某个远程服务器上运行(在Java 7上),我想使用Java Mission Control对其进行监视。 However, JMC is unable to connect, although I can telnet to the server using the port jmx remote port (12345 here, see below). 但是,尽管我可以使用端口jmx远程端口(此处为12345,请参见下面)远程登录服务器,但是JMC无法连接。

The remote java proces is started with 远程Java过程以

-Dcom.sun.management.jmxremote=true 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.port=12345 
-Djava.rmi.server.hostname=<some ip address>
-Dcom.sun.management.jmxremote.authenticate=false

and these seem to be correct values to me. 这些对我来说似乎是正确的价值观。 Port 12345 has been opened on the firewall, but I suspect that the rmi server port is blocked by the firewall. 端口12345已在防火墙上打开,但是我怀疑rmi服务器端口已被防火墙阻止。

Thus, my question is: Is there any way (using netstat on the server or maybe even telnet from the client) to determine which rmi server port the java process is currently using on the server? 因此,我的问题是:是否有任何方法(在服务器上使用netstat或甚至从客户端使用telnet)来确定Java进程当前在服务器上使用的rmi服务器端口? (Using netstat, I see several ports being used by the java process. However, I don't have a clue which one is the rmi port.) (使用netstat,我看到java进程正在使用多个端口。但是,我不知道哪个端口是rmi端口。)

This should display where a JMX remote client is told to connect to (plus some internal info) possibly after timing out: 这应该显示JMX远程客户端可能在超时后被告知要连接的位置(以及一些内部信息):

//nopackage -- move if you like
import java.rmi.Remote;
import java.rmi.registry.*;
import java.rmi.server.*;
import sun.rmi.server.UnicastRef;
import sun.rmi.transport.LiveRef;

public class JMXTarget {
    /*
     * run: java JMXTarget host port
     * where host (name or address) contains the JVM process offering JMX
     * and port (number) is the registry specified by -Dcom.sun.management.jmxremote.port 
     */
    public static void main(String[] args) throws Exception {
        Registry reg = LocateRegistry.getRegistry (args[0], Integer.parseInt(args[1]));
        Remote r = reg.lookup ("jmxrmi");
        RemoteObject ro = (RemoteObject)r; 
        RemoteRef rr = ro.getRef();
        UnicastRef ur = (UnicastRef)rr;
        LiveRef lr = ur.getLiveRef();
        System.out.println (lr);
    }
}

Note if sysprop java.rmi.server.hostname is specified as you did, its value (your "some ip address") is where the client connects. 请注意,如果像您一样指定sysprop java.rmi.server.hostname ,则它的值(您的“某些IP地址”)是客户端连接的位置。 If that value is not an address of the target machine, or a name that resolves (for the client) to an address of the target machine, it won't connect. 如果该值不是目标计算机的地址,或者不是(对于客户端)解析为目标计算机的地址的名称,则它将不会连接。 If you don't specify it, it defaults to (edit) the value determined by InetAddress.getLocalHost() which is or at least should be a valid address for that machine. 如果未指定,则默认为(编辑)InetAddress.getLocalHost()确定的值,该值至少应为该计算机的有效地址。

Adding '-Dcom.sun.management.jmxremote.rmi.port=12345' could help 添加'-Dcom.sun.management.jmxremote.rmi.port = 12345'可能会有所帮助

See Why Java opens 3 ports when JMX is configured? 请参阅为什么在配置JMX时Java打开3个端口?

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

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