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. ZBX_TCP_READ() time out windows

    zabbix 客户端无法推送数据,日志显示在启动的时候ZBX_TCP_READ() time out windows, 场景:agent 到proxy的10051通,proxy到agnet的10050 ...

  2. ESA2GJK1DH1K升级篇: 升级STM32 预热: 单片机每隔一定时间 使用 http 获取天气

    前言: 实现功能概要: STM32使用AT指令控制Wi-Fi以TCP方式连接服务器(YY天气Web服务器),然后使用http的get协议获取今天的天气数据 单片机提取今天的温度和湿度数据,把温湿度数据 ...

  3. 搜索法 | 1103 dfs搜索:符合条件的多项式

    其实这题我已经写过两遍了,但都是在看过算法笔记的情况下写的.方法不难,只要能想出来. 找到一个项数为k,每项为p次幂,和为n,并且在有多个结果的情况下要求数字之和最大的一个多项式.如果数字之和相等.还 ...

  4. 【树状数组】【P5069】[Ynoi2015]纵使日薄西山

    Description 给定一个长度为 \(n\) 的非负整数序列 \(\{a_n\}\),\(q\) 次操作,每次要么单点修改序列某个值,要么查询整个序列需要操作多少次才能变成全 \(0\). 一次 ...

  5. Spring Boot进阶系列三

    Thymeleaf是官方推荐的显示引擎,这篇文章主要介绍怎么让spring boot整合Thymeleaf.  它是一个适用于Web和独立环境的现代服务器端Java模板引擎. Thymeleaf的主要 ...

  6. 20165214 2018-2019-2 《网络对抗技术》Exp9 Web安全基础 Week13

    <网络对抗技术>Exp9 Web安全基础 Week13 一.实验目标与内容 1.实践内容 (1).本实践的目标理解常用网络攻击技术的基本原理,做不少于7个题目.包括(SQL,XSS,CSR ...

  7. shell (二) shell for循环

    for循环 基本示例 for i in var1 var2 var2 do echo $i done for i in {1..100} do echo $i done 列表中复杂值,可以使用引号或者 ...

  8. K8S之traefik高级特性

    Traefik Traefik是一个用Golang开发的轻量级的Http反向代理和负载均衡器.由于可以自动配置和刷新backend节点,目前可以被绝大部分容器平台支持,例如Kubernetes,Swa ...

  9. Qt 实现超时锁屏

    最近使用Qt实现超时锁屏的功能(工控机触摸屏),当手长时间不触摸屏幕的时候,程序超时会显示锁屏窗口. 一.效果 主窗口超时显示锁屏窗口: 系统窗口超时显示锁屏窗口: 二.实现思路 首先开启一个线程用于 ...

  10. CentOS 7.6 安装Python3.7.2 多版本共存

    CentOS 7.6 默认安装了 Python 2.7.5 准备环境 yum install git gcc gcc-c++ make automake autoconf libtool pcre p ...