这是"How to access JMX interface in docker from outside?“之后的内容,它讨论了如何建立未加密的JMX连接。
我可以使用Glassfish使用的RMI或JMXMP。
有一组必需的JVM选项,我正在寻找使用SSL设置JMX所需的更改:
com.sun.management.jmxremote=true
com.sun.management.jmxremote.local.only=false
com.sun.management.jmxremote.ssl=true
com.sun.management.jmxremote.authenticate=true
com.sun.management.jmxremote.port=12345
com.sun.management.jmxremote.rmi.port=12346
java.rmi.server.hostname=10.11.12.176
com.sun.management.jmxremote.access.file=/.secure/jmxremote.access
com.sun.management.jmxremote.password.file=/.secure/jmxremote.pass
com.sun.management.jmxremote.login.config=ldap-ad-config
java.net.preferIPv4Stack=true
com.sun.management.jmxremote.ssl.config.file=/.secure/jmxremotessl.properties
javax.net.ssl.keyStore=/config/app.jks
javax.net.ssl.keyStorePassword=teabag
javax.net.ssl.trustStore=/config/cacerts
javax.net.ssl.trustStorePassword=milk问题是一样的:
java.rmi.ConnectException: Connection refused to host: 172.0.0.85; nested exception is
java.net.ConnectException: Operation timed out该IP地址是docker容器的内部IP地址。我假设尽管使用了java.rmi.server.hostname解决方案,这种情况还是会发生,因为它是基于SSL的。
我尝试使用nginx将SSL反向代理为非SSL,但失败并出现错误
java.rmi.ConnectIOException: non-JRMP server at remote endpoint所以我想我应该在nginx中转发额外的报头。
我现在正在尝试设置JMXMP,但是关于如何设置JMXMP的文档非常少。有一个Spring实现和一个Glassfish实现,但(到目前为止)还没有可查找的文档-所以我添加了glassfish标签。
发布于 2018-01-19 02:57:07
答案是,我可以将我的应用程序设置为使用JMXMP,并使用以下TLS选项将其配置为实现JVM连接:
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=true
-Dcom.sun.management.jmxremote.ssl=true
-Dcom.sun.management.jmxremote.access.file=C:/dev/.secure/jmxremote.access
-Dcom.sun.management.jmxremote.password.file=C:/dev/.secure/jmxremote.pass
-Dcom.sun.management.jmxremote.login.config=spnego-server
-Djava.net.preferIPv4Stack=true
-Dcom.sun.management.jmxremote.ssl.config.file=/.secure/jmxremotessl.properties但是,我必须编写一个configuration类来启动JMXConnectorServer,如下所示:
@Configuration
public class JmxServer {
public JmxServer(
@Value("${jmx.remote.hostname}") final String hostname,
@Value("${jmx.remote.port}") final String port) {
try {
Map<String, Object> env = new HashMap<>();
env.put("jmx.remote.profiles", "TLS SASL/PLAIN");
env.put(JMXConnector.CREDENTIALS,
new String[] {"myusername", "password"});
JMXConnectorServerFactory.newJMXConnectorServer(
new JMXServiceURL(
String.format("service:jmx:jmxmp://%s:%s",
hostname, port)),
env,
ManagementFactory.getPlatformMBeanServer()
).start();
} catch (IOException e) {
e.printStackTrace();
}
}
}但这只是其中的一半。我现在正在和JConsole争论,让它和TLS一起做JMXMP。
为此,我在Oracle论坛上关注了2007年的这个化石问题:
Can JConsole connect to a remote JMX agent using JMXMP and TLS?
但仍在挣扎..。
https://stackoverflow.com/questions/48288310
复制相似问题