如何使用 ssh 隧道远程连接到 tomcat 上的 jmx 并且不破坏 ehcache
我已按照以下链接中的说明在 tomcat 内的单个端口上创建我自己的 RMI 注册表和 jmx 服务器。根据评论,我需要设置-Djava.rmi.server.hostname=localhost。一旦我这样做了,我确实可以使用 ssh 端口转发通过 jconsole 连接到我的服务器。
但是
,我'我们发现它会破坏我们使用 RMI 的 ehcache 复制,从而产生非常严重的副作用。它失败,抱怨它无法从远程对等本地主机引导。我猜测是因为对等点都通过设置 -Djava.rmi.server.hostname=localhost 将其 rmi 服务器主机名设置为 localhost。
有没有人有可能解决这个问题?
I've followed the instructions in the following link to create my own RMI registry and jmx server on a single port inside tomcat. According to the comments, I need to set -Djava.rmi.server.hostname=localhost. Once I do that, I can indeed connect to my server via jconsole using ssh port forwarding.
http://blogs.oracle.com/jmxetc/entry/connecting_through_firewall_using_jmx
However, I've found it has the very bad side affect of breaking our ehcache replication which uses RMI. It fails complaining that it cannot bootstrap from remote peer localhost. I'm guessing because the peers all have their rmi server hostname set to localhost from setting -Djava.rmi.server.hostname=localhost.
Does anyone have a possible workaround to this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚遇到这个问题。问题是 java.rmi.servername.hostname 属性是全局的。为了使 ehcache 和 jmx 服务器协调工作,您必须在运行 VisualVM 的计算机上执行一些修改。
这就是你需要做的。这是基于使用 Mac 作为客户端的情况,因此请根据需要修改命令。
删除 -Djava.rmi.server.hostname=localhost。
编写一个测试应用程序,该应用程序将为您提供要分析的服务器计算机上的 InetAddress.getLocalHost().getHostAddress() 值。这应该会给你本地IP(如果经过NAT,则为私有)。您必须在本地计算机上引用此 IP。在下面的命令显示 IP 的情况下使用此 IP。
现在,这是有趣的部分:将内部 IP 添加到计算机上的环回接口。 (ifconfig lo0 IP 网络掩码 255.255.255.0 up)
测试这实际上是否会将流量引导至环回。它应该返回环回。 (route get IP)
启动 SSH 隧道: ssh -C -L IP:PORT:localhost:PORT -L IP:OTHER_PORT:localhost:OTHER_PORT user@host。
请注意,ssh 隧道的 IP 实际上是现在与环回绑定的 IP。你不再引用 localhost,而是引用机器的 IP。您还必须修改 JMX URL 以引用此 IP 而不是 localhost。
I just came across the problem. The problem is that the java.rmi.servername.hostname property is global. To make ehcache and the jmx server play in harmony, you must perform a few hacks on the machine you're running VisualVM from.
Here's what you need to do. This is based on using a Mac for the client so modify the commands as needed.
Remove the -Djava.rmi.server.hostname=localhost.
Write a tester application that will give you the value of InetAddress.getLocalHost().getHostAddress() on your server machine you want to profile. This should give you the local ip (private if nat'd). You will have to refer to this IP on your local machine. Use this IP where the commands below say IP.
Now, this is the fun part: Add the internal IP to your loopback interface on your machine. (ifconfig lo0 IP netmask 255.255.255.0 up)
Test that this will actually direct traffic to the loopback. It should return the loopback. (route get IP)
Initiate the SSH tunnel: ssh -C -L IP:PORT:localhost:PORT -L IP:OTHER_PORT:localhost:OTHER_PORT user@host.
Notice the IP's for the ssh tunnel are actually the one now tied to loopback. You no longer refer to localhost, but the IP of the machine for everything. You'll also have to modify your JMX URL to refer to this IP instead of localhost.
如果您正在寻找一种易于使用、防火墙友好的 JMX 远程处理替代方案,jmx4perl 可能值得一试。它是一种基于代理的方法,通过 HTTP/Rest 导出 JMX MBean。
虽然其主要重点是在脚本环境(即 perl)中用于监视目的,但对于预定版本 0.70,已添加 Java 客户端库(测试版质量)
If you look for an easy to use, firewall friendly JMX remoting alternative, jmx4perl might be worth a try. It is an agent based approach, which export JMX MBeans via HTTP/Rest.
Though its main focus is directed for use in a scripting environment (i.e. perl) for monitoring purposes, for the scheduled version 0.70 a Java client library has been added (beta quality)
抱歉,我的第一个答案是错误的。但我认为使用 tomcat6 你可以选择 JmxRemoteLifecycleListener:
sorry, but my first answer was wrong. But I think with tomcat6 you have an option with JmxRemoteLifecycleListener: