diff --git a/ReadMe.md b/ReadMe.md index 6aabce3..84572da 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -30,6 +30,8 @@

+

+ # Java基础 ## 基础知识 @@ -394,6 +396,25 @@ todo # 消息队列 ## Kafka +* [消息队列kafka详解:Kafka快速上手(Java版)](docs/mq/kafka/消息队列kafka详解:Kafka快速上手(Java版).md) +* [消息队列kafka详解:Kafka一条消息存到broker的过程](docs/mq/kafka/消息队列kafka详解:Kafka一条消息存到broker的过程.md) +* [消息队列kafka详解:消息队列kafka详解:Kafka介绍](docs/mq/kafka/消息队列kafka详解:Kafka介绍.md) +* [消息队列kafka详解:Kafka原理分析总结篇](docs/mq/kafka/消息队列kafka详解:Kafka原理分析总结篇.md) +* [消息队列kafka详解:Kafka常见命令及配置总结](docs/mq/kafka/消息队列kafka详解:Kafka常见命令及配置总结.md) +* [消息队列kafka详解:Kafka架构介绍](docs/mq/kafka/消息队列kafka详解:Kafka架构介绍.md) +* [消息队列kafka详解:Kafka的集群工作原理](docs/mq/kafka/消息队列kafka详解:Kafka的集群工作原理.md) +* [消息队列kafka详解:Kafka重要知识点+面试题大全](docs/mq/kafka/消息队列kafka详解:Kafka重要知识点+面试题大全.md) +* [消息队列kafka详解:如何实现延迟队列](docs/mq/kafka/消息队列kafka详解:如何实现延迟队列.md) +* [消息队列kafka详解:如何实现死信队列](docs/mq/kafka/消息队列kafka详解:如何实现死信队列.md) + +## RocketMQ +* [RocketMQ系列:事务消息(最终一致性)](docs/mq/RocketMQ/RocketMQ系列:事务消息(最终一致性).md) +* [RocketMQ系列:基本概念](docs/mq/RocketMQ/RocketMQ系列:基本概念.md) +* [RocketMQ系列:广播与延迟消息](docs/mq/RocketMQ/RocketMQ系列:广播与延迟消息.md) +* [RocketMQ系列:批量发送与过滤](docs/mq/RocketMQ/RocketMQ系列:批量发送与过滤.md) +* [RocketMQ系列:消息的生产与消费](docs/mq/RocketMQ/RocketMQ系列:消息的生产与消费.md) +* [RocketMQ系列:环境搭建](docs/mq/RocketMQ/RocketMQ系列:环境搭建.md) +* [RocketMQ系列:顺序消费](docs/mq/RocketMQ/RocketMQ系列:顺序消费.md) # 大后端 * [后端技术杂谈开篇:云计算,大数据与AI的故事](docs/backend/后端技术杂谈开篇:云计算,大数据与AI的故事.md) diff --git a/docs/monitor/Spring Actuator.md b/docs/monitor/Spring Actuator.md new file mode 100644 index 0000000..a1ee5ef --- /dev/null +++ b/docs/monitor/Spring Actuator.md @@ -0,0 +1,578 @@ +## ǰ + +΢ϵͳܹУļDZزٵġĿǰ΢ӦǻSpring CloudϵУҲ˵ǻSpring BootϵеġʱʹSpring Boot Actuator΢ļأȫ棬ҷdz㡣 + +ƪ¡[Spring Boot Actuatorɣѵã](https://link.juejin.cn?target=https%3A%2F%2Fmp.weixin.qq.com%2Fs%2FBaNQWygQb8UXxktrXetOcw "https://mp.weixin.qq.com/s/BaNQWygQb8UXxktrXetOcw")ѾνActuatorɵSpring BootĿУҽԶEndpoint˵㣩˵룬ôƪأǽActuatorԭ˵Ĺܼʹó + +## Endpoints + +Actuatorν Endpoints Ϊ˵㣩ṩⲿӦóзʺͽĹܡ ˵/health˵ṩӦýϢmetrics ˵ṩӦóָ꣨JVM ڴʹáϵͳCPUʹõȣϢ + +ActuatorԭĶ˵ɷΪࣺ + +* ӦࣺȡӦóмصӦáԶñSpring BootӦصϢ +* ָࣺȡӦóйڼصĶָ꣬磺ڴϢ̳߳ϢHTTPͳƵȡ +* ࣺṩ˶ӦõĹرյȲ๦ܡ + +ͬ汾Actuatorṩԭ˵룬ʹõĹʹð汾ĹٷĵΪ׼ͬʱÿԭĶ˵㶼ͨĽûá + +Actuator 2.x Ĭ϶˵/actuatorǰ׺ͬʱĬֻ¶˵Ϊ/actuator/health /actuator/infoڶ˵㱩¶ãɲοǰһƪ¡Spring Boot 2.2.2.RELEASE汾ص㽲ÿ˵ĹܺӦó + +## actuator˵ + +Actuator 2.xĬ϶˵㣬չʾĿǰӦб¶Ķ˵ܣΪö˵Ŀ¼ + +URL[http://localhost:8080/actuator](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator "http://localhost:8080/actuator") Ӧչʾͼ + +![image-20230530233537559](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233537559.png) + +ֻչʾһֵĶ˵㣬ؽΪIJ-Handler˸ʽͨactuatorֱ۵ĿĿǰЩ˵㣬ԼЩ˵ƺ· + +ǾͰʾactuator˵չʾбһܡ + +## auditevents˵ + +auditevents˵ʾӦñ¶¼ (֤롢ʧ)ʹǴж˵㣬ĬҲǿ˵ġΪʹǰҪSpringдһΪAuditEventRepositoryBeanġ + +鿴ϴ̳̣϶ǽauditevents˵㹦ܣδչʾʵ߾෽ԣڸдһ + +漰Ȩ֤Ҫspring-boot-starter-security + +```` + + org.springframework.boot + spring-boot-starter-security +` +```` + +DzģҪsecurityãȻAuthorizationAuditListener,AuthenticationAuditListener ʲô¼? ,Ǽ´룺 + + +```` +@Configuration +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + + auth.inMemoryAuthentication() + .withUser("admin") + .password(bcryptPasswordEncoder().encode("admin")) + .roles("admin"); + } +```` + +```` + @Bean + public PasswordEncoder bcryptPasswordEncoder() { + return new BCryptPasswordEncoder(); + } +} +```` + +securityĬϵĵ¼Ȩ޿ƣҲ˵еķʶҪе¼¼ûΪadmin + +⣬ǰᵽҪõAuditEventRepositoryBeanʼһӦBean + + + + +```` +@Configuration +public class AuditEventConfig { + + @Bean + public InMemoryAuditEventRepository repository(){ + return new InMemoryAuditEventRepository(); + } +} +```` + +InMemoryAuditEventRepositoryAuditEventRepositoryӿڵΨһʵࡣ + +Ŀauditevents˵ˡ[http://localhost:8080/actuator](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator "http://localhost:8080/actuator") ,ʱתSecurityṩĵ¼ҳ棺 + +![image-20230530233604253](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233604253.png) + +ָû룬¼ɹת/actuatorҳ棺 + +![image-20230530233625068](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233625068.png) + +Կauditevents˵Ѿɹʾˡ¿ҳ[http://localhost:8080/actuator/auditevents](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fauditevents "http://localhost:8080/actuator/auditevents") չʾ£ + +![image-20230530233716752](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233716752.png) + +ԿѾ¼Ȩص¼еһ¼ֱӷactuator˵ʱ֮ǰΪȨ棬¼Ϊ"AUTHORIZATION_FAILURE"Ҳ֤ʧܡʱת¼ҳ棬Ȼڵ¼ҳû룬¼ɹӦ¼Ϊ"AUTHENTICATION_SUCCESS" + +Ҳ˵auditevents¼û֤¼ϵͳص¼Ϣʱ֤û¼͡ʵַsessionIdȡ + +ʾԴַ[github.com/secbr/sprin](https://link.juejin.cn?target=https%3A%2F%2Fgithub.com%2Fsecbr%2Fspringboot-all%2Ftree%2Fmaster%2Fspringboot-actuator-auditevents "https://github.com/secbr/springboot-all/tree/master/springboot-actuator-auditevents") + +## beans˵ + +/beans˵᷵Springbeanı͡ǷϢ + +·Ϊ[http://localhost:8080/actuator/beans](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fbeans "http://localhost:8080/actuator/beans") Χ£ + +![image-20230530233748286](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233748286.png) + +˵չʾĿǰSpringгʼBeanһ£һBeanȷǷɹʵDzǾͿͨ˿ڲѯһأ + +ĿжһTestControllerעһUserService + + +```` +@Controller +public class TestController { + + @Resource + private UserService userService; +} +```` + +ʸö˵㣬ῴϢ + +![image-20230530233805161](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233805161.png) + +ԿTestControllerʵˣUserService + +## caches˵ + +caches˵Ҫڱ¶ӦóеĻ塣Spring BootṩCacheչʾһʵ + +Ŀмspring-boot-starter-cache + + +```` + + org.springframework.boot + spring-boot-starter-cache + +```` + +Ȼ@EnableCaching湦ܡ + +һCacheController䷽queryAllʹûƣ + + +```` +@RestController +public class CacheController { + + @RequestMapping("/queryAll") + @Cacheable(value = "queryAll") + public Map queryAll() { + Map map = new HashMap<>(); + map.put("1", "Tom"); + map.put("2", "Steven"); + return map; + } +} +```` + +ʹ@Cacheableעʵֻ湦ܣkeyΪqueryAllʱ[http://localhost:8080/actuator/caches](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fcaches "http://localhost:8080/actuator/caches") չʾĸݣ沢ûл档 + +һ[http://localhost:8080/queryAll](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2FqueryAll "http://localhost:8080/queryAll") ҲǴһ»ݵɡʱٷӣԿӦóеĻϢˣ + +![image-20230530233852486](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233852486.png) + +ԿصݲչʾӦóĻͬʱҲչʾ˻Keyͻݴ洢Ϣ + +## caches-cache˵ + +caches-cache˵Ƕcaches˵չcaches˵չʾеĻϢֱӿһϢʹcaches-cache˵㡣 + +ʵURLΪ[http://localhost:8080/actuator/caches/{cache}](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fcaches%2F%257Bcache%257D "http://localhost:8080/actuator/caches/%7Bcache%7D") дڵֵ滻Ϊkey + + + + +`http://localhost:8080/actuator/caches/queryAll` + +ռλqueryAllkeyִн£ + +![image-20230530233906164](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233906164.png) + +ԿֻѯָĻϢƣkeyĴ洢͡ + +## health˵ + +health˵Ӧõ״̬Ƶʹõһ˵㡣Ӧʵ״̬ԼӦòԭ򣬱ݿӡ̿ռ䲻ȡ + +ʵַ[http://localhost:8080/actuator/health](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fhealth "http://localhost:8080/actuator/health") + +չʾ + +`{ +"status": "UP" +}` + +ʵڼ򵥣Ŀаݿɽȥ + +` + +```` + + org.springframework.boot + spring-boot-starter-jdbc + + + mysql + mysql-connector-java +` +```` + +Ȼapplicationļнã + + + +``` +spring: + datasource: + url: jdbc:mysql://xxx:3333/xxx?characterEncoding=utf8&serverTimezone=Asia/Shanghai + username: root + password: root + driver-class-name: com.mysql.cj.jdbc.Driver +``` + +ͬʱҪapplicationļһmanagement.endpoint.health.show-detailsֵѡ + +* never չʾϸϢup down ״̬Ĭã +* when-authorizedϸϢչʾ֤ͨûȨĽɫͨmanagement.endpoint.health.roles ã +* alwaysû¶ϸϢ + +ĬֵneverֱӷʿֻUPDOWNڼݿ⣬ͬʱѸֵΪalwaysһ飺 + +![image-20230530233934501](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233934501.png) + +Կ״̬ΪUPΪUPݿMYSQLݿΪSELECT 1ͬʱչʾ˴Ϣping״̬ + +ǰݿûĴʿɵã + +![image-20230530233951145](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233951145.png) + +״̬ΪDOWNdb⣬״̬ΪDOWNerrorչʾԿǽʱˡʵУǿͨhealth˿ڼݿ⡢RedisMongoDB̵ȽActuatorԤĴΪDataSourceHealthIndicator, DiskSpaceHealthIndicator, MongoHealthIndicator, RedisHealthIndicatorȡ + +ÿָ궼ԵĽп͹رգݿΪ + + +```` +management: + health: + db: + enabled: true` +```` + +## info˵ + +/info ˵鿴ļ applicationinfoͷϢĬ applicationвû info ڵãĬΪա + +applicationã + + + +```` +info: + user: + type: ں + name: ӽ + wechat: zhuan2quan +```` + +[http://localhost:8080/actuator/info](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Finfo "http://localhost:8080/actuator/info") չʾ£ + +![image-20230530234019487](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234019487.png) + +## conditions˵ + +Spring BootṩԶùܣʹdz㡣ЩԶʲôЧģǷЧDZȽŲġʱʹ conditions Ӧʱ鿴ijʲôЧΪʲôûЧ + +URL[http://localhost:8080/actuator/conditions](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fconditions "http://localhost:8080/actuator/conditions") ַϢ£ + +![image-20230530234053134](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234053134.png) + +ԿijԶӦЧʾϢ + +## shutdown˵ + +shutdown˵ڲ˵㣬Źر Spring Boot ӦáҪļп + + +```` +management: + endpoint: + shutdown: + enabled: true +```` + +ö˵ֻ֧POSTִؽ£ + + +``` +curl -X POST "http://localhost:8080/actuator/shutdown" +{ + "message": "Shutting down, bye..." +} +``` + +ִ֮󣬻ᷢӦóѾرˡڸö˵رӦóʹҪСġ + +## configprops˵ + +Spring BootĿУǾõ@ConfigurationPropertiesעעһЩԣconfigprops˵ʾЩעעࡣ + +ǰinfoãǾͿԶһInfoProperties + + +```` +@Component +@ConfigurationProperties(prefix = "info") +public class InfoProperties { + + private String type; + + private String name; + + private String wechat; + + // ʡgetter/setter +} +```` + +URL[http://localhost:8080/actuator/configprops](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fconfigprops "http://localhost:8080/actuator/configprops") Ϣ£ + +![image-20230530234110515](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234110515.png) + +ԿϵͳĬϼɵϢԿԶϢҪעǶӦҪʵ@Componentܹ + +ԶзBeanơǰ׺ProjectInfoPropertiesϢ + +## env˵ + +env˵ڻȡȫԣapplicationļеݡϵͳȡ + +URL[http://localhost:8080/actuator/envزϢ](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fenv%25EF%25BC%258C%25E8%25BF%2594%25E5%259B%259E%25E9%2583%25A8%25E5%2588%2586%25E4%25BF%25A1%25E6%2581%25AF%25EF%25BC%259A "http://localhost:8080/actuator/env%EF%BC%8C%E8%BF%94%E5%9B%9E%E9%83%A8%E5%88%86%E4%BF%A1%E6%81%AF%EF%BC%9A") + +![image-20230530234200949](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234200949.png) + +## env-toMatch˵ + +env-toMatch˵cachescaches-cacheƣһǻȡеģһǻȡָġenv-toMatch˵ǻȡָkeyĻԡ + +ʽΪ[http://localhost:8080/actuator/env/{toMatch}](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fenv%2F%257BtoMatch%257D%25E3%2580%2582 "http://localhost:8080/actuator/env/%7BtoMatch%7D%E3%80%82") ʵURL[http://localhost:8080/actuator/env/info.user.name](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fenv%2Finfo.user.name "http://localhost:8080/actuator/env/info.user.name") ؽͼ + +![image-20230530234238073](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234238073.png) + +ϢԵԴvalueֵϢ + +## loggers˵ + +/loggers ˵㱩¶˳ڲõ logger Ϣͬpackageͬ־Ϣ + +URL[http://localhost:8080/actuator/loggers](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Floggers "http://localhost:8080/actuator/loggers") ַؽ + +![image-20230530234301625](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234301625.png) + +## loggers-name˵ + +loggers-name˵Ҳlogger˵ϸ֣ͨnameijһlogger + +ʽ[http://localhost:8080/actuator/loggers/{name}](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Floggers%2F%257Bname%257D "http://localhost:8080/actuator/loggers/%7Bname%7D") ʾURL[http://localhost:8080/actuator/loggers/com.secbro2.SpringbootActuatorApplication](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Floggers%2Fcom.secbro2.SpringbootActuatorApplication "http://localhost:8080/actuator/loggers/com.secbro2.SpringbootActuatorApplication") ؽ£ + + + +`{ +"configuredLevel": null, +"effectiveLevel": "INFO" +}` + +Կ־ΪINFO + +## heapdump˵ + +heapdump˵᷵һJVM dumpͨJVMԴļعVisualVMɴ򿪴ļ鿴ڴաڴŻڶջŲ + +URL[http://localhost:8080/actuator/heapdump](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fheapdump "http://localhost:8080/actuator/heapdump") MacϵͳʻһΪheapdumpļ޺׺30M + +ִjvisualvmVisualVMεļװ롱ǵļҪѡ񡰶Dump(_.hprof,_.*)Ȼѡheapdump + +![image-20230530234346098](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234346098.png) + +ʱͨжջϢķˡķṩ˼Ϊķʽ + +## threaddump˵ + +/threaddump ˵ɵǰ̻߳Ŀաճλʱ鿴̵߳dzãҪչʾ߳߳ID̵߳״̬ǷȴԴϢ + +URL[http://localhost:8080/actuator/threaddump](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fthreaddump "http://localhost:8080/actuator/threaddump") ַؽ + +![image-20230530234405331](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234405331.png) + +ǿͨ߳̿Ų⡣ + +## metrics˵ + +/metrics ˵¶ǰӦõĸҪָ꣬磺ڴϢ߳ϢϢtomcatݿӳصȡ2.x汾ֻʾһָб + +URL[http://localhost:8080/actuator/metrics](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fmetrics "http://localhost:8080/actuator/metrics") + +```` +{ + "names": [ + "jvm.memory.max", + "jvm.threads.states", + "jvm.gc.pause", + "http.server.requests", + "process.files.max", + "jvm.gc.memory.promoted", + "system.load.average.1m", + "jvm.memory.used", + "jvm.gc.max.data.size", + "jvm.memory.committed", + "system.cpu.count", + "logback.events", + "jvm.buffer.memory.used", + "tomcat.sessions.created", + "jvm.threads.daemon", + "system.cpu.usage", + "jvm.gc.memory.allocated", + "tomcat.sessions.expired", + "jvm.threads.live", + "jvm.threads.peak", + "process.uptime", + "tomcat.sessions.rejected", + "process.cpu.usage", + "jvm.classes.loaded", + "jvm.classes.unloaded", + "tomcat.sessions.active.current", + "tomcat.sessions.alive.max", + "jvm.gc.live.data.size", + "process.files.open", + "jvm.buffer.count", + "jvm.buffer.total.capacity", + "tomcat.sessions.active.max", + "process.start.time" + ] +} +```` + +/metrics˵ṩӦ״ָ̬걨棬ܷdzʵãǶڼϵͳеĸعܣǵļݡռƵʶͬÿζͨȫȡķʽռԴֱٷҲǿǴڴ˷ĿǣSpring Boot 2.x֮/metrics˵ֻʾָб + +Ҫ鿴ijָ꣬ͨ/metrics-requiredMetricName˵ʵ֡ + +## metrics-requiredMetricName˵ + +metrics-requiredMetricName˵㣬ڷָָı棬һ/metrics˵ȲָбȻٲѯijָꡣ + +ʽ[http://localhost:8080/actuator/metrics/{requiredMetricName}](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fmetrics%2F%257BrequiredMetricName%257D%25E3%2580%2582 "http://localhost:8080/actuator/metrics/%7BrequiredMetricName%7D%E3%80%82") ʵURL[http://localhost:8080/actuator/metrics/jvm.memory.max](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fmetrics%2Fjvm.memory.max "http://localhost:8080/actuator/metrics/jvm.memory.max") ؽ£ + + +```` +{ + "name": "jvm.memory.max", + "description": "The maximum amount of memory in bytes that can be used for memory management", + "baseUnit": "bytes", + "measurements": [ + { + "statistic": "VALUE", + "value": 5606211583 + } + ], + "availableTags": [ + { + "tag": "area", + "values": [ + "heap", + "nonheap" + ] + }, + { + "tag": "id", + "values": [ + "Compressed Class Space", + "PS Survivor Space", + "PS Old Gen", + "Metaspace", + "PS Eden Space", + "Code Cache" + ] + } + ] +} +```` + +չʾڴָչʾ滻Ӧֽв鿴ɡ + +## scheduledtasks˵ + +/scheduledtasks˵չʾӦеĶʱϢ + +Ŀйʱ@EnableSchedulingʱܡȻ󴴽ʱࣺ + +```` +@Component +public class MyTask { + + @Scheduled(cron = "0/10 * * * * *") + public void work() { + System.out.println("I am a cron job."); + } + + @Scheduled(fixedDelay = 10000) + public void work1() { + System.out.println("I am a fixedDelay job."); + } +} +```` + +ж͵ĶʱworkǻcronʵֵĶʱwork1ǻfixedDelayʵֵĶʱ + +URL[http://localhost:8080/actuator/scheduledtasks](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fscheduledtasks "http://localhost:8080/actuator/scheduledtasks") ؽϢ£ + +``` +{ + "cron": [ + { + "runnable": { + "target": "com.secbro2.job.MyTask.work" + }, + "expression": "0/10 * * * * *" + } + ], + "fixedDelay": [ + { + "runnable": { + "target": "com.secbro2.job.MyTask.work1" + }, + "initialDelay": 0, + "interval": 10000 + } + ], + "fixedRate": [], + "custom": [] +} +``` + +Կͨö˵ȷ֪ǰӦжĶʱԼִģʽƵΡ + +## mappings˵ + +/mappings˵ȫ URI ·ԼͿӳϵDZȽϳõˣϵͳIJ鿴URLӦControllerʹô˶˵㡣 + +URL[http://localhost:8080/actuator/mappings](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fmappings "http://localhost:8080/actuator/mappings") ַؽ£ + +![image-20230530234501440](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234501440.png) + +˹Spring Boot Actuatorṩж˵ϡ + +## С + +ͨSpring Boot Actuatorṩж˵㹹ʵʾĴݺʵȫһϡÿܶŲ⣬ŻȶмİдĵĹҲԽԽ̾ActuatorĹ֮ǿǿƼ + +## ο + +ߣӽ +ӣhttps://juejin.cn/post/6984550846876876814 +Դϡ +ȨСҵתϵ߻Ȩҵתע + diff --git a/docs/monitor/SpringBoot Admin.md b/docs/monitor/SpringBoot Admin.md new file mode 100644 index 0000000..7b0c8ab --- /dev/null +++ b/docs/monitor/SpringBoot Admin.md @@ -0,0 +1,495 @@ +## ժҪ + +Spring Boot Admin ԶSpringBootӦõĸָмأΪ΢ܹеļʹãĽ÷ϸܡ + +## Spring Boot Admin + +SpringBootӦÿͨActuator¶Ӧйеĸָ꣬Spring Boot AdminͨЩָSpringBootӦãȻͨͼλֳSpring Boot AdminԼصӦãԺSpring Cloudע΢Ӧá + +Spring Boot Admin ṩӦõ¼Ϣ + +* ӦйеĸϢ +* ָϢJVMTomcatϢ +* ϢϵͳԡϵͳԼӦϢ +* 鿴дBeanϢ +* 鿴ӦеϢ +* 鿴Ӧ־Ϣ +* 鿴JVMϢ +* 鿴ԷʵWeb˵㣻 +* 鿴HTTPϢ + +## admin-serverģ + +> Ǵһadmin-serverģΪʾ书ܡ + +* pom.xml + + + + + +```` + + org.springframework.boot + spring-boot-starter-web + + + de.codecentric + spring-boot-admin-starter-server + + +```` + +* application.ymlнã + + + + + +````spring: + application: + name: admin-server +server: + port: 9301 +```` + +* @EnableAdminServeradmin-serverܣ + + + + +```` +@EnableAdminServer +@SpringBootApplication +public class AdminServerApplication { + + public static void main(String[] args) { + SpringApplication.run(AdminServerApplication.class, args); + } + +} +```` + +## admin-clientģ + +> Ǵһadmin-clientģΪͻעᵽadmin-server + +* pom.xml + + + +```` + + org.springframework.boot + spring-boot-starter-web + + + de.codecentric + spring-boot-admin-starter-client + +```` + +* application.ymlнã + + + + + + + + +``` +spring: + application: + name: admin-client + boot: + admin: + client: + url: http://localhost:9301 #admin-serverַ +server: + port: 9305 +management: + endpoints: + web: + exposure: + include: '*' + endpoint: + health: + show-details: always +logging: + file: admin-client.log #ӿadmin־ +``` + +* admin-serveradmin-client + +## Ϣʾ + +* µַSpring Boot Adminҳ[http://localhost:9301](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A9301 "http://localhost:9301") + +![image-20230531001002163](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001002163.png) + + + + + +* wallboardťѡadmin-client鿴Ϣ + +* Ϣ + +![image-20230531001023644](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001023644.png) + + + + + +* ָϢJVMTomcatϢ + +![image-20230531001053279](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001053279.png) + + + + + +* ϢϵͳԡϵͳԼӦϢ + +![image-20230531001103093](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001103093.png) + + + + + +* 鿴дBeanϢ + +![image-20230531001111221](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001111221.png) + + + + + +* 鿴ӦеϢ + +![image-20230531001124678](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001124678.png) + + + + + +* 鿴־ϢҪòܿ + + + +`logging: +file: admin-client.log #ӿadmin־` + +![image-20230531001136184](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001136184.png) + + + + +* 鿴JVMϢ + +![image-20230531001144614](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001144614.png) + + + + + +* 鿴ԷʵWeb˵㣻 + +![image-20230531001156191](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001156191.png) + + + + + +* 鿴HTTPϢ + +![image-20230531001206364](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001206364.png) + + + + + +## עʹ + +> Spring Boot AdminSpring Cloud עʹãֻ轫admin-serverעϼɣadmin-server ԶעĻȡбȻ󰤸ȡϢEurekaעΪ¸ùܡ + +### ޸admin-server + +* pom.xml + + + + +```` + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + +```` + +* application-eureka.ymlнãֻעüɣ + + + + +```` +spring: + application: + name: admin-server +server: + port: 9301 +eureka: + client: + register-with-eureka: true + fetch-registry: true + service-url: + defaultZone: http://localhost:8001/eureka/ +```` + +* @EnableDiscoveryClient÷עṦܣ + + + + + +```` +`@EnableDiscoveryClient +@EnableAdminServer +@SpringBootApplication +public class AdminServerApplication { + + public static void main(String[] args) { + SpringApplication.run(AdminServerApplication.class, args); + } + +} +```` + +### ޸admin-client + +* pom.xml + + + +```` + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + +```` + +* application-eureka.ymlнãɾԭadmin-serverַãעüɣ + + + + + +``` +spring: + application: + name: admin-client +server: + port: 9305 +management: + endpoints: + web: + exposure: + include: '*' + endpoint: + health: + show-details: always +logging: + file: admin-client.log #ӿadmin־ +eureka: + client: + register-with-eureka: true + fetch-registry: true + service-url: + defaultZone: http://localhost:8001/eureka/ +``` + +* @EnableDiscoveryClient÷עṦܣ + + + + + +``` +@EnableDiscoveryClient +@SpringBootApplication +public class AdminClientApplication { + + public static void main(String[] args) { + SpringApplication.run(AdminClientApplication.class, args); + } + +} +``` + +### ʾ + +* eureka-serverʹapplication-eureka.ymladmin-serveradmin-client + +* 鿴עķַע᣺[http://localhost:8001/](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8001%2F "http://localhost:8001/") + +![image-20230531001221519](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001221519.png) + + +* 鿴Spring Boot Admin ҳֿԿϢ[http://localhost:9301](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A9301 "http://localhost:9301") + +![image-20230531001232048](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001232048.png) + + +## ӵ¼֤ + +> ǿͨadmin-serverSpring Security֧õ¼֤ܡ + +### admin-security-serverģ + +* pom.xml + + + +``` + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + de.codecentric + spring-boot-admin-starter-server + 2.1.5 + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + +``` + +* application.ymlнãõ¼û룬admin-security-serverļϢ + + + + + +``` +spring: + application: + name: admin-security-server + security: # õ¼û + user: + name: macro + password: 123456 + boot: # ʾadmin-security-serverļϢ + admin: + discovery: + ignored-services: ${spring.application.name} +server: + port: 9301 +eureka: + client: + register-with-eureka: true + fetch-registry: true + service-url: + defaultZone: http://localhost:8001/eureka/ +``` + +* SpringSecurityãԱadmin-clientע᣺ + + + + + +scss + +ƴ + + + + + +``` +/** + * Created by macro on 2019/9/30. + */ +@Configuration +public class SecuritySecureConfig extends WebSecurityConfigurerAdapter { + private final String adminContextPath; + + public SecuritySecureConfig(AdminServerProperties adminServerProperties) { + this.adminContextPath = adminServerProperties.getContextPath(); + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); + successHandler.setTargetUrlParameter("redirectTo"); + successHandler.setDefaultTargetUrl(adminContextPath + "/"); + + http.authorizeRequests() + //1.о̬Դ͵¼ҳԹ + .antMatchers(adminContextPath + "/assets/**").permitAll() + .antMatchers(adminContextPath + "/login").permitAll() + .anyRequest().authenticated() + .and() + //2.õ¼͵dz· + .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and() + .logout().logoutUrl(adminContextPath + "/logout").and() + //3.http basic֧֣admin-clientעʱҪʹ + .httpBasic().and() + .csrf() + //4.cookiecsrf + .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) + //5.Щ·csrfԱadmin-clientע + .ignoringAntMatchers( + adminContextPath + "/instances", + adminContextPath + "/actuator/**" + ); + } +} +``` + +* ޸࣬AdminServerעֹᷢܣ + + + + + +``` +@EnableDiscoveryClient +@EnableAdminServer +@SpringBootApplication +public class AdminSecurityServerApplication { + + public static void main(String[] args) { + SpringApplication.run(AdminSecurityServerApplication.class, args); + } +} +``` + +* eureka-serveradmin-security-serverSpring Boot Admin ҳҪ¼ܷʣ[http://localhost:9301](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A9301 "http://localhost:9301") + +![image-20230531001242361](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001242361.png) + + + + + +## ʹõģ + + + + + +``` +springcloud-learning + eureka-server -- eurekaע + admin-server -- adminķ + admin-client -- adminļصӦ÷ + admin-security-server -- ¼֤adminķ` +``` \ No newline at end of file diff --git "a/docs/mq/RocketMQ/RocketMQ\347\263\273\345\210\227\357\274\232\346\266\210\346\201\257\347\232\204\347\224\237\344\272\247\344\270\216\346\266\210\350\264\271 .md" "b/docs/mq/RocketMQ/RocketMQ\347\263\273\345\210\227\357\274\232\346\266\210\346\201\257\347\232\204\347\224\237\344\272\247\344\270\216\346\266\210\350\264\271.md" similarity index 100% rename from "docs/mq/RocketMQ/RocketMQ\347\263\273\345\210\227\357\274\232\346\266\210\346\201\257\347\232\204\347\224\237\344\272\247\344\270\216\346\266\210\350\264\271 .md" rename to "docs/mq/RocketMQ/RocketMQ\347\263\273\345\210\227\357\274\232\346\266\210\346\201\257\347\232\204\347\224\237\344\272\247\344\270\216\346\266\210\350\264\271.md" diff --git "a/docs/mq/RocketMQ/RocketMQ\347\263\273\345\210\227\357\274\232\351\241\272\345\272\217\346\266\210\350\264\271 .md" "b/docs/mq/RocketMQ/RocketMQ\347\263\273\345\210\227\357\274\232\351\241\272\345\272\217\346\266\210\350\264\271.md" similarity index 100% rename from "docs/mq/RocketMQ/RocketMQ\347\263\273\345\210\227\357\274\232\351\241\272\345\272\217\346\266\210\350\264\271 .md" rename to "docs/mq/RocketMQ/RocketMQ\347\263\273\345\210\227\357\274\232\351\241\272\345\272\217\346\266\210\350\264\271.md"