最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Spring Boot Admin(監(jiān)控工具)的使用

 更新時(shí)間:2020年02月13日 10:48:35   作者:FLYDEAN  
今天我們將會(huì)講解一個(gè)優(yōu)秀的監(jiān)控工具Spring Boot Admin。 它采用圖形化的界面,讓我們的Spring Boot管理更加簡單,需要的朋友可以參考下

前面的文章我們講了Spring Boot的Actuator。但是Spring Boot Actuator只是提供了一個(gè)個(gè)的接口,需要我們自行集成到監(jiān)控程序中。今天我們將會(huì)講解一個(gè)優(yōu)秀的監(jiān)控工具Spring Boot Admin。 它采用圖形化的界面,讓我們的Spring Boot管理更加簡單。

先上圖給大家看一下Spring Boot Admin的界面:

 

從界面上面我們可以看到Spring Boot Admin提供了眾多強(qiáng)大的監(jiān)控功能。那么開始我們的學(xué)習(xí)吧。

配置Admin Server

既然是管理程序,肯定有一個(gè)server,配置server很簡單,我們添加這個(gè)依賴即可:

<dependency>
 <groupId>de.codecentric</groupId>
 <artifactId>spring-boot-admin-starter-server</artifactId>
 <version>2.2.2</version>
</dependency>

同時(shí)我們需要在main程序中添加@EnableAdminServer來啟動(dòng)admin server。

@EnableAdminServer
@SpringBootApplication
public class SpringBootAdminServerApplication {

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

配置admin client

有了server,我們接下來配置需要監(jiān)控的client應(yīng)用程序,在本文中,我們自己監(jiān)控自己,添加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

因?yàn)镾pring Boot Admin依賴于 Spring Boot Actuator, 從Spring Boot2 之后,我們需要主動(dòng)開啟暴露的主鍵,如下:

management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

配置安全主鍵

通常來說,我們需要一個(gè)登陸界面,以防止未經(jīng)授權(quán)的人訪問。spring boot admin提供了一個(gè)UI供我們使用,同時(shí)我們添加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;
 }
 @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);
 }
}

接下來,我們在配置文件中指定服務(wù)器的用戶名和密碼:

spring.boot.admin.client.username=admin
spring.boot.admin.client.password=admin

作為一個(gè)客戶端,連接服務(wù)器的時(shí)候,我們也需要提供相應(yīng)的認(rèn)證信息如下:

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

好了,登錄頁面和權(quán)限認(rèn)證也完成了。

Hazelcast集群

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

<dependency>
 <groupId>com.hazelcast</groupId>
 <artifactId>hazelcast</artifactId>
 <version>3.12.2</version>
</dependency>

然后添加Hazelcast的配置:

@Configuration
public 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;
 }
}

本文的例子可以參考 https://github.com/ddean2009/learn-springboot2/tree/master/springboot-admin

總結(jié)

以上所述是小編給大家介紹的Spring Boot Admin(監(jiān)控工具)的使用,希望對大家有所幫助!

相關(guān)文章

  • Mybatis中BindingException異常的產(chǎn)生原因及解決過程

    Mybatis中BindingException異常的產(chǎn)生原因及解決過程

    BindingException異常是MyBatis框架中自定義的異常,顧名思義指的是綁定出現(xiàn)問題,下面這篇文章主要給大家介紹了關(guān)于MyBatis報(bào)錯(cuò)BindingException異常的產(chǎn)生原因及解決過程,需要的朋友可以參考下
    2023-06-06
  • SpringBoot的自動(dòng)配置原理解析

    SpringBoot的自動(dòng)配置原理解析

    這篇文章主要介紹了SpringBoot的自動(dòng)配置原理解析,SpringBoot的自動(dòng)配置要從它的啟動(dòng)類@SpringBootApplication說起,點(diǎn)進(jìn)注解,@Target設(shè)置當(dāng)前注解可以標(biāo)記在哪,(ElementType.type)表示標(biāo)注在類上面,需要的朋友可以參考下
    2023-08-08
  • Java日常練習(xí)題,每天進(jìn)步一點(diǎn)點(diǎn)(50)

    Java日常練習(xí)題,每天進(jìn)步一點(diǎn)點(diǎn)(50)

    下面小編就為大家?guī)硪黄狫ava基礎(chǔ)的幾道練習(xí)題(分享)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧,希望可以幫到你
    2021-08-08
  • JPA使用樂觀鎖應(yīng)對高并發(fā)方式

    JPA使用樂觀鎖應(yīng)對高并發(fā)方式

    這篇文章主要介紹了JPA使用樂觀鎖應(yīng)對高并發(fā)方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • 2020.2 IntelliJ IDEA激活與IDEA2020.2破解詳細(xì)教程

    2020.2 IntelliJ IDEA激活與IDEA2020.2破解詳細(xì)教程

    這篇文章主要介紹了2020.2 IntelliJ IDEA激活與IDEA2020.2破解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • java 刪除數(shù)組元素與刪除重復(fù)數(shù)組元素的代碼

    java 刪除數(shù)組元素與刪除重復(fù)數(shù)組元素的代碼

    在java中刪除數(shù)組元素與過濾重復(fù)數(shù)組元素我們都會(huì)需要去遍歷數(shù)組然后根據(jù)我們設(shè)置的值或方法進(jìn)行去除數(shù)組
    2013-10-10
  • Java數(shù)據(jù)結(jié)構(gòu)中圖的進(jìn)階詳解

    Java數(shù)據(jù)結(jié)構(gòu)中圖的進(jìn)階詳解

    在Java學(xué)習(xí)與應(yīng)用中,數(shù)據(jù)結(jié)構(gòu)無疑是每個(gè)人都要接觸的難點(diǎn),為了更好的學(xué)習(xí)數(shù)據(jù)結(jié)構(gòu)這一塊內(nèi)容,用圖來理解便是最好的方式,讓我們一起來了解本篇內(nèi)容圖的進(jìn)階
    2022-01-01
  • SpringBoot中使用JeecgBoot的Autopoi導(dǎo)出Excel的方法步驟

    SpringBoot中使用JeecgBoot的Autopoi導(dǎo)出Excel的方法步驟

    這篇文章主要介紹了SpringBoot中使用JeecgBoot的Autopoi導(dǎo)出Excel的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • MyBatis?ofType和javaType的區(qū)別說明

    MyBatis?ofType和javaType的區(qū)別說明

    這篇文章主要介紹了MyBatis?ofType和javaType的區(qū)別,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • Java操作redis設(shè)置第二天凌晨過期的解決方案

    Java操作redis設(shè)置第二天凌晨過期的解決方案

    這篇文章主要介紹了Java操作redis設(shè)置第二天凌晨過期的解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-01-01

最新評(píng)論

个旧市| 龙州县| 伊川县| 龙川县| 洛阳市| 常熟市| 茂名市| 本溪市| 岳阳县| 江安县| 乌什县| 双鸭山市| 河东区| 蛟河市| 依兰县| 涟水县| 莱州市| 江津市| 三台县| 渭源县| 石林| 广平县| 佳木斯市| 清河县| 共和县| 塔城市| 大城县| 民勤县| 雷州市| 济南市| 安徽省| 河西区| 饶平县| 玉溪市| 丰顺县| 和林格尔县| 丰城市| 台东县| 胶州市| 丹寨县| 土默特右旗|