Spring Boot Admin的使用
文章目录
- 配置Admin Server
- 配置admin client
- 配置安全主键
- Hazelcast集群
Spring Boot Admin的使用
前面的文章我们讲了Spring Boot的Actuator。但是Spring Boot Actuator只是提供了一个个的接口,需要我们自行集成到监控程序中。今天我们将会讲解一个优秀的监控工具Spring Boot Admin。 它采用图形化的界面,让我们的Spring Boot管理更加简单。
先上图给大家看一下Spring Boot Admin的界面:
从界面上面我们可以看到Spring Boot Admin提供了众多强大的监控功能。那么开始我们的学习吧。
配置Admin Server
既然是管理程序,肯定有一个server,配置server很简单,我们添加这个依赖即可:
<dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-server</artifactId><version>2.2.2</version>
</dependency>
同时我们需要在main程序中添加@EnableAdminServer来启动admin server。
@EnableAdminServer
@SpringBootApplication
public class SpringBootAdminServerApplication {public static void main(String[] args) {SpringApplication.run(SpringBootAdminServerApplication.class, args);}
}
配置admin client
有了server,我们接下来配置需要监控的client应用程序,在本文中,我们自己监控自己,添加client依赖如下:
<dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-client</artifactId><version>2.2.2</version>
</dependency>
我们需要为client指定要注册到的admin server:
spring.boot.admin.client.url=http://localhost:8080
因为Spring Boot Admin依赖于 Spring Boot Actuator, 从Spring Boot2 之后,我们需要主动开启暴露的主键,如下:
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
配置安全主键
通常来说,我们需要一个登陆界面,以防止未经授权的人访问。spring boot admin提供了一个UI供我们使用,同时我们添加Spring Security依赖:
<dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-server-ui-login</artifactId><version>1.5.7</version>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId>
</dependency>
添加了Spring Security,我们需要自定义一些配置:
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {private final AdminServerProperties adminServer;public WebSecurityConfig(AdminServerProperties adminServer) {this.adminServer = adminServer;}@Overrideprotected void configure(HttpSecurity http) throws Exception {SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();successHandler.setTargetUrlParameter("redirectTo");successHandler.setDefaultTargetUrl(this.adminServer.getContextPath() + "/");http.authorizeRequests().antMatchers(this.adminServer.getContextPath() + "/assets/**").permitAll().antMatchers(this.adminServer.getContextPath() + "/login").permitAll().anyRequest().authenticated().and().formLogin().loginPage(this.adminServer.getContextPath() + "/login").successHandler(successHandler).and().logout().logoutUrl(this.adminServer.getContextPath() + "/logout").and().httpBasic().and().csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()).ignoringRequestMatchers(new AntPathRequestMatcher(this.adminServer.getContextPath() + "/instances", HttpMethod.POST.toString()), new AntPathRequestMatcher(this.adminServer.getContextPath() + "/instances/*", HttpMethod.DELETE.toString()),new AntPathRequestMatcher(this.adminServer.getContextPath() + "/actuator/**")).and().rememberMe().key(UUID.randomUUID().toString()).tokenValiditySeconds(1209600);}
}
接下来,我们在配置文件中指定服务器的用户名和密码:
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=admin
作为一个客户端,连接服务器的时候,我们也需要提供相应的认证信息如下:
spring.boot.admin.client.instance.metadata.user.name=admin
spring.boot.admin.client.instance.metadata.user.password=adminspring.boot.admin.client.username=admin
spring.boot.admin.client.password=admin
好了,登录页面和权限认证也完成了。
Hazelcast集群
Spring Boot Admin 支持Hazelcast的集群,我们先添加依赖如下:
<dependency><groupId>com.hazelcast</groupId><artifactId>hazelcast</artifactId><version>3.12.2</version>
</dependency>
然后添加Hazelcast的配置:
@Configuration
public class HazelcastConfig {@Beanpublic Config hazelcast() {MapConfig eventStoreMap = new MapConfig("spring-boot-admin-event-store").setInMemoryFormat(InMemoryFormat.OBJECT).setBackupCount(1).setEvictionPolicy(EvictionPolicy.NONE).setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100));MapConfig sentNotificationsMap = new MapConfig("spring-boot-admin-application-store").setInMemoryFormat(InMemoryFormat.OBJECT).setBackupCount(1).setEvictionPolicy(EvictionPolicy.LRU).setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100));Config config = new Config();config.addMapConfig(eventStoreMap);config.addMapConfig(sentNotificationsMap);config.setProperty("hazelcast.jmx", "true");config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig();tcpIpConfig.setEnabled(true);tcpIpConfig.setMembers(Collections.singletonList("127.0.0.1"));return config;}
}
本文的例子可以参考https://github.com/ddean2009/learn-springboot2/tree/master/springboot-admin
更多精彩内容且看:
- 区块链从入门到放弃系列教程-涵盖密码学,超级账本,以太坊,Libra,比特币等持续更新
- Spring Boot 2.X系列教程:七天从无到有掌握Spring Boot-持续更新
- Spring 5.X系列教程:满足你对Spring5的一切想象-持续更新
- java程序员从小工到专家成神之路(2020版)-持续更新中,附详细文章教程
更多教程请参考 flydean的博客
Spring Boot Admin的使用相关推荐
- Spring Boot Admin 2.1.0 全攻略
点击上方"方志朋",选择"置顶或者星标" 你的关注意义重大! Spring Boot Admin是一个开源社区项目,用于管理和监控SpringBoot应用程序. ...
- Spring Boot Admin 2.0开箱体验
2019独角兽企业重金招聘Python工程师标准>>> 概述 在我之前的 <Spring Boot应用监控实战> 一文中,讲述了如何利用 Spring Boot Admi ...
- Spring Boot Admin 2.1.4,Spring Boot 应用的 Admin UI
开发四年只会写业务代码,分布式高并发都不会还做程序员? Spring Boot Admin 是用来管理 Spring Boot 应用程序的一个简单的界面. Spring Boot Admin 2. ...
- Spring Boot Admin 2.5.5 发布,支持在线重启服务
来源 | https://mp.weixin.qq.com/s/kKhqEbgvRGW6AiHPt0eXbA Spring Boot Admin 2.5.5 发布,这是一个错误修正版本.现在可以从 m ...
- SpringCloud(8)微服务监控Spring Boot Admin
1.简介 Spring Boot Admin 是一个管理和监控Spring Boot 应用程序的开源软件.Spring Boot Admin 分为 Server 端和 Client 端,Spring ...
- 服务器状态显示down,Eureka心跳健康检查机制和Spring boot admin 节点状态一直为DOWN的排查(忽略某一个节点的健康检查)...
运行阶段执行健康检查的目的是为了从Eureka服务器注册表中识别并删除不可访问的微服务,Eureka 服务器并不是向客户端发送心跳请求,而是反过来,Eureka 客户端将心跳发送到Eureka服务器, ...
- Spring Boot Admin 2.0 上手
Spring Boot Admin 在 Spring Boot Actuator 的基础上提供简洁的可视化 WEB UI,是用来管理 Spring Boot 应用程序的一个简单的界面,提供如下功能: ...
- Spring Boot Admin:微服务应用监控
摘要 Spring Boot Admin 可以对SpringBoot应用的各项指标进行监控,可以作为微服务架构中的监控中心来使用,本文将对其用法进行详细介绍. Spring Boot Admin 简介 ...
- Spring Boot Admin 2 值得了解的新变化
6.19号,spring团队发布了期待已久的 Spring Cloud Finchley.RELEASE 版本. 期间Spring Boot Admin 也发布了 2.0.1 兼容它,我在升级pig ...
最新文章
- python官网怎么下载-python下载官网
- poj2140---herd sums
- MSP430单片机输入与输出
- Vue中使用vue-video-player和videojs-flash插件实现播放rtmp视频文件流
- Spring Cloud——基于Dubbo的分布式Session解决方案
- ATS (apache traffic server) http_ui 设置与使用
- mysql increment by_Mysql设置auto_increment_increment和auto_increment_offset
- java 切换目录,java-使用SVNKit,如何将目录切换到其他分支?
- SpringCloud Eureka自我保护机制介绍及配置
- ksd文件怎么导入存档_DAY5-step5 Python 示例说明 ZIP 压缩文件
- element ui html编辑器,Vue + Element UI使用富文本编辑器
- 如何查找识别苹果无线鼠标/无线键盘/触控板的设备序列号
- 维基百科公式不显示怎么办 找不到latex公式怎么办?
- 最新麦子学院嵌入式开发系列培训教程
- 树莓派 3B+/4B 连接“手机热点“或“WiFi“ 后无法上网(必解)
- 写给大家看的CSS书,写给大家看的设计书
- OPENGL 半透明贴图
- 维基百科诞生,它是一个自由、免费、内容开放的网络百科全书,是世界第五大网站...
- c++游戏编程(1)开发环境与工具函数
- 一种全新的智能远程施工方案被提出——无线图传+远程控制方案
热门文章
- dede config.chche.inc.php,dede/config.php · 辉辉菜/三强源码 - Gitee.com
- 线段树HDU1698(成段更新)
- 模拟赛-20190228-随机数(random)
- Linux 进程控制 :进程创建,进程终止,进程等待,程序替换
- Mark一下 | 当当优惠码,实付满150减30 | + 荐书
- LiveVideoStackCon2021音视频技术大会北京站今日开幕!
- 视频压缩标准简史:从1929到2020
- 视频内容理解在手淘逛逛中的应用与落地
- 用AI击破传统行业痛点 “百度大脑行业创新论坛”将提7大行业解决方案
- Hadoop之HDFS概述