如何在 JVM 上激活 JMX 以使用 jconsole 进行访问?

发布于 2024-07-20 04:28:34 字数 41 浏览 4 评论 0原文

如何在 JVM 上激活 JMX 以使用 jconsole 进行访问?

How to activate JMX on a JVM for access with jconsole?

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

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

发布评论

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

评论(12

萝莉病 2024-07-27 04:28:35

我正在使用 WAS ND 7.0

我的 JVM 需要在 JConsole 中监视以下所有参数

    -Djavax.management.builder.initial= 
    -Dcom.sun.management.jmxremote 
    -Dcom.sun.management.jmxremote.port=8855 
    -Dcom.sun.management.jmxremote.authenticate=false 
    -Dcom.sun.management.jmxremote.ssl=false

I'm using WAS ND 7.0

My JVM need all the following arguments to be monitored in JConsole

    -Djavax.management.builder.initial= 
    -Dcom.sun.management.jmxremote 
    -Dcom.sun.management.jmxremote.port=8855 
    -Dcom.sun.management.jmxremote.authenticate=false 
    -Dcom.sun.management.jmxremote.ssl=false
梅窗月明清似水 2024-07-27 04:28:35

随着下面的命令行参数,

-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

有时在linux服务器中,imx连接不成功。 这是因为,在云linux主机中,在/etc/hosts中,主机名解析为主机地址。

解决此问题的最佳方法是,从网络中的其他计算机 ping 特定的 Linux 服务器,并在 中使用该主机 IP 地址,

-Djava.rmi.server.hostname=IP address that obtained when you ping that linux server.

但切勿依赖使用 ifconfig.me 从 Linux 服务器获取的 IP 地址。 您在那里获得的 IP 是主机文件中存在的屏蔽 IP。

along with below command line parameters ,

-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

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

-Djava.rmi.server.hostname=IP address that obtained when you ping that linux server.

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.

等待圉鍢 2024-07-27 04:28:35

以下选项对我有用:

-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.rmi.port=9010
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname={host name}

并记住在服务器中打开 9010 端口

sudo ufw allow 9010/udp
sudo ufw allow 9010/tcp
sudo ufw reload

The below options works for me:

-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.rmi.port=9010
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname={host name}

and remember to open 9010 port in the server

sudo ufw allow 9010/udp
sudo ufw allow 9010/tcp
sudo ufw reload
灼痛 2024-07-27 04:28:35

使用以下命令行参数运行您的 java 应用程序:

-Dcom.sun.management.jmxremote.port=8855
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

如果您不想在 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:

-Dcom.sun.management.jmxremote.port=8855
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

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.

我恋#小黄人 2024-07-27 04:28:35

第 1 步:使用以下参数运行应用程序。

-Dcom.sun.management.jmxremote.port=9999 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false

上述参数将应用程序绑定到端口 9999。

步骤 2: 通过在命令提示符或终端中执行命令 jconsole 来启动 jconsole。

选择“远程进程:”并输入 URL {IP_Address}:9999,然后单击“连接”按钮连接到远程应用程序。

您可以参考此链接< /a> 以获得完整的应用程序。

Step 1: Run the application using following parameters.

-Dcom.sun.management.jmxremote.port=9999 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false

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.

惟欲睡 2024-07-27 04:28:35

使用远程进程选项运行本地进程 JCONSOLE

要在本地运行,这对我有用 -

我将其添加到我的 vm 参数中 -

-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=6001
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=localhost
-Dcom.sun.management.jmxremote.rmi.port=6001
  • 我通过以下方式打开 JConsole Intellij 终端
  • 它在本地向我显示所有 PID 为灰色,
  • 所以我选择了远程进程并使用主机登录 - localhost:6001
  • 保留空用户名和名称。 密码
  • 然后单击连接

  • 确保端口 6001 上没有其他进程正在运行。您也可以使用其他端口。

RUN LOCAL PROCESS JCONSOLE using Remote Process option

To run locally, this worked for me -

I added this in my vm args -

-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=6001
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=localhost
-Dcom.sun.management.jmxremote.rmi.port=6001
  • I opened JConsole via Intellij Terminal
  • It was showing me all PID's in grey in local
  • So I selected remote process and logged in using host - localhost:6001
  • Keep empty username & password
  • Then click connect

  • Make sure no other process is running on port 6001. You can also use other ports.
維他命╮ 2024-07-27 04:28:35

首先,您需要检查您的 java 进程是否已经使用 JMX 参数运行。 执行此操作:

ps -ef | grep java

检查您需要监视的 java 进程。 如果您可以看到 jmx rmi 参数 Djmx.rmi.registry.port=xxxx ,则使用 java VisualVM 中此处提到的端口在 jmx 连接下远程连接它。

如果它不是通过 jmx rmi 端口运行,那么您需要使用以下参数运行 java 进程:

-Djmx.rmi.registry.port=1234 -Djmx.rmi.port=1235 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false

注意:端口号基于您的选择。

现在您可以使用此端口进行 jmx 连接。 这里是端口1234

First you need to check if your java process is already running with JMX parameters. Do this:

ps -ef | grep java

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 :

-Djmx.rmi.registry.port=1234 -Djmx.rmi.port=1235 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false

Note: port numbers are based on your choice.

Now you can use this port for jmx coneection. Here it is port 1234.

风透绣罗衣 2024-07-27 04:28:35

我遇到了这个问题,创建了一个 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 simple docker-compose.yml for quick testing.

糖粟与秋泊 2024-07-27 04:28:34

相关文档可以在这里找到:

http://java .sun.com/javase/6/docs/technotes/guides/management/agent.html

使用以下参数启动程序:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.rmi.port=9010
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

例如:

java -Dcom.sun.management.jmxremote \
  -Dcom.sun.management.jmxremote.port=9010 \
  -Dcom.sun.management.jmxremote.local.only=false \
  -Dcom.sun.management.jmxremote.authenticate=false \
  -Dcom.sun.management.jmxremote.ssl=false \
  -jar Notepad.jar

-Dcom.sun.management.jmxremote.local。 only=false 不一定是必需的
但如果没有它,它就无法在 Ubuntu 上运行。 错误会是这样的
这个:

01 Oct 2008 2:16:22 PM sun.rmi.transport. customer .TCPTransport$AcceptLoop executeAcceptLoop
WARNING: RMI TCP Accept-0: accept loop for ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=37278] throws
java.io.IOException: The server sockets created using the LocalRMIServerSocketFactory only accept connections from clients running on the host where the RMI remote objects have been exported.
    at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:89)
    at sun.rmi.transport. customer .TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:387)
    at sun.rmi.transport. customer .TCPTransport$AcceptLoop.run(TCPTransport.java:359)
    at java.lang.Thread.run(Thread.java:636)

请参阅 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:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.rmi.port=9010
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

For instance like this:

java -Dcom.sun.management.jmxremote \
  -Dcom.sun.management.jmxremote.port=9010 \
  -Dcom.sun.management.jmxremote.local.only=false \
  -Dcom.sun.management.jmxremote.authenticate=false \
  -Dcom.sun.management.jmxremote.ssl=false \
  -jar Notepad.jar

-Dcom.sun.management.jmxremote.local.only=false is not necessarily required
but without it, it doesn't work on Ubuntu. The error would be something like
this:

01 Oct 2008 2:16:22 PM sun.rmi.transport. customer .TCPTransport$AcceptLoop executeAcceptLoop
WARNING: RMI TCP Accept-0: accept loop for ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=37278] throws
java.io.IOException: The server sockets created using the LocalRMIServerSocketFactory only accept connections from clients running on the host where the RMI remote objects have been exported.
    at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:89)
    at sun.rmi.transport. customer .TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:387)
    at sun.rmi.transport. customer .TCPTransport$AcceptLoop.run(TCPTransport.java:359)
    at java.lang.Thread.run(Thread.java:636)

see https://bugs.java.com/bugdatabase/view_bug?bug_id=6754672

Also be careful with -Dcom.sun.management.jmxremote.authenticate=false which
makes 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

情场扛把子 2024-07-27 04:28:34

在 Docker 容器中运行会带来一系列额外的连接问题,因此希望这对某人有所帮助。 我最终需要添加以下选项,我将在下面进行解释:

-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=${DOCKER_HOST_IP}
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.rmi.port=9998

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 连接...

添加 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:

-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=${DOCKER_HOST_IP}
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.rmi.port=9998

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:

  • Try and connect from jconsole with logging enabled
  • Fail
  • Figure out which port jconsole attempted to use
  • Use iptables/firewall rules as necessary to allow that port to connect

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

Add Remote Host

Then right-click the new Remote Host Connection and Add JMX Connection...

Add JMX Connection

Don't forget to check the checkbox for Do not require SSL connection. Hopefully, that should allow you to connect.

稚然 2024-07-27 04:28:34

请注意,最新版本的 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.

甲如呢乙后呢 2024-07-27 04:28:34

在 Linux 上,我使用了以下参数:

-Djavax.management.builder.initial= 
-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=9010 
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false

并且还编辑了 /etc/hosts,以便主机名解析为主机地址 (192.168.0.x),而不是环回地址 (127.0.0.1)

On Linux, I used the following params:

-Djavax.management.builder.initial= 
-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=9010 
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false

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)

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