如何在JVM上激活JMX以使用jconsole进行访问?
当前回答
注意,Java 6的最新版本允许jconsole将自己附加到正在运行的进程上,即使在没有JMX咒语的情况下启动了进程。
如果可以使用jvisualvm,也可以考虑jvisualvm,因为它提供了大量关于运行进程的信息,包括一个分析器。
其他回答
相关文件可在此找到:
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
以下选项适合我:
-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
连同下面的命令行参数,
-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进程是否已经使用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端口。
我使用的是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
推荐文章
- javac和Eclipse编译器之间的区别是什么?
- 工厂模式和策略模式之间的区别是什么?
- 在Java中使用正则表达式提取值
- 如何允许所有网络连接类型HTTP和HTTPS在Android(9)馅饼?
- Intellij IDEA Java类在保存时不能自动编译
- 何时使用Mockito.verify()?
- 在maven中安装mvn到底做什么
- 不可变与不可修改的集合
- 如何在JSON中使用杰克逊更改字段名
- GSON -日期格式
- 如何从线程捕获异常
- 无法解析主机"<URL here>"没有与主机名关联的地址
- 如何在Java中打印二叉树图?
- String.format()在Java中格式化双重格式
- com.jcraft.jsch.JSchException: UnknownHostKey