【问题标题】:Cannot disable remote Spring Boot JMX access无法禁用远程 Spring Boot JMX 访问
【发布时间】:2019-10-25 17:49:12
【问题描述】:

我们有一个带有执行器的 Spring Boot 应用程序。我们正在尝试禁用远程 JMX 访问,但不知何故这不起作用。我们尝试了以下设置:

在 Tomcat 启动选项中:

-Dcom.sun.management.jmxremote=false
-Dcom.sun.management.jmxremote.password.file=....../jmxremote.password
-Dcom.sun.management.jmxremote.registry.ssl=true 
-Djava.security.manager 
-Djava.security.policy=jmx.policy
-Djavax.net.ssl.keyStore=....jks
-Djavax.net.ssl.keyStorePassword=****
-Djavax.net.ssl.trustStore=.....jks
-Djavax.net.ssl.trustStorePassword=****

在 application.properties 中:

spring.jmx.enabled=false
spring.datasource.jmx-enabled=false
endpoints.jmx.enabled=false
spring.jmx.server=localhost

但是,我们仍然可以从远程系统访问 JMX。选项 spring.jmx.enabled 的唯一区别是 Spring 特定的 MBean 不可用,但其他 MBean 仍然可用。

我们如何禁用对 JMX 的远程访问?理想情况下,我们仍然希望在从本地计算机连接时进行访问,但如有必要,这也可能会被禁用。

添加 build.gradle

buildscript {
    ext {
        springBootVersion = '1.5.16.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply from: "../dependencies.gradle"

repositories {
    mavenCentral()
}

bootRepackage {
    enabled = false
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    providedRuntime project(':....')
    compile project(':...')
    compile project(':...')
    compile project(':...')
    compile project(':...')

    compile group: 'com.hazelcast', name: 'hazelcast', version: '3.12'
    compile group: 'com.hazelcast', name: 'hazelcast-client', version: '3.12'
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.11.Final'
    compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.9.2'

    compile group: 'org.apache.poi', name: 'poi', version: '4.0.1'
    compile group: 'org.apache.poi', name: 'poi-ooxml', version: '4.0.1'

    compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.2'

    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'

    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-actuator")

    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile group: 'org.mockito', name: 'mockito-all', version: '1.9.5'
}

【问题讨论】:

  • 如果删除所有启动选项会怎样?
  • 我们当然是这样开始的。结果:远程 JMX 可能(未经身份验证)。之后,我们开始试验属性和启动选项,直到现在都没有成功。
  • 当没有配置任何东西时,我看不到 JMX 远程正在启动。您可以在哪个端口上远程访问 JMX?
  • JMX 在端口 1099 上可用
  • 我无法重现您的问题。您的 Maven 或 Gradle 文件是什么样的?

标签: java spring-boot jmx spring-boot-actuator


【解决方案1】:

遇到了完全相同的问题并通过使用这些设置解决了它:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.local.only=true
-Dcom.sun.management.jmxremote.authenticate=true
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.host=localhost
-Djava.rmi.server.hostname=localhost
-Dcom.sun.management.jmxremote.password.file=<path to jmxremote.password>
-Dcom.sun.management.jmxremote.access.file=<path to jmxremote.access>

请注意,尽管显然不需要,但可能需要将属性排序和显式设置为其默认值。

【讨论】:

    【解决方案2】:

    基于 Diederik 的解决方案,需要更改两个属性

    1. 将身份验证设置为真。并且还要指定password.file和access.file。

    2. 将主机设置为 localhost 或 127.0.0.1。

    如果 authenticate 为 false 或 host 不是 localhost,将启用远程访问。

    这是一个示例

    -Dcom.sun.management.jmxremote \
    -Dcom.sun.management.jmxremote.port=1099 \
    -Dcom.sun.management.jmxremote.host=localhost \
    -Dcom.sun.management.jmxremote.authenticate=true \
    -Dcom.sun.management.jmxremote.password.file=<path to password file> \
    -Dcom.sun.management.jmxremote.access.file=<path to access file> \
    -Dcom.sun.management.jmxremote.ssl=false \
    

    【讨论】:

      猜你喜欢
      • 2015-06-07
      • 2019-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-03
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多