如何在JVM上激活JMX以使用jconsole进行访问?
当前回答
注意,Java 6的最新版本允许jconsole将自己附加到正在运行的进程上,即使在没有JMX咒语的情况下启动了进程。
如果可以使用jvisualvm,也可以考虑jvisualvm,因为它提供了大量关于运行进程的信息,包括一个分析器。
其他回答
使用以下命令行参数运行java应用程序:
-Dcom.sun.management.jmxremote.port=8855
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
使用-Dcom.sun.management.jmxremote非常重要。如果不想在JMX主机上设置数字证书,则使用Ssl =false参数。
如果在IP地址为192.168.0.1的机器上启动应用程序,则打开jconsole,在Remote Process字段中输入192.168.0.1:8855,然后单击Connect。
我有这个确切的问题,并创建了一个GitHub项目来测试和找出正确的设置。
它包含一个工作Dockerfile和支持脚本,以及一个简单的docker-compose。Yml快速测试。
相关文件可在此找到:
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)
参见http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6754672
还要小心使用-Dcom.sun.management.jmxremote。验证= false, 任何人都可以访问,但是如果您只使用它来跟踪JVM 您的本地机器并不重要。
更新:
在某些情况下,我无法连接到服务器。如果我也设置了这个参数,这个问题就得到了解决:-Djava.rmi.server.hostname=127.0.0.1
步骤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,然后单击连接按钮连接到远程应用程序。
您可以参考此链接以获得完整的应用程序。
连同下面的命令行参数,
-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.
但是永远不要依赖于你从linux服务器上使用ifconfig.me获得的ipaddress。你得到的IP是掩码的,在主机文件中。
推荐文章
- 在流中使用Java 8 foreach循环移动到下一项
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 用Java计算两个日期之间的天数
- 如何配置slf4j-simple
- 在Jar文件中运行类
- 带参数的可运行?
- 我如何得到一个字符串的前n个字符而不检查大小或出界?
- 我可以在Java中设置enum起始值吗?
- Java中的回调函数
- c#和Java中的泛型有什么不同?和模板在c++ ?
- 在Java中,流相对于循环的优势是什么?
- Jersey在未找到InjectionManagerFactory时停止工作
- 在Java流是peek真的只是调试?
- Recyclerview不调用onCreateViewHolder
- 将JSON字符串转换为HashMap