1 说明

  1. 全部配置基于1.8.0_111
  2. 当前SpringBoot使用2.0.5
  3. SpringBootAdmin基于Eureka进行Client发现,Eureka搭建参见SpringBoot2.x搭建Eureka
  4. SpringBootAdmin项目文档参见SpringBootAdmin参考文档

2 创建项目

SpringBoot项目生成器中,输入GroupArtifact,如下配置:

3 编辑pom.xml文件

pom.xml中新添加如下内容:

 <properties>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.0.3</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>

4 修改application.properties为application.yml文件

编辑application.properties为application.yml文件,添加以下内容:

server:
port: 8099
spring:
application:
name: SpringBootAdmin
security:
user:
name: anxminise
password: 123456
boot:
admin:
ui:
title: 忧臣解读 management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
eureka:
instance:
metadata-map:
user.name: anxminise
user.password: 123456
easeRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
ip-address: 127.0.0.1
prefer-ip-address: true
instance-id: ${eureka.instance.ip-address}:${server.port}
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: http://anxminise:123456@127.0.0.1:8888/eureka/

配置参数解释:

参数 说明
security.user.name SpringBootAdmin登录时的用户名
security.user.password SpringBootAdmin登录时的密码
eureka.instance.metadata-map.user.name SpringBootAdmin本身作为一个Eureka客户端被发现,这里由于SpringBootAdmin需要进行登录,因此,此处配置SpringBootAdmin登录时使用的用户名
eureka.instance.metadata-map.user.password 同上,配置SpringBootAdmin登录使用的密码

5 编辑SpbadminApplication.java文件

最后编辑SpbadminApplication.java文件,修改为:

@EnableDiscoveryClient
@EnableAdminServer
@SpringBootApplication
public class SpbadminApplication { public static void main(String[] args) {
SpringApplication.run(SpbadminApplication.class, args);
} @Configuration
public static class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
private final String adminContextPath; public SecuritySecureConfig(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()
.formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
.logout().logoutUrl(adminContextPath + "/logout").and()
.httpBasic().and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringAntMatchers(
adminContextPath + "/instances",
adminContextPath + "/actuator/**"
);
}
}
}

6 编译并启动运行

注:本次SpringBootAdmin是基于Eureka搭建的,需要先启动Eureka
./mvnw clean package -DskipTests #编辑应用
java -jar target/spbadmin-0.0.1-SNAPSHOT.jar #启动应用,注:jar包的名称应换成自己的





7 Eureka客户端监控

SpringBootAdmin的作用是:监控Eureka中的微服务,这里的微服务,我们使用SpringBoot2.x进行开发,对于SpringBoot2.x的SpringBoot项目,只需在application.yml中新加入以下内容:

logging:
path: logs/log
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS

参数解释说明

参数 说明
logging.path 配置日志的存放路径,此处用于SpringBootAdmin的日志监控
management.* 配置SpringBoot的全部监控点,此处注意:当前配置未对endpoint进行访问保护,勿对外网开放,后续我们加入对其的访问保护

SpringBoot2.x搭建SpringBootAdmin2.x的更多相关文章

  1. SpringBoot2.x搭建Eureka

    1 说明 全部配置基于1.8.0_111 当前SpringBoot使用2.0.5 2 创建项目 在SpringBoot项目生成器中,输入Group和Artifact,如下配置: 3 pom.xml配置 ...

  2. Spring Boot 2.X 如何添加拦截器?

    最近使用SpringBoot2.X搭建了一个项目,大部分接口都需要做登录校验,所以打算使用注解+拦截器来实现,在此记录下实现过程. 一.实现原理 1. 自定义一个注解@NeedLogin,如果接口需要 ...

  3. WebFlux03 SpringBoot WebFlux实现CRUD

    1 准备 基于SpringBoot2.0搭建WebFlux项目,详情请参见三少另外一篇博文 2 工程结构 <?xml version="1.0" encoding=" ...

  4. 使用JWT来实现单点登录功能

    出处: https://www.cnblogs.com/zexin/p/10389541.html 我们平时自己开发项目,分布式的结构时,访问量不大,但是又不想搭建redis服务器,这时我觉得jwt不 ...

  5. 如何使用JWT来实现单点登录功能

    我们平时自己开发项目,分布式的结构时,访问量不大,但是又不想搭建redis服务器,这时我觉得jwt不错. 个人理解,jwt就是类似于一把锁和钥匙,客户来租房(登录),我们需要给他进来(第一次登录)登记 ...

  6. SpringBoot2.0基础案例(01):环境搭建和RestFul风格接口

    一.SpringBoot 框架的特点 1.SpringBoot2.0 特点 1)SpringBoot继承了Spring优秀的基因,上手难度小 2)简化配置,提供各种默认配置来简化项目配置 3)内嵌式容 ...

  7. SpringBoot2整合activiti6环境搭建

    SpringBoot2整合activiti6环境搭建 依赖 <dependencies> <dependency> <groupId>org.springframe ...

  8. SpringBoot2 整合Nacos组件,环境搭建和入门案例详解

    本文源码:GitHub·点这里 || GitEE·点这里 一.Nacos基础简介 1.概念简介 Nacos 是构建以"服务"为中心的现代应用架构,如微服务范式.云原生范式等服务基础 ...

  9. SpringBoot2.x【一】从零开始环境搭建

    SpringBoot2.x[一]从零开始环境搭建 对于之前的Spring框架的使用,各种配置文件XML.properties一旦出错之后错误难寻,这也是为什么SpringBoot被推上主流的原因,Sp ...

随机推荐

  1. [RN] React Native 获取地理位置

    React Native 获取地理位置 实现原理: 1.用  navigator.geolocation.getCurrentPosition 获取到坐标信息 2.调用 高德地图 接口,解析位置数据 ...

  2. T2:中间值(median)———2019.10.15

    代码: #include <bits/stdc++.h> int ri() { , f = ; ; ) + (x << ) - ' + c; return x * f; } ; ...

  3. 关于window PC机的预定义宏win32

    MSDN 里说,VC 有 3 个预处理常量,分别是 _WIN32,_WIN64,WIN32.这三个常量如何使用呢?看起来简单,其实是很困惑的. 在 Win32 配置下,WIN32 在“项目属性-C/C ...

  4. 编码格式检测chardet模块

    chardet模块: -->检测编码格式 未知编码的bytes,要把它转换成str,就需要知道该bytes的编码方式 #1.直接检测bytes >>> chardet.dete ...

  5. iptables man手册翻译

    概要 iptables [-t table] -[AD] chain rule-specification [options]iptables [-t table] -I chain [rulenum ...

  6. linux脚本中有source相关命令时的注意事项

    写这个问题起因是因为一个同学去的java一键脚本环境变量设置问题, [root@localhost u01]# more 1.sh #!/bin/bash grep -q "export J ...

  7. 微信小程序在苹果手机的New Date坑

    new Date(“2017-06-16”) 在IOS会出现NAN的情况,必须改为new Date(“2017/06/16”) 才能兼容

  8. spark listener

    最近在做一个需求,当spark程序在读数据或写数据时,将所读的条数或或所写的条数实时的展现出来,这里用到了SparkListener,sparklisten 可以获取spark 各个运行阶段的状态. ...

  9. JS面向对象的类 实例化与继承

    JS中 类的声明有两种形式: // 类的声明 function Animal() { this.name = 'name' } // ES6中的class声明 class Animal2 { cons ...

  10. TP-LINK WR703N OpenWrt 无线配网历程

    ① 创建了两个 Interfaces,名字分别为 lan.wlan0 (可自行设定),一个负责连接 PPPoE,一个负责提供 AP 热点. ② 配置 wlan0 相关 ip 地址,该地址为无线网内网地 ...