有没有人能使用远程JMX JConsole来工作? [英] Has anyone ever got a remote JMX JConsole to work?
问题描述
似乎过去我从来没有做过这项工作.目前,我知道它不起作用.
It seems that I've never got this to work in the past. Currently, I KNOW it doesn't work.
但是我们开始我们的Java流程:
But we start up our Java process:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=6002
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
我可以远程登录到端口,并且那里有东西"(即,如果我不启动该进程,则没有任何答案,但是如果我这样做,则可以),但是我无法让JConsole进行填充在IP和端口中.
I can telnet to the port, and "something is there" (that is, if I don't start the process, nothing answers, but if I do, it does), but I can not get JConsole to work filling in the IP and port.
似乎应该是如此简单,但是没有错误,没有噪音,什么也没有.只是不起作用.
Seems like it should be so simple, but no errors, no noise, no nothing. Just doesn't work.
有人知道这个热门提示吗?
Anyone know the hot tip for this?
推荐答案
我对此有一个解决方案:
I have a solution for this:
如果您的 Java进程在防火墙后的Linux上运行,并且您想在本地计算机上的Windows上启动 JConsole/Java VisualVM/Java Mission Control 进行连接到Java进程的 JMX端口.
If your Java process is running on Linux behind a firewall and you want to start JConsole / Java VisualVM / Java Mission Control on Windows on your local machine to connect it to the JMX Port of your Java process.
您需要通过SSH登录访问您的linux计算机.所有通信将通过SSH连接建立隧道.
You need access to your linux machine via SSH login. All Communication will be tunneled over the SSH connection.
提示:无论是否有防火墙,此解决方案都有效.
TIP: This Solution works no matter if there is a firewall or not.
缺点::每次重新启动 Java进程时,您都需要再次执行4-9的所有步骤.
Disadvantage: Everytime you restart your java process, you will need to do all steps from 4 - 9 again.
http://www.chiark.greenend.org.uk /~sgtatham/putty/download.html
至少 putty.exe
<jmx-remote-port>
示例:
jmx-remote-port = 15666
必须完全像这样完成.如果按以下方式完成操作,则它适用于防火墙后的Linux计算机(它是-Djava.rmi.server.hostname=localhost
参数的原因).
This must be done exactly like this. If its done like below, it works for linux Machines behind firewalls (It works cause of the -Djava.rmi.server.hostname=localhost
argument).
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=<jmx-remote-port>
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=localhost
示例:
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=15666 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=localhost ch.sushicutta.jmxremote.Main
ps -ef | grep <java-processname>
result ---> <process-id>
示例:
ps -ef | grep ch.sushicutta.jmxremote.Main
result ---> 24321
java进程在linux机器上打开一个新的TCP端口,RMI Server-Stubs可在此处下载.还需要通过SSH隧道提供此端口,以建立与Java虚拟机的连接.
The java process opens a new TCP Port on the linux machine, where the RMI Server-Stubs will be available for download. This port also needs to be available via SSH Tunnel to get a connection to the Java Virtual Machine.
使用netstat -lp
可以找到此端口,并且lsof -i
可以提示已从Java进程打开了哪个端口.
With netstat -lp
this port can be found also the lsof -i
gives hints what port has been opened form the java process.
注意:启动Java进程时,此端口始终更改.
netstat -lp | grep <process-id>
tcp 0 0 *:<jmx-remote-port> *:* LISTEN 24321/java
tcp 0 0 *:<rmi-server-port> *:* LISTEN 24321/java
result ---> <rmi-server-port>
示例:
netstat -lp | grep 24321
tcp 0 0 *:15666 *:* LISTEN 24321/java
tcp 0 0 *:37123 *:* LISTEN 24321/java
result ---> 37123
Source port: <jmx-remote-port>
Destination: localhost:<jmx-remote-port>
[x] Local
[x] Auto
Source port: <rmi-server-port>
Destination: localhost:<rmi-server-port>
[x] Local
[x] Auto
示例:
Source port: 15666
Destination: localhost:15666
[x] Local
[x] Auto
Source port: 37123
Destination: localhost:37123
[x] Local
[x] Auto
打开腻子会话.
登录后,Putty将通过SSH端口22将所有TCP连接隧道传输到linux计算机.
When you are logged in, Putty will tunnel all TCP-Connections to the linux machine over the SSH port 22.
JMX端口:
Windows machine: localhost:15666 >>> SSH >>> linux machine: localhost:15666
RMIServer-Stub-Port:
RMIServer-Stub-Port:
Windows Machine: localhost:37123 >>> SSH >>> linux machine: localhost:37123
这可行,因为JConsole/Java VisualVM/Java Mission Control认为您已连接到本地Windows计算机上的端口.但是Putty会将所有负载发送到Linux机器的端口15666.
This works, cause JConsole / Java VisualVM / Java Mission Control thinks you connect to a Port on your local Windows machine. but Putty send all payload to the port 15666 to your linux machine.
首先在linux机器上,java进程给出答案并发回RMIServer端口.在此示例37123.
On the linux machine first the java process gives answer and send back the RMIServer Port. In this example 37123.
然后,JConsole/Java VisualVM/Java Mission Control认为它已连接到localhost:37123,而腻子会将整个有效负载发送到linux机器上
Then JConsole / Java VisualVM / Java Mission Control thinks it connects to localhost:37123 and putty will send the whole payload forward to the linux machine
java进程回答并且连接已打开.
The java Process answers and the connection is open.
[x] Remote Process:
service:jmx:rmi:///jndi/rmi://localhost:<jndi-remote-port>/jmxrmi
示例:
[x] Remote Process:
service:jmx:rmi:///jndi/rmi://localhost:15666/jmxrmi
这篇关于有没有人能使用远程JMX JConsole来工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!