如何在 JVM 上激活 JMX 以使用 jconsole 进行访问?
如何在 JVM 上激活 JMX 以使用 jconsole 进行访问?
How to activate JMX on a JVM for access with jconsole?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何在 JVM 上激活 JMX 以使用 jconsole 进行访问?
How to activate JMX on a JVM for access with jconsole?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(12)
我正在使用 WAS ND 7.0
我的 JVM 需要在 JConsole 中监视以下所有参数
I'm using WAS ND 7.0
My JVM need all the following arguments to be monitored in JConsole
随着下面的命令行参数,
有时在linux服务器中,imx连接不成功。 这是因为,在云linux主机中,在/etc/hosts中,主机名解析为主机地址。
解决此问题的最佳方法是,从网络中的其他计算机 ping 特定的 Linux 服务器,并在 中使用该主机 IP 地址,
但切勿依赖使用 ifconfig.me 从 Linux 服务器获取的 IP 地址。 您在那里获得的 IP 是主机文件中存在的屏蔽 IP。
along with below command line parameters ,
Sometimes in the linux servers , imx connection doesn't get succeeded. that is because , in cloud linux host, in /etc/hosts so that the hostname resolves to the host address.
the best way to fix it is, ping the particular linux server from other machine in network and use that host IP address in the
But never rely on the ipaddress that you get from linux server using ifconfig.me. the ip that you get there is masked one which is present in the host file.
以下选项对我有用:
并记住在服务器中打开 9010 端口
The below options works for me:
and remember to open 9010 port in the server
使用以下命令行参数运行您的 java 应用程序:
如果您不想在 jmx 上设置数字证书,请务必使用 -Dcom.sun.management.jmxremote.ssl=false 参数主持人。
如果您在 IP 地址为 192.168.0.1 的计算机上启动应用程序,请打开 jconsole,将 192.168.0.1:8855 放入 远程进程字段,然后单击连接。
Run your java application with the following command line parameters:
It is important to use the -Dcom.sun.management.jmxremote.ssl=false parameter if you don't want to setup digital certificates on the jmx host.
If you started your application on a machine having IP address 192.168.0.1, open jconsole, put 192.168.0.1:8855 in the Remote Process field, and click Connect.
第 1 步:使用以下参数运行应用程序。
上述参数将应用程序绑定到端口 9999。
步骤 2: 通过在命令提示符或终端中执行命令 jconsole 来启动 jconsole。
选择“远程进程:”并输入 URL {IP_Address}:9999,然后单击“连接”按钮连接到远程应用程序。
您可以参考此链接< /a> 以获得完整的应用程序。
Step 1: Run the application using following parameters.
Above arguments bind the application to the port 9999.
Step 2: Launch jconsole by executing the command jconsole in command prompt or terminal.
Select ‘Remote Process:’ and enter the url as {IP_Address}:9999 and click on Connect button to connect to the remote application.
You can refer this link for complete application.
使用远程进程选项运行本地进程 JCONSOLE
要在本地运行,这对我有用 -
我将其添加到我的 vm 参数中 -
RUN LOCAL PROCESS JCONSOLE using Remote Process option
To run locally, this worked for me -
I added this in my vm args -
首先,您需要检查您的 java 进程是否已经使用 JMX 参数运行。 执行此操作:
检查您需要监视的 java 进程。 如果您可以看到 jmx rmi 参数 Djmx.rmi.registry.port=xxxx ,则使用 java VisualVM 中此处提到的端口在 jmx 连接下远程连接它。
如果它不是通过 jmx rmi 端口运行,那么您需要使用以下参数运行 java 进程:
注意:端口号基于您的选择。
现在您可以使用此端口进行 jmx 连接。 这里是端口
1234
。First you need to check if your java process is already running with JMX parameters. Do this:
Check your java process you need to monitor. If you can see jmx rmi parameter Djmx.rmi.registry.port=xxxx then use the port mentioned here in your java visualvm to connect it remotely under jmx connection.
If it's not running through jmx rmi port then you need to run your java process with below mentioned parameters :
Note: port numbers are based on your choice.
Now you can use this port for jmx coneection. Here it is port
1234
.我遇到了这个问题,创建了一个 GitHub 项目来测试和弄清楚正确的设置。
它包含一个带有支持脚本的工作
Dockerfile
,以及一个用于快速测试的简单docker-compose.yml
。I had this exact issue, and created a GitHub project for testing and figuring out the correct settings.
It contains a working
Dockerfile
with supporting scripts, and a simpledocker-compose.yml
for quick testing.相关文档可以在这里找到:
http://java .sun.com/javase/6/docs/technotes/guides/management/agent.html
使用以下参数启动程序:
例如:
-Dcom.sun.management.jmxremote.local。 only=false
不一定是必需的但如果没有它,它就无法在 Ubuntu 上运行。 错误会是这样的
这个:
请参阅 https://bugs.java.com/bugdatabase/view_bug?bug_id=6754672< /a>
还要小心
-Dcom.sun.management.jmxremote.authenticate=false
使任何人都可以访问,但如果您仅使用它来跟踪 JVM
你的本地机器并不重要。
更新:
在某些情况下我无法访问服务器。 如果我也设置此参数,则可以修复此问题:
-Djava.rmi.server.hostname=127.0.0.1
The relevant documentation can be found here:
http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html
Start your program with following parameters:
For instance like this:
-Dcom.sun.management.jmxremote.local.only=false
is not necessarily requiredbut without it, it doesn't work on Ubuntu. The error would be something like
this:
see https://bugs.java.com/bugdatabase/view_bug?bug_id=6754672
Also be careful with
-Dcom.sun.management.jmxremote.authenticate=false
whichmakes access available for anyone, but if you only use it to track the JVM on
your local machine it doesn't matter.
Update:
In some cases I was not able to reach the server. This was then fixed if I set this parameter as well:
-Djava.rmi.server.hostname=127.0.0.1
在 Docker 容器中运行会带来一系列额外的连接问题,因此希望这对某人有所帮助。 我最终需要添加以下选项,我将在下面进行解释:
DOCKER_HOST_IP
与本地使用 jconsole 不同,您必须公布与在容器内可能看到的不同的 IP。 您需要将
${DOCKER_HOST_IP}
替换为 Docker 主机的外部可解析 IP(DNS 名称)。JMX远程& RMI 端口
看起来 JMX 还需要访问远程管理界面(jstat)在仲裁连接时使用不同的端口来传输一些数据。 我在
jconsole
中没有看到任何明显的地方可以设置此值。 在链接的文章中,过程是:jconsole
进行连接jconsole
尝试使用哪个端口iptables
/<必要时设置 code>firewall 规则以允许该端口连接虽然这有效,但它肯定不是一个自动化的解决方案。 我选择从 jconsole 升级到 VisualVM 因为它允许您显式指定 < code>jstatd 正在运行。 在 VisualVM 中,添加新的远程主机并使用与上面指定的值相关的值对其进行更新:
然后右键单击新的远程主机连接并
添加 JMX 连接...
不要忘记选中
不需要 SSL 连接
复选框。 希望这能让您建立联系。Running in a Docker container introduced a whole slew of additional problems for connecting so hopefully this helps someone. I ended up needed to add the following options which I'll explain below:
DOCKER_HOST_IP
Unlike using jconsole locally, you have to advertise a different IP than you'll probably see from within the container. You'll need to replace
${DOCKER_HOST_IP}
with the externally resolvable IP (DNS Name) of your Docker host.JMX Remote & RMI Ports
It looks like JMX also requires access to a remote management interface (jstat) that uses a different port to transfer some data when arbitrating the connection. I didn't see anywhere immediately obvious in
jconsole
to set this value. In the linked article the process was:jconsole
with logging enabledjconsole
attempted to useiptables
/firewall
rules as necessary to allow that port to connectWhile that works, it's certainly not an automatable solution. I opted for an upgrade from jconsole to VisualVM since it let's you to explicitly specify the port on which
jstatd
is running. In VisualVM, add a New Remote Host and update it with values that correlate to the ones specified above:Then right-click the new Remote Host Connection and
Add JMX Connection...
Don't forget to check the checkbox for
Do not require SSL connection
. Hopefully, that should allow you to connect.请注意,最新版本的 Java 6 允许 jconsole 将自身附加到正在运行的进程,即使在没有 JMX 咒语的情况下启动该进程也是如此。
如果您可以使用,还可以考虑 jvisualvm,因为它提供了有关正在运行的进程的大量信息,包括分析器。
Note, Java 6 in the latest incarnation allows for jconsole to attach itself to a running process even after it has been started without JMX incantations.
If that is available to you, also consider jvisualvm as it provides a wealth of information on running processes, including a profiler.
在 Linux 上,我使用了以下参数:
并且还编辑了 /etc/hosts,以便主机名解析为主机地址 (192.168.0.x),而不是环回地址 (127.0.0.1)
On Linux, I used the following params:
and also I edited
/etc/hosts
so that the hostname resolves to the host address (192.168.0.x) rather than the loopback address (127.0.0.1)