无法通过Java6中的jconsole连接到Tomcat的MBeanServer
我用的是vista机器。 我已经使用以下选项启动了 tomcat 5.5.27:
CATALINA_OPTS="-Dcom.sun.management.jmxremote.port=9003 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false"
当我通过 jconsole 连接并添加以下服务 url 时,
service:jmx:rmi:///jndi/rmi://localhost:9003/jmxrmi
它不会连接。 有任何想法吗 ?
I'm on a vista machine. I've started tomcat 5.5.27 with these options:
CATALINA_OPTS="-Dcom.sun.management.jmxremote.port=9003 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false"
When I connect via jconsole and added the following service url
service:jmx:rmi:///jndi/rmi://localhost:9003/jmxrmi
it would not connect. Any ideas ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好吧,我原本以为 op 给出的 URL 是错误的,但事实证明没有。 所以我无法回答。
不过,以下是基础知识:
通过
jconsole
进行简单连接。例如,如果您知道要连接的 JMX 服务器的RMI 注册表端口为 9003,请
改为使用 进行连接。
否则,这是我从头开始发现的:
假设您有 JMX 服务器(别名“JMX Agent”别名“您想要连接到的 JVM”)在“目标机器”上运行,RMI 注册表端口< /em> 位于“RMI REGISTRY PORT”,JMX RMI 服务器端口位于“JMX RMI SERVER PORT”。
注意:
jmxrmi
键获取信息。以下 URI 将导致成功(已测试)
service:jmx:rmi://:/jndi/rmi://:/jmxrmi
这看起来很糟糕。 我们把它分开吧。
这个 URI 是一个 RFC2609“服务定位协议 URL”(嗯,它确实是一个 URI,对吧?)
它由以下部分组成:
service
- 一个常量jmx:rmi
- 服务类型组成:抽象类型jmx
和URL方案rmi
sap 分解为:
//:
- ipsite/jndi/rmi://:/jmxrmi
- URL 部分消息灵通的 JMX 客户端连接到“ipsite”以进行 JMX-over-RMI 交换; 但是不知道该端口的 JMX 客户端会怎样呢? 耐心...
URL部分被分解为:
/jndi/
- 这似乎告诉JMX客户端它可以在rmi 的,我们在 RMI 注册表中的查找键
jmxrmi
下获取有关 JMX RMI 服务器的信息。后面的位置获取查找信息://:/jmxrmi -是 -before-horse,因为必须首先联系 SLP URL 的后部分给出的RMI 注册表。
挠头之后,凭直觉,让我们尝试一下:
service:jmx:rmi:///jndi/rmi://:/jmxrmi
是的,这有效! JMX RMI 服务器端口可以很好地从注册表中获取。 再考虑一下,目标计算机也应该从注册表获取,因此:
service:jmx:rmi:///jndi/rmi://:;/jmxrmi
更好的是,这也有效!
参考:
Ok, I orignally supposed the URL given by op was wrong but it turns out no. So I can't answer.
Still, here are the basics:
For a simple connection through
jconsole
.If you know that the JMX Server you want to connect to has the RMI registry port at 9003 for example, connect using
instead.
Otherwise, here's what I found out from the ground up:
Suppose you have the JMX Server (alias 'JMX Agent' alias 'the JVM you want to connect to') running on 'TARGET MACHINE' with the RMI registry port at 'RMI REGISTRY PORT' and the JMX RMI server port at 'JMX RMI SERVER PORT'.
Note:
jmxrmi
.The following URI will lead to success (tested)
service:jmx:rmi://<TARGET_MACHINE>:<JMX_RMI_SERVER_PORT>/jndi/rmi://<TARGET_MACHINE>:<RMI_REGISTRY_PORT>/jmxrmi
This looks nasty. Let's cut it apart.
This URI is an RFC2609 "Service Location Protocol URL" (well, it's really an URI, right?)
It is composed of:
service
- a constantjmx:rmi
- the service type composed of: abstract typejmx
and URL schemermi
sap is decomposed into:
//<TARGET_MACHINE>:<JMX_RMI_SERVER_PORT>
- ipsite/jndi/rmi://<TARGET_MACHINE>:<RMI_REGISTRY_PORT>/jmxrmi
- URL partA well-informed JMX client connects to the "ipsite" to do JMX-over-RMI exchanges; but what of the JMX client that doesn't KNOW that port? Patience...
URL part is decomposed into:
/jndi/
- This seems to tell the JMX client that it can get lookup information at the location that followsrmi://<TARGET_MACHINE>:<RMI_REGISTRY_PORT>/jmxrmi
- Yep, we get information about the JMX RMI Server at the RMI registry, under the lookup keyjmxrmi
This is somewhat cart-before-horse, as one has to contact the RMI registry given by the latter part of the SLP URL first.
After scratching head, intuitively, let's try:
service:jmx:rmi://<TARGET_MACHINE>/jndi/rmi://<TARGET_MACHINE>:<RMI_REGISTRY_PORT>/jmxrmi
Yes, that works! The JMX RMI server port is nicely obtained from the registry. On second thoughts, the target machine should also be obtained from the registry, thus:
service:jmx:rmi:///jndi/rmi://<TARGET_MACHINE>:<RMI_REGISTRY_PORT>/jmxrmi
Even better, that works, too!
References:
在 Ubuntu 10.04 上,使用 OpenJDK 6 和 Tomcat 6.0.29,我无法为本地 jconsole 会话激活 JMX,无论我传递给 java 有多少 com.sun.management.jmxremote.* 选项与 CATALINA_OPTS。 问题在于 -Djava.io.tmpdir 设置,默认为 $CATALINA_BASE/temp。 我只需
在 bin/catalina.sh 的开头设置:,就可以在本地与 jconsole、jmap、jps 等连接。不需要任何 com.sun。 management.jmxremote.* 设置完全没有。
On Ubuntu 10.04, using OpenJDK 6 and Tomcat 6.0.29, I was unable to activate JMX for a local jconsole session, no matter how many com.sun.management.jmxremote.* options I passed to java with CATALINA_OPTS. The problem was the -Djava.io.tmpdir setting, which defaults to $CATALINA_BASE/temp. I simply had to set:
at the beginning of bin/catalina.sh and I was able to connect locally with jconsole, jmap, jps etc. There was no need for any com.sun.management.jmxremote.* settings at all.
进程是否在同一用户下运行?
您还可以通过运行 jps 和 jconsole (都在 JDK_HOME/bin 目录中)进行检查
Are the processes run under the same user?
You can also check by running jps and jconsole (both in the JDK_HOME/bin directory)
OS X 10.7 又名 Lion 也需要这样做。
This is also needed for OS X 10.7 aka Lion.
我在这里回答了类似的问题:java.rmi .ConnectException: 连接拒绝主机: 127.0.1.1;
我发现了很多关于这个主题的问答,但没有什么对我有帮助 - 那是因为我的问题更基本(我能说我不是一个网络大师:))。 /etc/hosts 中我的 IP 地址不正确。 我尝试过的 CATALINA_OPTS 包括以下内容:
我的问题是我几个月前更改了我的 IP 地址,但从未更新过我的 /etc/hosts 文件。 似乎默认情况下 jconsole 以某种方式使用主机名 -i ip 地址,即使我正在查看本地进程。 最好的解决方案是简单地更改 /etc/hosts 文件。
另一个可行的解决方案是从 /sbin/ifconfig 获取正确的 IP 地址,并在例如 catalina.sh 脚本中指定 IP 地址时使用该 IP 地址:
I answered a similar question here:java.rmi.ConnectException: Connection refused to host: 127.0.1.1;
I found many of the Q&A on this topic, not nothing was helping me - that's because my issue was more basic ( what can I say I am not a networking guru :) ). My ip address in /etc/hosts was incorrect. What I had tried included the following for CATALINA_OPTS:
My problem was that I had changed my ip address many months ago, but never updated my /etc/hosts file. it seems that by default the jconsole uses the hostname -i ip address in some fashion even though I was viewing local processes. The best solution was to simply change the /etc/hosts file.
The other solution which can work is to get your correct ip address from /sbin/ifconfig and use that ip address when specifying the ip address in, for example, a catalina.sh script: