Java 无法使用 VisualVM 连接到 Tomcat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1051817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to Connect to Tomcat Using VisualVM
提问by
I am having problems monitoring a remote Tomcat process. I'm trying to use the Java 6 versions of JConsole/JVisualVM.
我在监视远程 Tomcat 进程时遇到问题。我正在尝试使用JConsole/JVisualVM的 Java 6 版本。
I have jstatd running on the remote server with the appropriate security policy. The process is started and the TCP connections are available.
我在具有适当安全策略的远程服务器上运行 jstatd。该进程已启动并且 TCP 连接可用。
When I try to connect through JConsole, I get 'Connection Failed:jmxrmi'
.
当我尝试通过 JConsole 连接时,我得到'Connection Failed:jmxrmi'
.
When I try to connect through VisualVM, I add the host name and my right-click options are 'Add JMX Connection'. It's unclear to me from the docs whether or not that's what I'd expect to see. When I try to connect, I get:
当我尝试通过 VisualVM 连接时,我添加了主机名,我的右键单击选项是“添加 JMX 连接”。从文档中我不清楚这是否是我期望看到的。当我尝试连接时,我得到:
'Cannot connect using service:jmx:rmi:///jndi/rmi://<host>:<port>/jmxrmi'.
So, the docs suggest I only need have jstatd running remotely to monitor in VisualVM, while the UI is asking for jmxrmi .. Are those the same? I've tried setting up tomcat using jmx rmi options and I also timeout, though I know it's not a firewall issue.
因此,文档建议我只需要远程运行 jstatd 即可在 VisualVM 中进行监控,而 UI 要求的是 jmxrmi .. 这些是一样的吗?我已经尝试使用 jmx rmi 选项设置 tomcat,但我也超时了,尽管我知道这不是防火墙问题。
If anyone has had success getting a remote Tomcat process attached in this manner, and could describe how, that would help me out a great deal.
如果有人成功地以这种方式连接了远程 Tomcat 进程,并且可以描述如何连接,那将对我有很大帮助。
回答by cletus
You need to enable the management extensions to the Tomcat VM. Usually that means passing in something like these:
您需要启用 Tomcat VM 的管理扩展。通常这意味着传递如下内容:
-Dcom.sun.management.jmxremote.port=8086
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
Of course, if you do it the above way make sure your Tomcat isn't visible on the Internet or the port is firewalled from remote access or take similar security measures to avoid being port scanned and compromised. Otherwise use the authentication options.
当然,如果您按照上述方式进行操作,请确保您的 Tomcat 在 Internet 上不可见,或者该端口已设置防火墙以防止远程访问,或采取类似的安全措施以避免端口扫描和泄露。否则使用身份验证选项。
回答by cletus
I think it was a firewall issue. My server does not have all ports open, so by following instructions here to use the one open port I have, I was able to make it work.
我认为这是一个防火墙问题。我的服务器没有打开所有端口,因此按照此处的说明使用我拥有的一个打开端口,我能够使其正常工作。
http://blogs.oracle.com/jmxetc/entry/connecting_through_firewall_using_jmx
http://blogs.oracle.com/jmxetc/entry/connecting_through_firewall_using_jmx
回答by Tom
Usually you need to make sure you specify the server's ip address in the JAVA_OPTS. Otherwise, it appears that JMX is going to send back instructions to the client to reconnect to the server on a different port and if it doesn't have the ip address to give the client, the connection fails.
通常您需要确保在 JAVA_OPTS 中指定服务器的 ip 地址。否则,看起来 JMX 将向客户端发送回指令以重新连接到不同端口上的服务器,如果它没有提供给客户端的 IP 地址,则连接将失败。
The argument for this is:
对此的论据是:
-Djava.rmi.server.hostname=1.2.3.4
You can find more details in this walk throughof the setup process.
你可以找到更多细节穿行在安装过程中。
回答by Omprakash
JMX port usually sends data to another port so you need to find that port number by executing lsof -p -n | grep TCP and enable permissions to that port and then try to connect to remote JMX agent.
JMX 端口通常将数据发送到另一个端口,因此您需要通过执行 lsof -p -n | 找到该端口号。grep TCP 并启用对该端口的权限,然后尝试连接到远程 JMX 代理。
回答by kabadisha
I have actually just tackled this problem myself and figured it out.
我实际上刚刚自己解决了这个问题并弄清楚了。
I would wager that the problem is the RMI connections - you can't predict which ports it will use and so you can't get it to work with a firewall.
我敢打赌,问题出在 RMI 连接上——您无法预测它将使用哪些端口,因此您无法让它与防火墙一起工作。
The workaround is to use an SSH proxy:
解决方法是使用 SSH 代理:
SSH to the box where your application is running but use the -D option like this:
ssh user@remoteHost -D 9999
This will start a socks proxy on your local machine on port 9999.
Open JVisualVM and in the preferences, under 'network' configure it to use a socks proxy at localhost, on port 9999.
通过 SSH 连接到运行应用程序的框,但使用 -D 选项,如下所示:
ssh 用户@remoteHost -D 9999
这将在您的本地机器上的 9999 端口上启动一个袜子代理。
打开 JVisualVM 并在首选项中的“网络”下将其配置为在 localhost 的 9999 端口上使用socks 代理。
If you do the above, you should then be able to connect to the remote machine as normal and since all the RMI traffic is now going over the SSH proxy, it is punched through the firewall and works nicely.
如果您执行上述操作,那么您应该能够像往常一样连接到远程机器,并且由于所有 RMI 流量现在都通过 SSH 代理,因此它会穿过防火墙并且运行良好。
Good luck :-)
祝你好运 :-)