无法通过Java6中的jconsole连接到Tomcat的MBeanServer

发布于 2024-07-16 15:26:28 字数 378 浏览 7 评论 0原文

我用的是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 技术交流群。

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

发布评论

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

评论(5

鹿港巷口少年归 2024-07-23 15:26:29

好吧,我原本以为 op 给出的 URL 是错误的,但事实证明没有。 所以我无法回答。

不过,以下是基础知识:

通过 jconsole 进行简单连接。

例如,如果您知道要连接的 JMX 服务器的RMI 注册表端口为 9003,请

localhost:9003

改为使用 进行连接。

否则,这是我从头开始发现的:

假设您有 JMX 服务器(别名“JMX Agent”别名“您想要连接到的 JVM”)在“目标机器”上运行,RMI 注册表端口< /em> 位于“RMI REGISTRY PORT”,JMX RMI 服务器端口位于“JMX RMI SERVER PORT”。

注意:

  1. RMI 注册表告诉 JMX 客户端在哪里可以找到 JMX RMI 服务器端口; 可以通过jmxrmi键获取信息。
  2. RMI 注册表端口众所周知,因为它是在 JVM 启动时通过系统属性设置的。
  3. JMX RMI 服务器端口通常已知,因为 JVM 随机选择它(如果不采取其他预防措施)。

以下 URI 将导致成功(已测试)

service:jmx:rmi://:/jndi/rmi://:/jmxrmi

这看起来很糟糕。 我们把它分开吧。

这个 URI 是一个 RFC2609“服务定位协议 URL”(嗯,它确实是一个 URI,对吧?)

它由以下部分组成:

  • service - 一个常量
  • jmx:rmi - 服务类型组成:抽象类型 jmxURL方案 rmi
  • 其余 - sap(服务访问协议规范)

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

更好的是,这也有效!

参考:

1 download.oracle.com/javase/6/docs/api/javax/management/remote/rmi/package-summary.html
2 download.oracle.com/javase/6/docs/api/javax/management/remote/JMXServiceURL.html
3 mx4j.sourceforge.net/docs/ch03s04.html
4 download.oracle.com/javase/6/docs/technotes/guides/management/agent.html#gdevg
5 http://www.rfc-editor.org/rfc/rfc2609.txt

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

localhost:9003

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:

  1. The RMI registry tells JMX clients where to find the JMX RMI server port; information can be obtained under key jmxrmi.
  2. The RMI registry port is generally known as it is set through system properties at JVM startup.
  3. The JMX RMI server port is generally not known as the JVM chooses it at random (if no other precautions are taken).

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 constant
  • jmx:rmi - the service type composed of: abstract type jmx and URL scheme rmi
  • the rest - the sap (service access protocol specification)

sap is decomposed into:

  • //<TARGET_MACHINE>:<JMX_RMI_SERVER_PORT> - ipsite
  • /jndi/rmi://<TARGET_MACHINE>:<RMI_REGISTRY_PORT>/jmxrmi - URL part

A 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 follows
  • rmi://<TARGET_MACHINE>:<RMI_REGISTRY_PORT>/jmxrmi - Yep, we get information about the JMX RMI Server at the RMI registry, under the lookup key jmxrmi

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:

1 download.oracle.com/javase/6/docs/api/javax/management/remote/rmi/package-summary.html
2 download.oracle.com/javase/6/docs/api/javax/management/remote/JMXServiceURL.html
3 mx4j.sourceforge.net/docs/ch03s04.html
4 download.oracle.com/javase/6/docs/technotes/guides/management/agent.html#gdevg
5 http://www.rfc-editor.org/rfc/rfc2609.txt
心房敞 2024-07-23 15:26:29

在 Ubuntu 10.04 上,使用 OpenJDK 6 和 Tomcat 6.0.29,我无法为本地 jconsole 会话激活 JMX,无论我传递给 java 有多少 com.sun.management.jmxremote.* 选项与 CATALINA_OPTS。 问题在于 -Djava.io.tmpdir 设置,默认为 $CATALINA_BASE/temp。 我只需

CATALINA_TMPDIR="/tmp"

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:

CATALINA_TMPDIR="/tmp"

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.

泪冰清 2024-07-23 15:26:29

进程是否在同一用户下运行?

您还可以通过运行 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)

阳光的暖冬 2024-07-23 15:26:29

OS X 10.7 又名 Lion 也需要这样做。

This is also needed for OS X 10.7 aka Lion.

仙女 2024-07-23 15:26:29

我在这里回答了类似的问题:java.rmi .ConnectException: 连接拒绝主机: 127.0.1.1;

我发现了很多关于这个主题的问答,但没有什么对我有帮助 - 那是因为我的问题更基本(我能说我不是一个网络大师:))。 /etc/hosts 中我的 IP 地址不正确。 我尝试过的 CATALINA_OPTS 包括以下内容:

CATALINA_OPTS="$CATALINA_OPTS -Djava.awt.headless=true -Xmx128M -server 
-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=7091 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=A.B.C.D"  #howeverI put the wrong ip here!

export CATALINA_OPTS

我的问题是我几个月前更改了我的 IP 地址,但从未更新过我的 /etc/hosts 文件。 似乎默认情况下 jconsole 以某种方式使用主机名 -i ip 地址,即使我正在查看本地进程。 最好的解决方案是简单地更改 /etc/hosts 文件。

另一个可行的解决方案是从 /sbin/ifconfig 获取正确的 IP 地址,并在例如 catalina.sh 脚本中指定 IP 地址时使用该 IP 地址:

-Djava.rmi.server.hostname=A.B.C.D

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:

CATALINA_OPTS="$CATALINA_OPTS -Djava.awt.headless=true -Xmx128M -server 
-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=7091 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=A.B.C.D"  #howeverI put the wrong ip here!

export 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:

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