中文字幕第五页-中文字幕第页-中文字幕韩国-中文字幕最新-国产尤物二区三区在线观看-国产尤物福利视频一区二区

SpringBootAdmin排坑指南是什么

Spring Boot Admin排坑指南是什么,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

創新互聯從2013年創立,是專業互聯網技術服務公司,擁有項目成都網站設計、成都網站建設、外貿網站建設網站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元賈汪做網站,已為上家服務,為賈汪各地企業和個人服務,聯系電話:13518219792

服務直接注冊失敗

常見的注冊失敗問題可以分為以下兩種

  • Spring Boot Admin服務端與客戶端不在同一臺服務器

  • 提示安全校驗不通過

第一種問題的解決辦法:

必須在客戶端配置boot.admin.client.instance.service-url屬性,讓Spring Boot Admin服務端可以通過網絡獲取客戶端的數據(否則默認會通過主機名去獲取)

  boot:
    admin:
      client:
        url: ${your spring boot admin url}
        username: ${your spring boot admin username}
        password: ${your spring boot admin password}
        instance:
          prefer-ip: true
          service-url: ${your spring boot client url}

第二種問題的解決辦法:

首先,安全檢驗問題,其實就是現在服務端配置賬號密碼,然后客戶端在注冊的時候提供賬號密碼進行登錄來完成校驗

這個過程的實現,作為Spring全家桶項目,推薦使用Spring Security來解決,所以如果出現校驗失敗,那多半是Spring Security的配置出現問題

接下來介紹如何分別配置服務端與客戶端來處理這個問題

服務端配置

通過maven加載Spring Security依賴

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-security</artifactId>
</dependency>

設置服務端的用戶名和密碼(客戶端來注冊時使用此賬號密碼進行登錄)

spring:
  security:
    user:
      name: liumapp
      password: superliumapp

編寫Spring Security配置類

import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;

/**
 * file SecuritySecureConfig.java
 * author liumapp
 * github https://github.com/liumapp
 * email liumapp.com@gmail.com
 * homepage http://www.liumapp.com
 * date 2018/11/29
 */
@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");
        successHandler.setDefaultTargetUrl(adminContextPath + "/");

        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()
                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                .ignoringAntMatchers(
                        adminContextPath + "/instances",
                        adminContextPath + "/actuator/**"
                );
        // @formatter:on
    }
}

上面這段代碼,需要大家注意的就一個AdminServerProperties類,通過瀏覽它的部分源代碼:

@ConfigurationProperties("spring.boot.admin")
public class AdminServerProperties {
    /**
     * The context-path prefixes the path where the Admin Servers statics assets and api should be
     * served. Relative to the Dispatcher-Servlet.
     */
    private String contextPath = "";
    
    /**
     * The metadata keys which should be sanitized when serializing to json
     */
    private String[] metadataKeysToSanitize = new String[]{".*password$", ".*secret$", ".*key$", ".*$token$", ".*credentials.*", ".*vcap_services$"};

    /**
     * For Spring Boot 2.x applications the endpoints should be discovered automatically using the actuator links.
     * For Spring Boot 1.x applications SBA probes for the specified endpoints using an OPTIONS request.
     * If the path differs from the id you can specify this as id:path (e.g. health:ping).
     */
    private String[] probedEndpoints = {"health", "env", "metrics", "httptrace:trace", "httptrace", "threaddump:dump", "threaddump", "jolokia", "info", "logfile", "refresh", "flyway", "liquibase", "heapdump", "loggers", "auditevents", "mappings", "scheduledtasks", "configprops", "caches", "beans"};
    
    //以下省略...
    
}

可以發現AdminServerProperties定義了Spring Boot Admin的配置屬性,登錄自然也是其中之一,所以我們在編寫Spring Security配置類的時候,務必要引入AdminServerProperties

到這里,Spring Boot Admin服務端對于Spring Security的配置便結束了,接下來讓我們開始客戶端的Security配置

客戶端配置

首先對于客戶端,我們除了Spring Boot Admin Client依賴外,還需要額外引入 Spring Security依賴:

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>2.0.2</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

在此基礎上通過編寫客戶端application.yml配置文件來設置賬號密碼

spring:
  boot:
    admin:
      client:
        url: ${your sba server url}
        username: ${your sba username}
        password: ${your sba password}
        instance:
          service-base-url: ${your client url}

接下來對Client端的Spring Security做配置,允許Server端讀取actuator暴露的數據

添加一個配置類:

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
public class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().permitAll()
                .and().csrf().disable();
    }
}

到此,因為安全驗證而不能注冊成功的問題便可以解決

注冊成功但無法顯示日志

這個問題產生原因有兩種

  • 客戶端日志沒有以文件形式存儲下來

  • 客戶端容器化部署后,日志文件沒有映射到宿主機磁盤上

針對第一種情況,解決辦法比較簡單,將系統產生的日志以文件形式保存即可:

logging:
  file: ./log/client.log
  pattern:
    file: "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx"

第二種情況較為復雜,首先要分清除是用什么工具來部署容器的,但一般而言直接通過文件映射即可

這里以docker為例,在docker內通過設置volumes來映射日志文件

volumes:
  - ./log:/client/log/

注冊成功但信息顯示不全

偶爾也會遇到這種情況:Spring Boot Admin客戶端注冊服務端是成功的,但是統計頁面顯示的數據過少(可能只有日志這一欄)

造成這種問題的原因在于:我們沒有開放客戶端的actuator接口地址給服務端訪問

那么解決辦法也很簡單,允許服務端訪問actuator即可

首先我們需要確保項目有actuator依賴(一般來說,spring-boot-admin-starter-client本身就包含這個依賴,所以不需要額外引入):

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

然后打開actuator的端口,在client端的配置文件中增加以下內容:

management:
  endpoints:
    web:
      exposure:
        include: "*"

同時考慮到client與server域名存在不一樣的情況,順便把跨域也解決掉,增加跨域配置類:

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author liumapp
 * @file CorsConfig.java
 * @email liumapp.com@gmail.com
 * @homepage http://www.liumapp.com
 * @date 2018/8/11
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
   
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowCredentials(true)
                .allowedHeaders("*")
                .allowedOrigins("*")
                .allowedMethods("*");

    }
}

關于Spring Boot Admin排坑指南是什么問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注創新互聯行業資訊頻道了解更多相關知識。

分享題目:SpringBootAdmin排坑指南是什么
網址分享:http://m.2m8n56k.cn/article28/jdccjp.html

成都網站建設公司_創新互聯,為您提供營銷型網站建設域名注冊品牌網站建設手機網站建設網站收錄做網站

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都定制網站建設
主站蜘蛛池模板: 国产在线观看免费一级 | 国产aaa级一级毛片 国产aaa毛片 | 免费观看一级欧美在线视频 | 99久免费精品视频在线观看2 | 国产在线精品一区免费香蕉 | 欧美一级毛片高清毛片 | 国产精品无打码在线播放9久 | 男女性关系视频免费观看软件 | 一级毛片视频在线 | 免费观看视频成人国产 | 免费看亚洲 | 亚洲精品亚洲人成毛片不卡 | 国产日韩欧美一区二区三区在线 | 久久精品国产午夜伦班片 | 综合欧美日韩一区二区三区 | 亚洲综合91| 九九亚洲精品自拍 | 一区不卡在线观看 | 日本精品久久久久久久久免费 | 成人欧美一区二区三区 | 女人被男人躁得好爽免费视频免费 | 免费播放国产性色生活片 | 在线看欧美日韩中文字幕 | 一级毛片在线 | 亚洲欧美日韩视频一区 | 欧美日韩一区二区三区免费不卡 | 一区二区三区四区视频 | 手机看片日韩日韩国产在线看 | 日韩毛片在线免费观看 | 午夜私人影院免费体验区 | 亚洲国产成人久久综合区 | 一级做a爰片久久毛片欧美 一级做a爰片久久毛片人呢 | 亚洲成人免费观看 | 亚洲免费视频网址 | 成年人激情视频 | 天堂中文资源在线8 | 亚洲香蕉久久一区二区 | 日韩免费在线视频 | 亚洲欧美在线精品一区二区 | 成年午夜一级毛片视频 | 欧美日韩中文一区二区三区 |