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进行访问保护,勿对外网开放,后续我们加入对其的访问保护

最新文章

  1. 微信接口php
  2. Java重点之小白解析--浅谈HashMap与HashTable
  3. salesforce 零基础学习(四十)Custom Settings简单使用
  4. POJ 2386 Lake Counting(深搜)
  5. MFC 修改 单文档 SDI 窗体 标题
  6. Java--常用类summary
  7. MATLAB 函数
  8. Send User to a Portal Folder
  9. 谷歌眼镜--UI指南
  10. session销毁
  11. SafeHandle和Dispose z
  12. Rank of Tetris(hdu1811拓扑排序+并查集)
  13. atitit。自己定义uml MOF EMF体系eclipse emf 教程o7t
  14. IOS 代码管理工具
  15. 手机应用PC端演示工具介绍
  16. 【精】搭建redis cluster集群,JedisCluster带密码访问【解决当中各种坑】!
  17. Django和SQLAlchemy,哪个Python ORM更好?
  18. jQuery筛选总结
  19. Vue.js路由
  20. php 两个值进行比较的问题

热门文章

  1. 【AGC009E】Eternal Average
  2. 深入js系列-类型(数字)
  3. 安卓设备连接Mac的简单方法
  4. iptables 常用命令解析
  5. Spring Boot 2.2.1 发布,一个有点坑的版本!
  6. C/C++中书写汇编指令
  7. prometheus、node_exporter、cAdvisor常用参数
  8. java自带的xml解析工具类
  9. 13. Scala函数式编程(高级部分)
  10. excel查找定位操作(for lutai)