成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Spring Boot Admin 2.1.0 全攻略

TalkingData / 2871人閱讀

摘要:并向注冊中心注冊,注冊地址為,最后將的所有端口暴露出來,配置如下在工程的啟動(dòng)類加上注解,開啟的功能,加上注解開啟的功能。在啟動(dòng)類加上注解,開啟的功能。

轉(zhuǎn)載請標(biāo)明出處: 
https://www.fangzhipeng.com
本文出自方志朋的博客
Spring Boot Admin簡介

Spring Boot Admin是一個(gè)開源社區(qū)項(xiàng)目,用于管理和監(jiān)控SpringBoot應(yīng)用程序。 應(yīng)用程序作為Spring Boot Admin Client向?yàn)镾pring Boot Admin Server注冊(通過HTTP)或使用SpringCloud注冊中心(例如Eureka,Consul)發(fā)現(xiàn)。 UI是的AngularJs應(yīng)用程序,展示Spring Boot Admin Client的Actuator端點(diǎn)上的一些監(jiān)控。常見的功能或者監(jiān)控如下:

顯示健康狀況

顯示詳細(xì)信息,例如

JVM和內(nèi)存指標(biāo)

micrometer.io指標(biāo)

數(shù)據(jù)源指標(biāo)

緩存指標(biāo)

顯示構(gòu)建信息編號(hào)

關(guān)注并下載日志文件

查看jvm系統(tǒng)和環(huán)境屬性

查看Spring Boot配置屬性

支持Spring Cloud的postable / env-和/ refresh-endpoint

輕松的日志級(jí)管理

與JMX-beans交互

查看線程轉(zhuǎn)儲(chǔ)

查看http跟蹤

查看auditevents

查看http-endpoints

查看計(jì)劃任務(wù)

查看和刪除活動(dòng)會(huì)話(使用spring-session)

查看Flyway / Liquibase數(shù)據(jù)庫遷移

下載heapdump

狀態(tài)變更通知(通過電子郵件,Slack,Hipchat,......)

狀態(tài)更改的事件日志(非持久性)

快速開始 創(chuàng)建Spring Boot Admin Server

本文的所有工程的Spring Boot版本為2.1.0 、Spring Cloud版本為Finchley.SR2。案例采用Maven多module形式,父pom文件引入以下的依賴(完整的依賴見源碼):

    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.0.RELEASE
        
    
    
    
     
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    


    Finchley.SR2

在工程admin-server引入admin-server的起來依賴和web的起步依賴,代碼如下:


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


    org.springframework.boot
    spring-boot-starter-web

然后在工程的啟動(dòng)類AdminServerApplication加上@EnableAdminServer注解,開啟AdminServer的功能,代碼如下:

@SpringBootApplication
@EnableAdminServer
public class AdminServerApplication {

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

}

在工程的配置文件application.yml中配置程序名和程序的端口,代碼如下:

spring:
  application:
    name: admin-server
server:
  port: 8769

這樣Admin Server就創(chuàng)建好了。

創(chuàng)建Spring Boot Admin Client

在admin-client工程的pom文件引入admin-client的起步依賴和web的起步依賴,代碼如下:

        
            de.codecentric
            spring-boot-admin-starter-client
            2.1.0
        
       
        
            org.springframework.boot
            spring-boot-starter-web
        

在工程的配置文件application.yml中配置應(yīng)用名和端口信息,以及向admin-server注冊的地址為http://localhost:8769,最后暴露自己的actuator的所有端口信息,具體配置如下:

spring:
  application:
    name: admin-client
  boot:
    admin:
      client:
        url: http://localhost:8769
server:
  port: 8768

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS

在工程的啟動(dòng)文件如下:

@SpringBootApplication
public class AdminClientApplication {

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

一次啟動(dòng)兩個(gè)工程,在瀏覽器上輸入localhost:8769 ,瀏覽器顯示的界面如下:

查看wallboard:

點(diǎn)擊wallboard,可以查看admin-client具體的信息,比如內(nèi)存狀態(tài)信息:

也可以查看spring bean的情況:

更多監(jiān)控信息,自己體驗(yàn)。

Spring boot Admin結(jié)合SC注冊中心使用

同上一個(gè)案例一樣,本案例也是使用的是Spring Boot版本為2.1.0 、Spring Cloud版本為Finchley.SR2。案例采用Maven多module形式,父pom文件引入以下的依賴(完整的依賴見源碼),此處省略。

搭建注冊中心

注冊中心使用Eureka、使用Consul也是可以的,在eureka-server工程中的pom文件中引入:

 
    org.springframework.cloud
    spring-cloud-starter-netflix-eureka-server

配置eureka-server的端口信息,以及defaultZone和防止自注冊。最后系統(tǒng)暴露eureka-server的actuator的所有端口。

spring:
  application:
    name: eureka-server
server:
  port: 8761
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka
    register-with-eureka: false
    fetch-registry: false
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS

在工程的啟動(dòng)文件EurekaServerApplication加上@EnableEurekaServer注解開啟Eureka Server.

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

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

eureka-server搭建完畢。

搭建admin-server

在admin-server工程的pom文件引入admin-server的起步依賴、web的起步依賴、eureka-client的起步依賴,如下:


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



    org.springframework.boot
    spring-boot-starter-web

        

    org.springframework.cloud
    spring-cloud-starter-netflix-eureka-client

然后配置admin-server,應(yīng)用名、端口信息。并向注冊中心注冊,注冊地址為http://localhost:8761,最后將actuator的所有端口暴露出來,配置如下:

spring:
  application:
    name: admin-server
server:
  port: 8769
eureka:
  client:
    registryFetchIntervalSeconds: 5
    service-url:
      defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/
  instance:
    leaseRenewalIntervalInSeconds: 10
    health-check-url-path: /actuator/health

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS

在工程的啟動(dòng)類AdminServerApplication加上@EnableAdminServer注解,開啟admin server的功能,加上@EnableDiscoveryClient注解開啟eurke client的功能。

@SpringBootApplication
@EnableAdminServer
@EnableDiscoveryClient
public class AdminServerApplication {

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

}
搭建admin-client

在admin-client的pom文件引入以下的依賴,由于2.1.0采用webflux,引入webflux的起步依賴,引入eureka-client的起步依賴,并引用actuator的起步依賴如下:

 
            org.springframework.boot
            spring-boot-starter-webflux
        

        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        

        
            org.springframework.boot
            spring-boot-starter-actuator
        

在工程的配置文件配置應(yīng)用名、端口、向注冊中心注冊的地址,以及暴露actuator的所有端口。

spring:
  application:
    name: admin-client
eureka:
  instance:
    leaseRenewalIntervalInSeconds: 10
    health-check-url-path: /actuator/health

  client:
    registryFetchIntervalSeconds: 5
    service-url:
      defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS
server:
  port: 8762

在啟動(dòng)類加上@EnableDiscoveryClie注解,開啟DiscoveryClient的功能。

@SpringBootApplication
@EnableDiscoveryClient
public class AdminClientApplication {

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

一次啟動(dòng)三個(gè)工程,在瀏覽器上訪問localhost:8769,瀏覽器會(huì)顯示和上一小節(jié)一樣的界面。

集成spring security

在2.1.0版本中去掉了hystrix dashboard,登錄界面默認(rèn)集成到了spring security模塊,只要加上spring security就集成了登錄模塊。

只需要改變下admin-server工程,需要在admin-server工程的pom文件引入以下的依賴:


    org.springframework.boot
    spring-boot-starter-security

在admin-server工的配置文件application.yml中配置spring security的用戶名和密碼,這時(shí)需要在服務(wù)注冊時(shí)帶上metadata-map的信息,如下:

spring:
  security:
    user:
      name: "admin"
      password: "admin"
      
eureka:
  instance:
    metadata-map:
      user.name: ${spring.security.user.name}
      user.password: ${spring.security.user.password}

寫一個(gè)配置類SecuritySecureConfig繼承WebSecurityConfigurerAdapter,配置如下:

@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 {
        // @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
    }
}

重啟啟動(dòng)工程,在瀏覽器上訪問:http://localhost:8769/,會(huì)被重定向到登錄界面,登錄的用戶名和密碼為配置文件中配置的,分別為admin和admin,界面顯示如下:

集成郵箱報(bào)警功能

在spring boot admin中,也可以集成郵箱報(bào)警功能,比如服務(wù)不健康了、下線了,都可以給指定郵箱發(fā)送郵件。集成非常簡單,只需要改造下admin-server即可:

在admin-server工程Pom文件,加上mail的起步依賴,代碼如下:


    org.springframework.boot
    spring-boot-starter-mail

在配置文件application.yml文件中,需要配置郵件相關(guān)的配置,如下:

spring.mail.host: smtp.163.com
spring.mail.username: miles02
spring.mail.password:
spring.boot.admin.notify.mail.to: [email protected]

做完以上配置后,當(dāng)我們已注冊的客戶端的狀態(tài)從 UP 變?yōu)?OFFLINE 或其他狀態(tài),服務(wù)端就會(huì)自動(dòng)將電子郵件發(fā)送到上面配置的地址。

源碼下載

快速開始: https://github.com/forezp/Spr...

和spring cloud結(jié)合:https://github.com/forezp/Spr...

參考資料

http://codecentric.github.io/...

https://github.com/codecentri...

更多閱讀

史上最簡單的 SpringCloud 教程匯總

SpringBoot教程匯總

Java面試題系列匯總


掃一掃,支持下作者吧

(轉(zhuǎn)載本站文章請注明作者和出處 方志朋的博客

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/72870.html

相關(guān)文章

  • SpringBoot-Admin的使用

    摘要:端項(xiàng)目依賴添加是為了使應(yīng)用處于啟動(dòng)狀態(tài),會(huì)自動(dòng)添加相關(guān)依賴。接下來以作為服務(wù)發(fā)現(xiàn)的示例來進(jìn)行演示,實(shí)際上也可以使用或者。最后是一個(gè)用方式監(jiān)聽的使用連接端 【前情提要】Spring Boot Actuator 提供了對單個(gè) Spring Boot 應(yīng)用的監(jiān)控,信息包含應(yīng)用狀態(tài)、內(nèi)存、線程、堆棧等,比較全面的監(jiān)控了 Spring Boot 應(yīng)用的整個(gè)生命周期。但是這樣監(jiān)控也有一些問題:第一...

    vslam 評論0 收藏0
  • Spring Boot Admin 2.0開箱體驗(yàn)

    摘要:概述在我之前的應(yīng)用監(jiān)控實(shí)戰(zhàn)一文中,講述了如何利用版本來可視化地監(jiān)控應(yīng)用。接下來我們就來創(chuàng)建一個(gè)待監(jiān)控的示例。 showImg(https://segmentfault.com/img/remote/1460000015671446); 概述 在我之前的 《Spring Boot應(yīng)用監(jiān)控實(shí)戰(zhàn)》 一文中,講述了如何利用 Spring Boot Admin 1.5.X 版本來可視化地監(jiān)控 ...

    CastlePeaK 評論0 收藏0
  • Spring Boot Admin排坑指南

    摘要:其簡陋的頁面讓人不忍直視,但更新到系列后,像脫胎換骨一般好用這篇博客記錄我個(gè)人在使用過程中遇到過的坑,每個(gè)坑位都會(huì)附上詳細(xì)的填坑辦法環(huán)境參數(shù)服務(wù)直接注冊失敗常見的注冊失敗問題可以分為以下兩種服務(wù)端與客戶端不在同一臺(tái)服務(wù)器上提示安全校驗(yàn)不通過 Spring Boot Admin 1.x其簡陋的頁面讓人不忍直視,但更新到2.x系列后,像脫胎換骨一般好用 這篇博客記錄我個(gè)人在使用Spring...

    CocoaChina 評論0 收藏0
  • Spring Cloud Admin 實(shí)戰(zhàn)

    摘要:簡介用于監(jiān)控基于的應(yīng)用,它是在的基礎(chǔ)上提供簡潔的可視化。提供了很多功能,如顯示和,顯示在線狀態(tài),的日志級(jí)別管理,線程管理,管理等。 Spring Cloud Admin 簡介 Spring Boot Admin 用于監(jiān)控基于 Spring Boot 的應(yīng)用,它是在 Spring Boot Actuator 的基礎(chǔ)上提供簡潔的可視化 WEB UI。Spring Boot Admin 提供...

    MrZONT 評論0 收藏0
  • 第三課(spring-boot+mybatis+jqgrid)

    摘要:課程目標(biāo)完成與與的的集成處理數(shù)據(jù)課程計(jì)劃使用完成博客后臺(tái)管理員列表的搜索課程分析想要完成列表的搜索,就必須對按提交搜索條件進(jìn)行邏輯判斷組織也就是動(dòng)態(tài)步驟加入依賴使用配置使用使用注解方式動(dòng)態(tài)動(dòng) 課程目標(biāo) 完成與spring boot 與的mybatis的集成處理數(shù)據(jù)curd 課程計(jì)劃 使用mybatis完成博客后臺(tái)管理員列表的jqgird搜索 課程分析 想要完成列表的搜索,就必須對sql...

    terasum 評論0 收藏0

發(fā)表評論

0條評論

最新活動(dòng)
閱讀需要支付1元查看
<