使用 jConsole 连接远程 tomcat JMX 实例
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
检查您的服务器是否位于防火墙后面。 JMX是基于RMI的,它在启动时打开两个端口。 一是注册端口,默认为1099,可以通过com.sun.management.jmxremote.port选项指定。 另一种是用于数据通信的,并且是随机的,这就是导致问题的原因。 好消息是,从 JDK6 开始,可以通过 com.sun.management.jmxremote.rmi.port 选项指定此随机端口。
在 {tomcat_dir}/bin/setenv.sh 中添加以下行:
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:
我给你们准备了一些东西,以完成对整个事件的调查。 有一个技巧,当分析器工具使用某个端口与 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 namedcom.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!
好吧,我在 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.
PROTIP:您需要修复(如具有已知编号)RMI 注册表和 JMX/RMI 服务器端口。 您可以通过将 jar 文件放入 lib-dir 并配置一个特殊的侦听器来完成此操作。 (当然,激活 JMX 的常用标志
请参阅: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
See: JMX Remote Lifecycle Listener at http://tomcat.apache.org/tomcat-6.0-doc/config/listeners.html
在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.我有一个类似的问题,即使不是相同的问题。 如果我在计算机上本地启动 jconsole,我可以连接到 JMX 服务器。
RMI 服务器似乎没有侦听正确的 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:
to
JAVA_OPTS
as well, and then it worked.我收集了网上流传的信息,并根据其他成员的提示找到了这些信息。
JMX 造成的最大痛苦是(我认为)JMX 打开第二个动态分配的网络端口。 防火墙(如 iptables)会阻止此操作。
Linux 上 tomcat 的解决方案:
使用 tomcat 6.0.24 或更高版本
从 apache tomcat extras 下载 catalina-jmx-remote.jar (在 tomcat 下载页面上使用浏览)
将其复制到 $CTALINA_HOME\lib
这允许您设置 JMX 使用的两个端口
在 server.xml 中编辑服务器部分
设置一些环境变量(例如在 setenv.sh 中)
这会激活 JMX 的访问控制
jmxremote.access 看起来像
end 将
jmxremote.password (只是简单的空格)
重新启动tomcat。
现在在服务器上配置防火墙(例如 iptables)
/etc/sysconfig/iptables
和 /etc/sysconfig/ip6tables
重新启动 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
set some environment variables (e.g. in setenv.sh)
this activates access control for JMX
jmxremote.access will look like
end jmxremote.password will be
(just simple spaces)
restart tomcat.
Now configure firewall on the server (e.g. iptables)
/etc/sysconfig/iptables
and /etc/sysconfig/ip6tables
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.
尝试使用 Java 8
1. 将其添加到您的 java tomcat 启动脚本中:
例如,将其添加到 bin/setenv.sh 中:
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
4. 玩得开心!
Tried with Java 8
1. Add this to your java tomcat startup script:
for example add into bin/setenv.sh this:
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 computer4. Have fun!
ssh
and-L
you specify that the port 1616 on the local (client) host is to be forwarded to the remote side.您使用什么字符串作为 JMX 连接 url。 我并不是想指出显而易见的事情,但 JConsole 的界面很糟糕,对我来说,在连接到远程 jmx 应用程序之前需要一个过于复杂的 url。 我的看起来像这样:
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:
在 Tomcat8 中启用 JMX,在我的 POC 中测试成功
1/ 从 apache 网站下载
catalina-jmx-remote.jar
并放置在$CATALINA_HOME/lib
中。2/ 备份
server.xml
/setenv.sh
。 对server.xml
进行如下更改 -3/ 对
$CATALINA_BASE/bin/setenv.sh
进行更改,如下 -4/ 创建这两个文件 -
$touch $CATALINA_BASE/conf/jmxremote.password
包含:$touch $CATALINA_BASE/conf/jmxremote.access
包含:5/ 重新启动 tomcat 并在 jconsole 工具上测试:)
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 toserver.xml
like below-3/ Make the changes to
$CATALINA_BASE/bin/setenv.sh
like -4/ Create these two files as -
$touch $CATALINA_BASE/conf/jmxremote.password
containing:$touch $CATALINA_BASE/conf/jmxremote.access
containing:5/ Restart tomcat and test on jconsole tool :)
当您说“但无法成功连接”时,您到底是什么意思? 有错误信息吗? 尝试在 jconsole 中打开日志记录,看看这是否有助于调试它。
要打开 jconsole 日志记录,请在将运行 jconsole 的目录中编辑名为logging.properties 的文件,添加:
然后,使用以下命令启动 jconsole:
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:
Then, start jconsole with:
如果您在 Linux 上工作,请修改 catalina.sh 文件添加:
则以 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]”符号逐行分隔每个选项。
希望能帮助到你
if you are working on linux, modify the catalina.sh file adding:
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.
Hope it helps