Java 如何在远程 Glassfish 服务器上激活 JMX 以使用 jconsole 进行访问?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1231868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 01:10:18  来源:igfitidea点击:

How to activate JMX on remote Glassfish server for access with jconsole?

javaglassfishjmxjconsole

提问by Pavel

I would like to monitor remote glassfish server. I have enabled JMX Connection in domain.xml:

我想监控远程 glassfish 服务器。我在 domain.xml 中启用了 JMX 连接:

<jmx-connector accept-all="true" address="0.0.0.0" auth-realm-name="admin-realm" enabled="true" name="system" port="8686" protocol="rmi_jrmp" security-enabled="false">

But this didn't help. I still can't connect to server with JConsole. Then I've found solution - I need to specify JVM properties in domain.xml to open 8686 port for remote connection. So I added this lines into java-configsection:

但这没有帮助。我仍然无法使用 JConsole 连接到服务器。然后我找到了解决方案 - 我需要在 domain.xml 中指定 JVM 属性以打开 8686 端口进行远程连接。所以我将此行添加到java-config部分:

<jvm-options>-Dcom.sun.management.jmxremote</jvm-options>
<jvm-options>-Dcom.sun.management.jmxremote.port=8686</jvm-options>
<jvm-options>-Dcom.sun.management.jmxremote.local.only=false</jvm-options>
<jvm-options>-Dcom.sun.management.jmxremote.authenticate=false</jvm-options>

But now when I'm starting server, I'm getting following errors:

但是现在当我启动服务器时,出现以下错误:

Could not load Logmanager "com.sun.enterprise.server.logging.ServerLogManager" java.lang.ClassNotFoundException: com.sun.enterprise.server.logging.ServerLogManager at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.util.logging.LogManager$1.run(LogManager.java:166) at java.security.AccessController.doPrivileged(Native Method) at java.util.logging.LogManager.(LogManager.java:156) at java.util.logging.Logger.getLogger(Logger.java:273) at sun.management.snmp.util.MibLogger.(MibLogger.java:57) at sun.management.snmp.util.MibLogger.(MibLogger.java:42) at sun.management.jmxremote.ConnectorBootstrap.(ConnectorBootstrap.java:760) at sun.management.Agent.startAgent(Agent.java:127) at sun.management.Agent.startAgent(Agent.java:239) javax.management.JMRuntimeException: Failed to load MBeanServerBuilder class com.sun.enterprise.admin.server.core.jmx.AppServerMBeanServerBuilder: java.lang.ClassNotFoundException: com.sun.enterprise.admin.server.core.jmx.AppServerMBeanServerBuilder at javax.management.MBeanServerFactory.checkMBeanServerBuilder(MBeanServerFactory.java:480) at javax.management.MBeanServerFactory.getNewMBeanServerBuilder(MBeanServerFactory.java:511) at javax.management.MBeanServerFactory.newMBeanServer(MBeanServerFactory.java:298) at javax.management.MBeanServerFactory.createMBeanServer(MBeanServerFactory.java:213) at javax.management.MBeanServerFactory.createMBeanServer(MBeanServerFactory.java:174) at sun.management.ManagementFactory.createPlatformMBeanServer(ManagementFactory.java:302) at java.lang.management.ManagementFactory.getPlatformMBeanServer(ManagementFactory.java:504) at sun.management.jmxremote.ConnectorBootstrap.initialize(ConnectorBootstrap.java:392) at sun.management.Agent.startAgent(Agent.java:127) at sun.management.Agent.startAgent(Agent.java:239) Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.admin.server.core.jmx.AppServerMBeanServerBuilder at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at javax.management.MBeanServerFactory.loadBuilderClass(MBeanServerFactory.java:423) at javax.management.MBeanServerFactory.checkMBeanServerBuilder(MBeanServerFactory.java:465) ... 9 more Exception thrown by the agent : javax.management.JMRuntimeException: Failed to load MBeanServerBuilder class com.sun.enterprise.admin.server.core.jmx.AppServerMBeanServerBuilder: java.lang.ClassNotFoundException: com.sun.enterprise.admin.server.core.jmx.AppServerMBeanServerBuilder

无法加载日志管理器“com.sun.enterprise.server.logging.ServerLogManager”java.lang.ClassNotFoundException:com.sun.enterprise.server.logging.ServerLogManager at java.net.URLClassLoader$1.run(URLClassLoader.java:200)在 java.security.AccessController.doPrivileged(Native Method) 在 java.net.URLClassLoader.findClass(URLClassLoader.java:188) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:307) 在 sun.misc.Launcher$AppClassLoader .loadClass(Launcher.java:301) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:252) 在 java.util.logging.LogManager$1.run(LogManager.java:166) 在 java.security.AccessController.doPrivileged (本机方法)在 java.util.logging.LogManager.(LogManager.java:156) 在 java.util.logging.Logger。getLogger(Logger.java:273) at sun.management.snmp.util.MibLogger.(MibLogger.java:57) at sun.management.snmp.util.MibLogger.(MibLogger.java:42) at sun.management.jmxremote .ConnectorBootstrap.(ConnectorBootstrap.java:760) at sun.management.Agent.startAgent(Agent.java:127) at sun.management.Agent.startAgent(Agent.java:239) javax.management.JMRuntimeException: 无法加载 MBeanServerBuilder类 com.sun.enterprise.admin.server.core.jmx.AppServerMBeanServerBuilder:java.lang.ClassNotFoundException:com.sun.enterprise.admin.server.core.jmx.AppServerMBeanServerBuilder 在 javax.management.MBeanServerFactory.checkMBeanServerBuilder(MBeanServerFactory.java :480) 在 javax.management.MBeanServerFactory.getNewMBeanServerBuilder(MBeanServerFactory.java:511) 在 javax。management.MBeanServerFactory.newMBeanServer(MBeanServerFactory.java:298) at javax.management.MBeanServerFactory.createMBeanServer(MBeanServerFactory.java:213) at javax.management.MBeanServerFactory.createMBeanServer(MBeanServerFactory.java:174) at sun.management.ManagementFactory.createPlatformMBeanServer (ManagementFactory.java:302) at java.lang.management.ManagementFactory.getPlatformMBeanServer(ManagementFactory.java:504) at sun.management.jmxremote.ConnectorBootstrap.initialize(ConnectorBootstrap.java:392) at sun.management.Agent.startAgent( Agent.java:127) at sun.management.Agent.startAgent(Agent.java:239) 由:java.lang.ClassNotFoundException: com.sun.enterprise.admin.server.core.jmx.AppServerMBeanServerBuilder at java.net。 URLClassLoader$1。run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307)在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:252) 在 javax.management.MBeanServerFactory.loadBuilderClass(MBeanServerFactory.java:423) 在 javax。 management.MBeanServerFactory.checkMBeanServerBuilder(MBeanServerFactory.java:465) ... 代理抛出的另外 9 个异常:javax.management.JMRuntimeException:无法加载 MBeanServerBuilder 类 com.sun.enterprise.admin.server.core.jmx.AppServerMBeanServerBuilder: java.lang.ClassNotFoundException:com.sun.enterprise.admin.server。core.jmx.AppServerMBeanServerBuilder

How can I fix the problem?

我该如何解决这个问题?

Thanks in advance.

提前致谢。

采纳答案by Pavel

Steps to solve the problem are: 1. use default settings 2. add -Djava.rmi.server.hostname= in the JVM Options of the instance of GlassFish.

解决问题的步骤是: 1. 使用默认设置 2. 在 GlassFish 实例的 JVM Options 中添加 -Djava.rmi.server.hostname=。

回答by Grzegorz Oledzki

回答by tronda

I ended up setting the following option to ensure that JMX with Glassfish is firewall friendly:

我最终设置了以下选项以确保带有 Glassfish 的 JMX 是防火墙友好的:

<jvm-options>-Dcom.sun.aas.jconsole.server.cbport=XXXX</jvm-options>

Where XXXX is the port number that you use in the firewall together with the application server configured JMX port number (usually 8686).

其中 XXXX 是您在防火墙中使用的端口号以及应用程序服务器配置的 JMX 端口号(通常为 8686)。

Read more in this blogpost. Note that this feature requires a newer version of Glassfish. I've successfully used it with Glassfish 2.1.1.

这篇博文中阅读更多内容。请注意,此功能需要更新版本的 Glassfish。我已经成功地将它与 Glassfish 2.1.1 一起使用。

回答by javadude

Still mystical behavior, but with these 4 settings you can connect to the JVM running Glassfish (add to domain.xml in admin console, restart required)

仍然是神秘的行为,但是通过这 4 个设置,您可以连接到运行 Glassfish 的 JVM(添加到管理控制台中的 domain.xml,需要重新启动)

-Djava.rmi.server.hostname=yourhost
-Dcom.sun.management.jmxremote.port=8686
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

Beware! This is not safe, as anyone now can connect a jconsole to it !

当心!这不安全,因为现在任何人都可以将 jconsole 连接到它!

IMO this is not the Glassfish way, which is using the JMX connector.

IMO 这不是 Glassfish 方式,它使用 JMX 连接器。

(Above works in GF 3.1)

(以上适用于 GF 3.1)

回答by Yu Chen

If run your application inside Glassfish app server, simply run the following asadmin command, you would need to restart all running servers for the change to take affect.

如果在 Glassfish 应用服务器中运行您的应用程序,只需运行以下 asadmin 命令,您需要重新启动所有正在运行的服务器以使更改生效。

./asadmin enable-secure-admin

./asadmin enable-secure-admin

There are extra Glassfish server configurations to further enable security, see more at Connecting remotely to Glassfish through JMX.

有额外的 Glassfish 服务器配置可以进一步启用安全性,请参阅通过 JMX 远程连接到 Glassfish 中的更多信息。

You do need to follow the steps on JVM options, these are instructions for Java applications in general. For a Java application that runs with Glassfish application server, simply using the asadm command. That saved me lots of time!

您确实需要遵循 JVM 选项的步骤,这些是 Java 应用程序的一般说明。对于与 Glassfish 应用服务器一起运行的 Java 应用程序,只需使用 asadm 命令。这为我节省了很多时间!

** Another note, with only the settings using JVM options, Glassfish would fail to start with the above runtime exceptions. ** I am using GF3.1.2 and above, and Java 7.

** 另一个注意事项,仅使用 JVM 选项的设置,Glassfish 将无法启动,并出现上述运行时异常。** 我使用的是 GF3.1.2 及更高版本,以及 Java 7。