java - 无法禁用远程 Spring Boot JMX 访问
问题描述
我们有一个带有执行器的 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'
}
解决方案
有完全相同的问题并通过使用以下设置解决了它:
-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>
请注意,即使显然不需要,也可能需要order 和明确地将属性设置为其默认值。
推荐阅读
- google-apps-script - Bit.ly 从 Google Apps 脚本给出 404
- emacs - Emacs 模式行单击更改缓冲区
- android - 更改android芯片图标位置
- ruby - 单击按钮时,我希望将选定的字段 id 传递给给定的路径
- php - PAM 需要 exec/shell_exec 的密码,即使在 /etc/sudoers 中使用 NOPASSWD
- list - Python:我不明白为什么结果中的数字或多或少
- javascript - CSS Long 字体不适合屏幕的问题
- spring - 使用 Kubernetes 冲刺云数据流:BackoffLimit
- reactjs - 无法从“index.js”解析自定义组件的模块
- scala - 如何为多个键值应用 regexp_replace spark 函数?