千家信息网

SpringBootAdmin监控工具怎么用

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,这篇文章主要为大家展示了"SpringBootAdmin监控工具怎么用",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"SpringBootAdmin监控工具
千家信息网最后更新 2026年11月01日SpringBootAdmin监控工具怎么用

这篇文章主要为大家展示了"SpringBootAdmin监控工具怎么用",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"SpringBootAdmin监控工具怎么用"这篇文章吧。

配置Admin Server

既然是管理程序,肯定有一个server,配置server很简单,我们添加这个依赖即可:

de.codecentric spring-boot-admin-starter-server 2.2.2

同时我们需要在main程序中添加@EnableAdminServer来启动admin server。

@EnableAdminServer@SpringBootApplicationpublic class SpringBootAdminServerApplication { public static void main(String[] args) { SpringApplication.run(SpringBootAdminServerApplication.class, args); }}

配置admin client

有了server,我们接下来配置需要监控的client应用程序,在本文中,我们自己监控自己,添加client依赖如下:

de.codecentric spring-boot-admin-starter-client 2.2.2

我们需要为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依赖:

de.codecentric spring-boot-admin-server-ui-login 1.5.7 org.springframework.boot spring-boot-starter-security

添加了Spring Security,我们需要自定义一些配置:

@Configurationpublic class WebSecurityConfig extends WebSecurityConfigurerAdapter { private final AdminServerProperties adminServer; public WebSecurityConfig(AdminServerProperties adminServer) { this.adminServer = adminServer; } @Override protected 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=adminspring.boot.admin.client.password=admin

作为一个客户端,连接服务器的时候,我们也需要提供相应的认证信息如下:

spring.boot.admin.client.instance.metadata.user.name=adminspring.boot.admin.client.instance.metadata.user.password=adminspring.boot.admin.client.username=adminspring.boot.admin.client.password=admin

好了,登录页面和权限认证也完成了。

Hazelcast集群

Spring Boot Admin 支持Hazelcast的集群,我们先添加依赖如下:

com.hazelcast hazelcast 3.12.2

然后添加Hazelcast的配置:

@Configurationpublic class HazelcastConfig { @Bean public 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; }}

以上是"SpringBootAdmin监控工具怎么用"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

配置 监控 工具 内容 程序 篇文章 接下来 同时 服务器 集群 学习 帮助 服务 认证 主动 安全 中指 信息 客户 客户端 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 广州紫鲸互联网科技有限公司 互联网科技工作委员会 北京路客互联网科技有限公司 圆梦互联网科技 中资互联网科技 互联网科技公司有哪些 科技互联网创业计划书 国外互联网科技网站 顺网科技2021年互联网排名 太原新华互联网科技学校怎么样 老年人脱离互联网科技的作文 成都玖崟互联网科技有限公司乐商圈怎么样 北京大学互联网科技怎么样 企晟互联网信息科技有限公司 广州富喜互联网络科技 厦门江牛科技互联网 国产互联网科技公司 互联网科技新闻 互联网对科技影响 网互联网络科技 互联网科技公司经营范围 互联网科技公司税收优惠 北京互联网科技 镁科技互联网资讯平台 宁夏众和广鑫互联网科技有限公司 河南猎农互联网科技有限公司 四川慕妮娅互联网科技有限公司 互联网科技圈年度人物 互联网时代的科技公司 皮皮虾互联网科技有限公司
0