网贷之家网站建设,北京装修公司哪家口碑好一些,电子商务公司是做什么的,NET网站开发工程师网站招聘JMX和Springboot Actuator
JMX是Java Management Extensions#xff0c;它是一个Java平台的管理和监控接口。
为什么要搞JMX呢#xff1f;因为在所有的应用程序中#xff0c;对运行中的程序进行监控都是非常重要的#xff0c;Java应用程序也不例外。我们肯定希望知道Java…JMX和Springboot Actuator
JMX是Java Management Extensions它是一个Java平台的管理和监控接口。
为什么要搞JMX呢因为在所有的应用程序中对运行中的程序进行监控都是非常重要的Java应用程序也不例外。我们肯定希望知道Java应用程序当前的状态例如占用了多少内存分配了多少内存当前有多少活动线程有多少休眠线程等等。如何获取这些信息呢
为了标准化管理和监控Java平台使用JMX作为管理和监控的标准接口任何程序只要按JMX规范访问这个接口就可以获取所有管理与监控信息。
JMX把所有被管理的资源都称为MBeanManaged Bean这些MBean全部由MBeanServer管理如果要访问MBean可以通过MBeanServer对外提供的访问接口例如通过RMI或HTTP访问。
在生产环境中需要对应用程序的状态进行监控。前面我们已经介绍了使用JMX对Java应用程序包括JVM进行监控使用JMX需要把一些监控信息以MBean的形式暴露给JMX Server而Spring Boot已经内置了一个监控功能它叫Actuator。
如何使用Actuator
非常简单只需要在一个正常的Springboot项目的pom.xml里面添加如下依赖
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId
/dependency
对于 Gradle请使用以下声明
dependencies {implementation org.springframework.boot:spring-boot-starter-actuator
}
然后正常启动应用程序Actuator会把它能收集到的所有信息都暴露给JMX。
此外Actuator还可以通过URL/actuator/挂载一些监控点例如输入http://localhost:8080/actuator/health我们可以查看应用程序当前状态
{status: UP
}
许多网关作为反向代理需要一个URL来探测后端集群应用是否存活这个URL就可以提供给网关使用。
Actuator默认把所有访问点暴露给JMX但处于安全原因只有health和info会暴露给Web。
Actuator提供的所有访问点均在官方文档列出要暴露更多的访问点给Web需要在Springboot里面的application.yml中加上配置
management:endpoints:jmx:exposure:# exclude: *include: *web:exposure:include: [health,info,beans,mappings,logfile,metrics,shutdown,env]# include: *
gitee有个demo
配置Actuator
Actuator各个端点介绍都在
官方文档https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#actuatorhttps://blog.csdn.net/justry_deng/article/details/103308797https://www.cnblogs.com/jmcui/p/9820579.html
Actuator 接口文档
https://docs.spring.io/spring-boot/docs/2.5.4/actuator-api/htmlsingle/
Gateway配置
https://segmentfault.com/a/1190000019101829
部分踩坑
Gateway和spring-boot-starter-web冲突问题重要
https://blog.csdn.net/nlcexiyue/article/details/112345499
https://www.jb51.net/article/217600.htm
可以说两者几乎水火不容如果从starter-web排除tomcat会导致项目跑不起来如果从gateway里面排除starter-web会直接导致gateway功能不可用
IDEA打包报meta-inf/spring.factories not found
直接mvn命令打包
IDEA直接运行能运行但是打包成war或者jar报JMX找不到org.springframework.boot:nameSpringApplication,typeAdmin
原因spring.application.admin.enabledtrue是IDEA启动自己加上去的java -jar运行的时候没有
在application.yml里面加上spring.application.admin.enabledtrue
dockers跑Spring项目跑不起来报数据库连接失败
检查配置用户密码之类的是否正确有种情况需要jar报错退出再跑一次jar相当于连两次数据库
漏洞学习
利用场景和exphttps://github.com/LandGrey/SpringBootVulExploit
讲的十分详细了
MySQL JDBC POC报错
其中MySQL JDBC deserialization的poc有点问题解决方案如下
https://github.com/0xJDow/rogue-mysql-server
Float Conversion
Due to this error:
Traceback (most recent call last):File rogue-mysql-server.py, line 102, in modulerun_mysql_server()File rogue-mysql-server.py, line 63, in run_mysql_server_payload_hex str(hex(len(deserialization_payload)/2)).replace(0x, ).zfill(4)
TypeError: float object cannot be interpreted as an integer
Updated these lines to use // to do float division
_payload_hex str(hex(len(deserialization_payload)//2)).replace(0x, ).zfill(4)
_data_hex str(hex(len(deserialization_payload)//2 5)).
String and Byte Concatenation
deserialization_payload is raw bytes and needs to be decoded into a str before we can concatenate. This is to fix this traceback.
Traceback (most recent call last):File rogue-mysql-server.py, line 102, in modulerun_mysql_server()File rogue-mysql-server.py, line 67, in run_mysql_server_data _data_length 04 0131fc _payload_length deserialization_payload
TypeError: can only concatenate str (not bytes) to str
We change
_data _data_length 04 0131fc _payload_length deserialization_payload
to
_data _data_length 04 0131fc _payload_length deserialization_payload.decode()