使用 jConsole 连接远程 tomcat JMX 实例

发布于 2024-08-02 02:12:35 字数 350 浏览 6 评论 0原文

我正在尝试使用 jConsole 连接到远程 tomcat JMX 实例。 但无法连接成功。 任何想法?

我在远程 tomcat catalina.sh 中添加了以下选项:

JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote \
    -Dcom.sun.management.jmxremote.port=9004 \
    -Dcom.sun.management.jmxremote.ssl=false \
    -Dcom.sun.management.jmxremote.authenticate=false"

I am trying to connect to a remote tomcat JMX instance using jConsole. But can't connect successfully. Any Idea?

I included the following option in remote tomcat catalina.sh:

JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote \
    -Dcom.sun.management.jmxremote.port=9004 \
    -Dcom.sun.management.jmxremote.ssl=false \
    -Dcom.sun.management.jmxremote.authenticate=false"

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

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

发布评论

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

评论(12

南风几经秋 2024-08-09 02:12:36

检查您的服务器是否位于防火墙后面。 JMX是基于RMI的,它在启动时打开两个端口。 一是注册端口,默认为1099,可以通过com.sun.management.jmxremote.port选项指定。 另一种是用于数据通信的,并且是随机的,这就是导致问题的原因。 好消息是,从 JDK6 开始,可以通过 com.sun.management.jmxremote.rmi.port 选项指定此随机端口。

在 {tomcat_dir}/bin/setenv.sh 中添加以下行:

export CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8991 -Dcom.sun.management.jmxremote.rmi.port=8991 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

Check if your server is behind the firewall. JMX is base on RMI, which open two port when it start. One is the register port, default is 1099, and can be specified by the com.sun.management.jmxremote.port option. The other is for data communication, and is random, which is what cause problem. A good news is that, from JDK6, this random port can be specified by the com.sun.management.jmxremote.rmi.port option.

add the line in you {tomcat_dir}/bin/setenv.sh:

export CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8991 -Dcom.sun.management.jmxremote.rmi.port=8991 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
ゃ人海孤独症 2024-08-09 02:12:36

我给你们准备了一些东西,以完成对整个事件的调查。 有一个技巧,当分析器工具使用某个端口与 jvm 连接时,jvm 使用另一个随机端口继续对话。 如果 jvm 在远程计算机(例如:tomcat Web 应用程序服务器)内运行,并且远程计算机具有针对传出和传入连接的保护,则必须设置 java 系统属性 com.sun.management.jmxremote .rmi.port 与名为 com.sun.management.jmxremote.port 的属性的相同值

来源:https://serverfault.com/questions/308662/how-do-i-fix-a-failed-检索-rmiserver-stub-jmx-错误
还要检查一下: http://blog.cantremember.com /debugging-with-jconsole-jmx-ssh-tunnels/

希望能为大家做出贡献!

还有祝你好运!

I got something for all of you, in order to complete the investigation of this whole thing. There is a trick, it happens that profiler tool connnects with the jvm using a port, but the jvm continues the conversation using another random port. If the jvm is running inside a remote machine (for example : a tomcat web-app server), and the remote machine has protection against outgoing and incoming connections, you must set the java system property com.sun.management.jmxremote.rmi.port to the same value of the property named com.sun.management.jmxremote.port

Source : https://serverfault.com/questions/308662/how-do-i-fix-a-failed-to-retrieve-rmiserver-stub-jmx-error
And also check this out : http://blog.cantremember.com/debugging-with-jconsole-jmx-ssh-tunnels/

Hope to contribute guys!

And good luck!

梦里梦着梦中梦 2024-08-09 02:12:36

好吧,我在 Linux 盒子(虚拟机)中遇到了这个问题,我使用 -Djava.rmi.server.hostname 属性修复了它,但有件事我无法理解。 我的机器有 5 台 tomcat 服务器,所有服务器都在连续端口(8008,8018,8028...)中启用了 jmx,并且只有其中一台在连接 JMX 时出现此问题。 没有防火墙,任何 tomcat 中都没有 -Djava.rmi.server.hostname 属性...

所以问题是我理解这个问题,但我无法理解为什么我的 4 个 tomcat 工作而其中 1 个不工作。

PD:我知道我的英语很差。 我很抱歉。

Well, I had this problem in a Linux box (virtual machine) and I fixed it using -Djava.rmi.server.hostname property but there's a thing I can't understand. My machine has 5 tomcat servers, all of them has jmx enabled in consecutive ports (8008,8018,8028...) and only one of them had this issue connecting JMX. No firewall, no -Djava.rmi.server.hostname property in any tomcat....

So the thing is that I understand the problem but I can't understand why 4 of my tomcats worked and 1 of them not.

P.D: My english is very poor, I know. My Apologies.

赠意 2024-08-09 02:12:36

PROTIP:您需要修复(如具有已知编号)RMI 注册表和 JMX/RMI 服务器端口。 您可以通过将 jar 文件放入 lib-dir 并配置一个特殊的侦听器来完成此操作。 (当然,激活 JMX 的常用标志

    -Dcom.sun.management.jmxremote  \
    -Dcom.sun.management.jmxremote.port=8999 \
    -Dcom.sun.management.jmxremote.ssl=false \
    -Dcom.sun.management.jmxremote.authenticate=false \
    -Djava.rmi.server.hostname=<HOSTNAME> \

请参阅:JMX Remote Lifecycle Listener,位于 http ://tomcat.apache.org/tomcat-6.0-doc/config/listeners.html

PROTIP: You need to fix (as in having a known number) the RMI Registry and JMX/RMI Server ports. You do this by putting jar-file in the lib-dir and configuring a special listener. (And ofcourse the usual flags for activating JMX

    -Dcom.sun.management.jmxremote  \
    -Dcom.sun.management.jmxremote.port=8999 \
    -Dcom.sun.management.jmxremote.ssl=false \
    -Dcom.sun.management.jmxremote.authenticate=false \
    -Djava.rmi.server.hostname=<HOSTNAME> \

See: JMX Remote Lifecycle Listener at http://tomcat.apache.org/tomcat-6.0-doc/config/listeners.html

梦里南柯 2024-08-09 02:12:36

在Linux上更改/etc/hosts,我将与我的帐户关联的本地主机地址替换为机器IP,为我解决了这个问题。

Changing the /etc/hosts on linux, where I replaced the localhost address associated to my account to the machine ip, solved this problem for me.

等你爱我 2024-08-09 02:12:35

我有一个类似的问题,即使不是相同的问题。 如果我在计算机上本地启动 jconsole,我可以连接到 JMX 服务器。

RMI 服务器似乎没有侦听正确的 IP。 因此,正如此相关问题,我也将以下内容添加

-Djava.rmi.server.hostname=<host ip>

JAVA_OPTS 中,然后它就起作用了。

I had a similar, if not the same, problem. I could connect to the JMX server if I started jconsole locally on the machine.

It appears the RMI server was not listening on the correct ip. So, as was suggested in this related question, I added the following:

-Djava.rmi.server.hostname=<host ip>

to JAVA_OPTS as well, and then it worked.

眉黛浅 2024-08-09 02:12:35

我收集了网上流传的信息,并根据其他成员的提示找到了这些信息。

JMX 造成的最大痛苦是(我认为)JMX 打开第二个动态分配的网络端口。 防火墙(如 iptables)会阻止此操作。

Linux 上 tomcat 的解决方案:

使用 tomcat 6.0.24 或更高版本
从 apache tomcat extras 下载 catalina-jmx-remote.jar (在 tomcat 下载页面上使用浏览)
将其复制到 $CTALINA_HOME\lib

这允许您设置 JMX 使用的两个端口

在 server.xml 中编辑服务器部分

<Server port="8005" ..>
  ...
  <Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="9840" rmiServerPortPlatform="9841"/>

设置一些环境变量(例如在 setenv.sh 中)

CATALINA_OPTS="
  -Djava.rmi.server.hostname=IP-TO-LISTEN
  -Dcom.sun.management.jmxremote.password.file=$CATALINA_BASE/conf/jmxremote.password 
  -Dcom.sun.management.jmxremote.access.file=$CATALINA_BASE/conf/jmxremote.access 
  -Dcom.sun.management.jmxremote.ssl=false"

这会激活 JMX 的访问控制

jmxremote.access 看起来像

monitorRole readonly
controlRole readwrite

end 将

monitorRole tomcat
controlRole tomcat

jmxremote.password (只是简单的空格)

重新启动tomcat。

现在在服务器上配置防火墙(例如 iptables)

/etc/sysconfig/iptables

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 9840 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 9841 -j ACCEPT

和 /etc/sysconfig/ip6tables

-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 9840 -j ACCEPT
-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 9841 -j ACCEPT

重新启动 iptables

完成!

现在,在您的工作站上使用 VisualVM 或 JConsole 建立与 rmiRegistryPortPlatform(在我们的示例中为 9840)的连接。

如果工作站和服务器之间不再有防火墙,它应该可以工作。

I've collected information spread over the net, found with hints from other members.

Most pain caused by JMX is (imo) the fact that JMX opens a second dynamically allocated network port. A firewall (like iptables) will block this.

Solution for tomcat on linux :

use tomcat 6.0.24 or newer
download catalina-jmx-remote.jar from apache tomcat extras (use browse on tomcat download page)
copy it in the $CTALINA_HOME\lib

This allows you to set both ports used by JMX

edit Server section in your server.xml

<Server port="8005" ..>
  ...
  <Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="9840" rmiServerPortPlatform="9841"/>

set some environment variables (e.g. in setenv.sh)

CATALINA_OPTS="
  -Djava.rmi.server.hostname=IP-TO-LISTEN
  -Dcom.sun.management.jmxremote.password.file=$CATALINA_BASE/conf/jmxremote.password 
  -Dcom.sun.management.jmxremote.access.file=$CATALINA_BASE/conf/jmxremote.access 
  -Dcom.sun.management.jmxremote.ssl=false"

this activates access control for JMX

jmxremote.access will look like

monitorRole readonly
controlRole readwrite

end jmxremote.password will be

monitorRole tomcat
controlRole tomcat

(just simple spaces)

restart tomcat.

Now configure firewall on the server (e.g. iptables)

/etc/sysconfig/iptables

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 9840 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 9841 -j ACCEPT

and /etc/sysconfig/ip6tables

-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 9840 -j ACCEPT
-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 9841 -j ACCEPT

restart iptables

Done!

Now use VisualVM or JConsole on your workstation to establish a connection to rmiRegistryPortPlatform, 9840 in our sample.

If there are no more firewalls between workstation and server it should work.

如日中天 2024-08-09 02:12:35

尝试使用 Java 8

1. 将其添加到您的 java tomcat 启动脚本中:

-Dcom.sun.management.jmxremote.port=1616
-Dcom.sun.management.jmxremote.rmi.port=1616
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=localhost

例如,将其添加到 bin/setenv.sh 中:

export CATALINA_OPTS="$CATALINA_OPTS \
-Dcom.sun.management.jmxremote.port=1616 \
-Dcom.sun.management.jmxremote.rmi.port=1616 \
-Dcom.sun.management.jmxremote.local.only=true \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false "

2. 在您的计算机上执行此命令。

  • Windows 用户

    putty.exe -ssh user@remote-host -L 1616:remote-host:1616

  • Linux 和 Mac 用户

    ssh user@remote-host -L 1616:remote-host:1616

3. 在计算机上启动 jconsole

jconsole localhost:1616

4. 玩得开心!

  • PS:在步骤 2 中,使用 ssh 和 -L 指定将本地(客户端)主机上的端口 1616 转发到远程端。
  • PS2.:您可以为 JMX 和 RMI 对话指定相同的端口

Tried with Java 8

1. Add this to your java tomcat startup script:

-Dcom.sun.management.jmxremote.port=1616
-Dcom.sun.management.jmxremote.rmi.port=1616
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=localhost

for example add into bin/setenv.sh this:

export CATALINA_OPTS="$CATALINA_OPTS \
-Dcom.sun.management.jmxremote.port=1616 \
-Dcom.sun.management.jmxremote.rmi.port=1616 \
-Dcom.sun.management.jmxremote.local.only=true \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false "

2. Execute this on your computer.

  • Windows users:

    putty.exe -ssh user@remote-host -L 1616:remote-host:1616

  • Linux and Mac Users:

    ssh user@remote-host -L 1616:remote-host:1616

3. Start jconsole on your computer

jconsole localhost:1616

4. Have fun!

  • P.S.: during step 2, using ssh and -L you specify that the port 1616 on the local (client) host is to be forwarded to the remote side.
  • P.S.2.: you can specify same port for JMX and RMI conversations
新人笑 2024-08-09 02:12:35

您使用什么字符串作为 JMX 连接 url。 我并不是想指出显而易见的事情,但 JConsole 的界面很糟糕,对我来说,在连接到远程 jmx 应用程序之前需要一个过于复杂的 url。 我的看起来像这样:

service:jmx:rmi:///jndi/rmi://(hostname):(jmxport)/jmxrmi

what string are you using as the JMX connection url. I don't mean to point out the obvious but JConsole has a terrible interface and to me requires an overly complex url before it will connect to a remote jmx app. Mine looks like this:

service:jmx:rmi:///jndi/rmi://(hostname):(jmxport)/jmxrmi
鹿! 2024-08-09 02:12:35

在 Tomcat8 中启用 JMX,在我的 POC 中测试成功

1/ 从 apache 网站下载 catalina-jmx-remote.jar 并放置在 $CATALINA_HOME/lib 中。

2/ 备份server.xml / setenv.sh。 对 server.xml 进行如下更改 -

<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="10001" rmiServerPortPlatform="10002" />

3/ 对 $CATALINA_BASE/bin/setenv.sh 进行更改,如下 -

[...]

JVM_OPTS="[...] 
-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.authenticate=true 
-Djava.rmi.server.hostname=<eth:0_IP>| <`hostname -i`> 
-Dcom.sun.management.jmxremote.password.file=/apps/data/apache-tomcat-8_8080/conf/jmxremote.password 
-Dcom.sun.management.jmxremote.access.file=/apps/data/apache-tomcat-8_8080/conf/jmxremote.access 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.local.only=false 
-Dcom.sun.management.jmxremote=true "

4/ 创建这两个文件 -
$touch $CATALINA_BASE/conf/jmxremote.password 包含:

管理员让我

$touch $CATALINA_BASE/conf/jmxremote.access 包含:

管理员读写

$ chmod 600 jmxremote.password

5/ 重新启动 tomcat 并在 jconsole 工具上测试:)

$echo|telnet 10.105.14.90 10001

Enable JMX in Tomcat8, successfully tested in my POC

1/ Download the catalina-jmx-remote.jar from apache website and place in $CATALINA_HOME/lib.

2/ Take server.xml / setenv.sh backup. Make the changes to server.xml like below-

<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="10001" rmiServerPortPlatform="10002" />

3/ Make the changes to $CATALINA_BASE/bin/setenv.sh like -

[...]

JVM_OPTS="[...] 
-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.authenticate=true 
-Djava.rmi.server.hostname=<eth:0_IP>| <`hostname -i`> 
-Dcom.sun.management.jmxremote.password.file=/apps/data/apache-tomcat-8_8080/conf/jmxremote.password 
-Dcom.sun.management.jmxremote.access.file=/apps/data/apache-tomcat-8_8080/conf/jmxremote.access 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.local.only=false 
-Dcom.sun.management.jmxremote=true "

4/ Create these two files as -
$touch $CATALINA_BASE/conf/jmxremote.password containing:

admin letmein

$touch $CATALINA_BASE/conf/jmxremote.access containing:

admin readwrite

$ chmod 600 jmxremote.password

5/ Restart tomcat and test on jconsole tool :)

$echo|telnet 10.105.14.90 10001
绮烟 2024-08-09 02:12:35

当您说“但无法成功连接”时,您到底是什么意思? 有错误信息吗? 尝试在 jconsole 中打开日志记录,看看这是否有助于调试它。

要打开 jconsole 日志记录,请在将运行 jconsole 的目录中编辑名为logging.properties 的文件,添加:

handlers= java.util.logging.ConsoleHandler

.level=INFO

java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter

java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

javax.management.level=FINEST
javax.management.remote.level=FINEST

然后,使用以下命令启动 jconsole:

jconsole -J-Djava.util.logging.config.file=logging.properties

What exactly do you mean when you say "But can't connect successfully."? Is there an error message? Try turning on logging in jconsole and see if that helps debug it.

To turn on jconsole logging, edit a file named logging.properties in the directory you will be running jconsole in, add:

handlers= java.util.logging.ConsoleHandler

.level=INFO

java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter

java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

javax.management.level=FINEST
javax.management.remote.level=FINEST

Then, start jconsole with:

jconsole -J-Djava.util.logging.config.file=logging.properties
听,心雨的声音 2024-08-09 02:12:35

如果您在 Linux 上工作,请修改 catalina.sh 文件添加:

                CATALINA_OPTS="-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=<HOST_IP> -Dcom.sun.management.jmxremote.port=<HOST_PORT> -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
            export CATALINA_OPTS

则以 root 身份修改 /etc/profile 文件并重新运行该文件(源 /etc/profile)

或者如果您在 Windows 上工作并且从命令启动 tomcat, 线,使用
环境变量 CATALINA_OPTS

如果您在 Windows 上工作并且将 tomcat 作为服务启动,则需要使用监视服务实用程序来配置服务初始化参数(setenv.bat、catalina.bat 或 env-vars 都不起作用)。 为此,您需要 services.msc 中列出的服务名称(例如 jasperreportsTomcat)。 之后,您需要以管理员身份打开控制台并执行(例如):
tomcat6w.exe //MS//jasperreportsTomcat

使用此命令将出现一个托盘图标,您可以在其中打开一个面板。 现在您可以在“Java”选项卡中修改 jmx 选项。 请注意不要添加尾随空格并使用“[enter]”符号逐行分隔每个选项。

-Dcom.sun.management.jmxremote
-Djava.rmi.server.hostname=192.168.61.101
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

希望能帮助到你

if you are working on linux, modify the catalina.sh file adding:

                CATALINA_OPTS="-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=<HOST_IP> -Dcom.sun.management.jmxremote.port=<HOST_PORT> -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
            export CATALINA_OPTS

or modify the /etc/profile file as root and rerun the file (source /etc/profile)

if you are working on windows and you are starting tomcat from the command line, use
the environment variable CATALINA_OPTS

if you are working on windows and you are starting tomcat as a service, you'll need to use the monitor service utility to configure the service initialization parameters (neither setenv.bat, catalina.bat or env-vars will work). for that you'll need the service name that appears listed in services.msc (for example jasperreportsTomcat). After, you'll need to open a console as administrator and execute (for example):
tomcat6w.exe //MS//jasperreportsTomcat

with this command will appear a tray icon where you can open a panel. In the "Java" tab now you can modify the jmx options. Be careful to not add trailing whitespaces and use the "[enter]" symbol to separate each option line by line.

-Dcom.sun.management.jmxremote
-Djava.rmi.server.hostname=192.168.61.101
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

Hope it helps

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