春のブート管理を監視springbootビジュアルインターフェイスサービス

サーバーのセットアップ

作成springbootサーバープロジェクト
のjarパッケージを導入します


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

        <!-- springboot admin server安全登录控制 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>2.2.1.RELEASE</version>
        </dependency>

新しい設定項目

server.port=9527

spring.application.name=spring-boot-examples-admin-server
spring.security.user.name=admin
spring.security.user.password=123456

新しいセキュリティコントロールの設定クラス、ノートに注意を払う@Configuration

@Configuration
public class SecuritySecureServerConfig extends WebSecurityConfigurerAdapter {
    private final String adminContextPath;

    public SecuritySecureServerConfig(AdminServerProperties adminServerProperties) {
        this.adminContextPath = adminServerProperties.getContextPath();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // 登录成功处理类
        SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        successHandler.setDefaultTargetUrl(adminContextPath + "/");

        http.authorizeRequests()
                //静态文件允许访问
                .antMatchers(adminContextPath + "/assets/**").permitAll()
                //登录页面允许访问
                .antMatchers(adminContextPath + "/login").permitAll()
                //其他所有请求需要登录
                .anyRequest().authenticated()
                .and()
                //登录页面配置,用于替换security默认页面
                .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
                //登出页面配置,用于替换security默认页面
                .logout().logoutUrl(adminContextPath + "/logout").and()
                .httpBasic().and()
                .csrf()
                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                .ignoringAntMatchers(
                        "/instances",
                        "/actuator/**"
                );
    }
}

注釈付きの新しいクラスを開始します@EnableAdminServer

@SpringBootApplication
@EnableAdminServer
public class ServerApplication {

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

}

この時点で設定したサーバが完了し、ブラウザとを入力します。http:// localhostを:9527 /、ユーザー名adminを入力し、パスワード123456
ここに画像を挿入説明

クライアントのビルド

JARパッケージの導入


        <!-- spring-boot-admin-client -->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>2.2.1</version>
        </dependency>

        <!-- spring-boot-admin-client 中加入 actuator, 将 spring-boot-admin-client 的端点数据暴露出来 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>2.2.1.RELEASE</version>
        </dependency>

        <!-- springboot admin server安全登录控制 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>2.2.1.RELEASE</version>
        </dependency>

新しい設定項目

server.port=8080

#springboot admin client
spring.boot.admin.client.url=http://localhost:9527
#暴露所有的 actuator 端点信息重启
management.endpoints.web.exposure.include=*

spring.application.name=spring-boot-examples-admin-client
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=123456
spring.boot.admin.client.instance.metadata.user.name=${spring.security.user.name}
spring.boot.admin.client.instance.metadata.user.password=${spring.boot.admin.client.password}
spring.security.user.name=client
spring.security.user.password=123456
spring.security.user.roles=ACTUATOR_ADMIN

新しいセキュリティコントロールの設定クラス、ノートに注意を払う@Configuration

@Configuration
public class SecuritySecureClientConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                //拦截所有endpoint,拥有ACTUATOR_ADMIN角色可访问,否则需登录
                .requestMatchers(EndpointRequest.toAnyEndpoint()).hasRole("ACTUATOR_ADMIN")
                //静态文件允许访问
                .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
                //根路径允许访问
                .antMatchers("/").permitAll()
                //所有请求路径可以访问
                .antMatchers("/**").permitAll()
                .and().httpBasic();
    }
}

クライアントを起動し、次のようにインターフェースがあるリフレッシュ
ここに画像を挿入説明
クリック管理クライアントは、詳細情報を監視表示
ここに画像を挿入説明

参考記事は、
春のブート管理を使用すると説明し
4穴ガイドのSpringBootを:使用春ブーツ管理者は、サービスの監視を行います

公開された17元の記事 ウォンの賞賛0 ビュー404

おすすめ

転載: blog.csdn.net/qq_25073261/article/details/104747040