基于 Putty SSH 隧道的 VisualVM

发布于 2025-01-06 01:46:10 字数 2499 浏览 6 评论 0原文

我正在尝试分析远程java应用程序,实际上它是一个游戏服务器。它在我的本地计算机(带有 JDK1.7.0_02 x64 的 Windows XP x64)上正常工作,但在生产服务器(带有 JDK1.7.0_03 i586 的 CentOS)上表现非常奇怪。

我做了很多搜索,发现我应该使用 VisualVM 来完成这项任务。因此,VisualVM 在本地计算机上运行良好,但在本地计算机上没有挂起,我需要在生产环境中使用实际负载进行分析。 参数在远程计算机上启动了 jstatd

jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.logCalls=false &

我使用策略文件的

grant codebase "file:/usr/java/jdk1.7.0_02/lib/tools.jar" {
    permission java.security.AllPermission;
};

,然后像这样启动了我的 java 应用程序

java -server -Dcom.sun.management.jmxremote\
 -Dcom.sun.management.jmxremote.port=4000\
 -Dcom.sun.management.jmxremote.ssl=false\
 -Dcom.sun.management.jmxremote.authenticate=false\
 -jar /home/pinballSocketServer/pinballSocketServer.jar

应用程序和 jstatd 都是使用 root 权限启动的。

并且 VisualVM 无​​法连接到远程主机。但是在远程主机上,当 VisualVM 正在运行并且添加了远程主机时,我看到以下日志:

Feb 16, 2012 7:11:52 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(3)-217.16.27.195: [217.16.27.195: sun.rmi.registry.RegistryImpl[0:0:0, 0]: java.rmi.Remote lookup(java.lang.String)]
Feb 16, 2012 7:11:56 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(3)-217.16.27.195: [217.16.27.195: sun.rmi.registry.RegistryImpl[0:0:0, 0]: java.rmi.Remote lookup(java.lang.String)]
Feb 16, 2012 7:12:00 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(3)-217.16.27.195: [217.16.27.195: sun.rmi.registry.RegistryImpl[0:0:0, 0]: java.rmi.Remote lookup(java.lang.String)]
Feb 16, 2012 7:12:04 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(3)-217.16.27.195: [217.16.27.195: sun.rmi.registry.RegistryImpl[0:0:0, 0]: java.rmi.Remote lookup(java.lang.String)]

经过进一步谷歌搜索后,我发现我需要使用 ssh 隧道。我按照以下方式配置了腻子

http://www.advancedigital.ru/show/putty_config.jpg

和 VisualVM 如下

http://www.advancedigital.ru/show/visualvm_config.jpg

VisualVM 上面的 Adter munipulations 连接到远程主机,但我只能看到线程摘要图表,并且分析器处于非活动状态。

我已经看到一些建议,两台机器上的 jvm 应该相似并且具有相同的平台(x86 或 x64),但我已经尝试从另一台机器(带有 JDK1.7.0_03 x86 的 Windows 7 x86)进行分析,并且具有相同的结果。

我也尝试过这个,但再次得到相同的结果。 通过 ssh 的 VisualVM

如何让此分析发挥作用?

I'm trying to profile remote java app, actually it is a gameserver. It works normally on my local machine (windows XP x64 with JDK1.7.0_02 x64), but behaves very wierd on the production server (CentOS with JDK1.7.0_03 i586).

I've done a lot of searching and found out that I should use VisualVM for this task. So VisualVM works great on local machine, but there is no hangs on local machine, i need profiling in production environment with real payload. I started jstatd on the remote machine with arguments

jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.logCalls=false &

with the policy file

grant codebase "file:/usr/java/jdk1.7.0_02/lib/tools.jar" {
    permission java.security.AllPermission;
};

then I started my java application like this

java -server -Dcom.sun.management.jmxremote\
 -Dcom.sun.management.jmxremote.port=4000\
 -Dcom.sun.management.jmxremote.ssl=false\
 -Dcom.sun.management.jmxremote.authenticate=false\
 -jar /home/pinballSocketServer/pinballSocketServer.jar

Both application and jstatd are launched with root priveledges.

and VisualVM didn't manage to connect to remote host. But on the remote host i see the following log, while VisualVM is running and remote host added:

Feb 16, 2012 7:11:52 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(3)-217.16.27.195: [217.16.27.195: sun.rmi.registry.RegistryImpl[0:0:0, 0]: java.rmi.Remote lookup(java.lang.String)]
Feb 16, 2012 7:11:56 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(3)-217.16.27.195: [217.16.27.195: sun.rmi.registry.RegistryImpl[0:0:0, 0]: java.rmi.Remote lookup(java.lang.String)]
Feb 16, 2012 7:12:00 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(3)-217.16.27.195: [217.16.27.195: sun.rmi.registry.RegistryImpl[0:0:0, 0]: java.rmi.Remote lookup(java.lang.String)]
Feb 16, 2012 7:12:04 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(3)-217.16.27.195: [217.16.27.195: sun.rmi.registry.RegistryImpl[0:0:0, 0]: java.rmi.Remote lookup(java.lang.String)]

After further googling, I found out that I need to use ssh tunneling. I configured putty in the following way

http://www.advancedigital.ru/show/putty_config.jpg

and VisualVM as this

http://www.advancedigital.ru/show/visualvm_config.jpg

Adter munipulations above VisualVM connects to remote host, but I can only see the threads summary chart and profiler is inactive.

I've seen some recommendations that jvms on both machines should be similar and have the same platform (x86 or x64) but i've already tried profiling from another machine (windows 7 x86 with JDK1.7.0_03 x86), and have the same result.

I've also tried this, but get the same result again.
VisualVM over ssh

How can I get this profiling to work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

好倦 2025-01-13 01:46:10

即使这个问题已经得到回答,我还是设法做到了,所以我将添加我的方法:

我使用了以下来源:

https: //bowerstudios.com/node/731

我在 Windows 中使用具有 ssh 命令的 git bash 执行此操作。您还可以使用 cygwin 或纯 minggw。

1) 在命令提示符中运行 ssh 隧道命令(我在 git bash/MINGGW32 中执行此操作)。

ssh -D 9010 -p 22 root@IP -v

2) 使用 JMX 选项(单行)在服务器上运行应用程序

 java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 
-Dcom.sun.management.jmxremote.local.only=false 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false -jar application.jar

3) 通过socks代理运行VisualVM进行连接(单行)

visualvm -J-Dnetbeans.system_socks_proxy=localhost:9010 
-J-Djava.net.useSystemProxies=true

4) 在VisualVM中实际添加您的JMX远程连接

也可用: http://maythesource.com/2013/ 12/04/connecting-to-jmx-from-visualvm-using-ssh-tunnel/(将随着时间的推移更新更多信息)。

Even though this has been answered, I managed to do it so I will add my approach:

I used the following source:

https://bowerstudios.com/node/731

I did this in windows using git bash that has ssh command. You can also do using cygwin or pure minggw.

1) Run ssh tunnel command in command prompt (I do this in git bash/MINGGW32).

ssh -D 9010 -p 22 root@IP -v

2) Run your application on server with JMX options (one liner)

 java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 
-Dcom.sun.management.jmxremote.local.only=false 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false -jar application.jar

3) Run visualVM through socks proxy to connect (one liner)

visualvm -J-Dnetbeans.system_socks_proxy=localhost:9010 
-J-Djava.net.useSystemProxies=true

4) Actually add your JMX remote connection in visualVM

Also available: http://maythesource.com/2013/12/04/connecting-to-jmx-from-visualvm-using-ssh-tunnel/ (will be updated with more info over time).

陪我终i 2025-01-13 01:46:10

请注意,如果服务器安装了 X11 库,您可以远程运行 JVisualVM,只需让 Putty 将 X11 连接转发到本地计算机上运行的 X11 服务器即可。

如果您没有可用的 X11 服务器,Xming - http://www.straightrunning.com/XmingNotes/< /a> - 对此效果很好。如果您的计算机是安全的,您可以在没有访问控制的情况下运行,从而更容易启动和运行。

请注意,X11 通信非常冗长。使用“blowfish”-cypher 并要求压缩。

Note that if the server has X11 libraries installed you can run JVisualVM remotely and just have Putty forward the X11 connection to a X11-server running on your local machine.

If you do not have an X11-server available, Xming - http://www.straightrunning.com/XmingNotes/ - works fine for this. If your computer is secure, you can run without access control making it much easier to get up and running.

Note that X11 communication is quite verbose. Use "blowfish"-cypher and ask for compression.

万劫不复 2025-01-13 01:46:10

我将从调试 jstatd 连接开始,并将 JMX 连接留到以后使用。从您所写的内容来看,尚不清楚为什么应该使用 ssh 隧道。您的远程主机上是否有防火墙,或者您为什么认为需要使用 ssh 隧道。
另请注意 - 两台机器上的 jvm 并不应该相似并且具有相同的平台(x86 或 x64)。

I would start with debugging just jstatd connection and leave JMX connection for later. From you wrote it is not clear why you should use ssh tunneling. Is there a firewall on your remote host or why do you think that you need to use ssh tunneling.
One additional note - it is not true that jvms on both machines should be similar and have the same platform (x86 or x64).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文