通过 JConsole 公开资源以进行远程管理
原文: https://docs.oracle.com/javase/tutorial/jmx/remote/jconsole.html
如果使用现成的远程管理代理和现有的监视和管理工具(如 JConsole),则使用 JMX API 公开 Java 应用程序以进行远程管理非常简单。
要公开远程管理应用程序,需要使用正确的属性启动它。此示例显示如何公开 Main
JMX 代理以进行远程管理。
Security consideration:
为简单起见,在此示例中禁用了身份验证和加密安全机制。但是,在实际环境中实现远程管理时,应实现这些安全机制。 下一步是什么? 提供了指向其他 JMX 技术文档的指针,这些文档展示了如何激活安全性。
此示例需要 Java SE 平台的第 6 版。要远程监视Main
JMX 代理,请按照下列步骤操作:
- 如果尚未这样做,请将
jmx_examples.zip
保存到work_dir
目录中。 在终端窗口中使用以下命令解压缩示例类包。
unzip jmx_examples.zip
编译
work_dir
目录中的示例 Java 类。javac com/example/*.java
Start the
Main
application, specifying the properties that exposeMain
for remote management. (For Windows, use the carat (^
) instead of the backslash (\
) to break up a long command into multiple lines):java -Dcom.sun.management.jmxremote.port=9999 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
com.example.Main
生成
Main
正在等待发生某事的确认。Start JConsole in a different terminal window on a different machine:
jconsole
将显示“新建连接”对话框,其中列出了可以在本地连接的正在运行的 JMX 代理。
Select Remote Process, and type the following in the Remote Process field:
hostname:9999
在此地址中,
hostname
是运行Main
应用程序的远程机器的名称,9999 是开箱即用的 JMX 连接器将连接的端口号。Click Connect.
显示正在运行
Main
的 Java 虚拟机(Java VM)的当前活动的摘要。Click the MBeans tab.
此面板显示当前在远程 MBean 服务器中注册的所有 MBean。
In the left-hand frame, expand the
com.example
node in the MBean tree.您会看到
Main
创建并注册的示例 MBeanHello
。如果单击Hello
,您将在 MBean 树中看到其关联的属性和操作节点,即使它在另一台计算机上运行。要关闭 JConsole,请选择 Connection - >出口。