博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringBoot 2.x | Spring Boot Admin 微服务监控
阅读量:4104 次
发布时间:2019-05-25

本文共 4724 字,大约阅读时间需要 15 分钟。

一、简介

SpringBootAdmin 是一个开源项目,用来监控 SpringBoot 应用,SpringBootAdmin 客户端可以整合 SpringCloud ,通过集成 Eureka 进行微服务的监控。本教程基于最新版本 2.2.0, 提供了汉化等功能。

在这里插入图片描述

二、示例

1、创建工程项目

父类 pom 文件,基于 Spring Cloud Hoxton.RELEASE 版本

1.8
Hoxton.RELEASE
de.codecentric
spring-boot-admin-starter-client
2.2.0
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.boot
spring-boot-starter-webflux
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
2、搭建注册中心 Eureka

在这里插入图片描述

org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
org.springframework.boot
spring-boot-starter
spring:  application:    name: eureka-serverserver:  port: 8761eureka:  client:    service-url:      defaultZone: http://localhost:8761/eureka    register-with-eureka: false    fetch-registry: falsemanagement:  endpoints:    web:      exposure:        include: "*"  endpoint:    health:      show-details: ALWAYS
@SpringBootApplication@EnableEurekaServerpublic class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args); }}
3、搭建 SpringBootAdmin 服务端
org.springframework.boot
spring-boot-starter-security
org.springframework.boot
spring-boot-starter-mail
de.codecentric
spring-boot-admin-starter-server
2.2.0
spring:  application:    name: admin-server  security:    user:      name: "admin"      password: "admin"server:  port: 8769eureka:  client:    registryFetchIntervalSeconds: 5    service-url:      defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/  instance:    leaseRenewalIntervalInSeconds: 10    health-check-url-path: /actuator/health    metadata-map:      user.name: ${spring.security.user.name}      user.password: ${spring.security.user.password}management:  endpoints:    web:      exposure:        include: "*"  endpoint:    health:      show-details: ALWAYS

集成 Spring Security 提供登录权限

@Configurationpublic class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
private final String adminContextPath; public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
this.adminContextPath = adminServerProperties.getContextPath(); } @Override protected void configure(HttpSecurity http) throws Exception {
// @formatter:off SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); successHandler.setTargetUrlParameter( "redirectTo" ); http.authorizeRequests() .antMatchers( adminContextPath + "/assets/**" ).permitAll() .antMatchers( adminContextPath + "/login" ).permitAll() .anyRequest().authenticated() .and() .formLogin().loginPage( adminContextPath + "/login" ).successHandler( successHandler ).and() .logout().logoutUrl( adminContextPath + "/logout" ).and() .httpBasic().and() .csrf().disable(); // @formatter:on }}
@SpringBootApplication@EnableAdminServer@EnableEurekaClientpublic class AdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class, args); }}
4、搭建 SpringBootAdmin 客户端
spring:  application:    name: admin-client4server:  port: 8764eureka:  client:    registryFetchIntervalSeconds: 5    service-url:      defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/  instance:    leaseRenewalIntervalInSeconds: 10    health-check-url-path: /actuator/healthmanagement:  endpoints:    web:      exposure:        include: "*"  endpoint:    health:      show-details: ALWAYS
@SpringBootApplication@EnableEurekaClientpublic class AdminClientApplication {
public static void main(String[] args) {
SpringApplication.run(AdminClientApplication.class, args); }}

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
—— 完

ABOUT

公众号:【星尘Pro】

github:

推荐阅读

参考资料

https://blog.csdn.net/forezp/article/details/86105850

https://codecentric.github.io/spring-boot-admin/2.2.0/
https://github.com/codecentric/spring-boot-admin

你可能感兴趣的文章
B 站爆红的数学视频,竟是用这个 Python 开源项目做的!
查看>>
安利 10 个让你爽到爆的 IDEA 必备插件!
查看>>
自学编程的八大误区!克服它!
查看>>
GitHub 上的一个开源项目,可快速生成一款属于自己的手写字体!
查看>>
早知道这些免费 API,我就可以不用到处爬数据了!
查看>>
Java各种集合类的合并(数组、List、Set、Map)
查看>>
JS中各种数组遍历方式的性能对比
查看>>
Mysql复制表以及复制数据库
查看>>
进程管理(一)
查看>>
linux 内核—进程的地址空间(1)
查看>>
存储器管理(二)
查看>>
开局一张图,学一学项目管理神器Maven!
查看>>
Android中的Binder(二)
查看>>
Framework之View的工作原理(一)
查看>>
Web应用架构
查看>>
设计模式之策略模式
查看>>
深究Java中的RMI底层原理
查看>>
用idea创建一个maven web项目
查看>>
Kafka
查看>>
9.1 为我们的角色划分权限
查看>>