springcloud整合Admin

一、整合Admin

1、添加依赖(注意版本和springboot版本要一致,否则会报错,我的springboot版本是2.5.5)

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

2、配置服务端 eureka yaml文件

spring:
  application:
    name: eureka

  boot:
    admin:
      context-path: /admin
      ui:
        public-url: http://localhost:9900/admin
        title: Sunshine Admin

#暴露服务
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always

3、添加客户端依赖

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

 

4、配置客户端 yaml文件

server:
  port: 9902
  tomcat:
    uri-encoding: UTF-8

eureka:
  instance:
    preferIpAddress: true
    instance-id: ${spring.cloud.client.ip-address}:${server.port}
  client:
    serviceUrl:
      defaultZone: http://localhost:9900/eureka/



##开放所有页面节点,默认只开放health.info
  #management.endpoints.web.exposure.include=*
  ##显示健康具体信息,默认不会显示详细信息
  #management.endpoint.health.show-details=always
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always

5、启动服务即可

二、整合security

1、eureka添加依赖

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

2、eureka配置yaml文件

server:
  port: 9900
  tomcat:
    uri-encoding: UTF-8

eureka:
  instance:
    hostname: localhost
    metadata-map:
      user.name: ${spring.security.user.name}
      user.password: ${spring.security.user.password}
#    心跳发发送频率,指定续约更新频率。
#  如果在eureka在eureka.instance.lease-renewal-interval-in-seconds后没有收到心跳,将摘除改实例。
#    可以解决Eureka注册服务慢的问题,注意:在生产中,最好坚持使用默认值,因为在服务器内部有一些计算,他们对续约做出假设。
    lease-renewal-interval-in-seconds: 10
#  健康检查页面的URL,绝对路径
    health-check-url-path: /actuator/health
#    是否显示IP地址
    prefer-ip-address: true
  client:
    #     声明是否将自己的信息注册到 Eureka 服务器上
    registerWithEureka: true
    #     是否到 Eureka 服务器中抓取注册信息
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/


spring:
  application:
    name: eureka
  security:
    user:
      name: sunshine
      password: sunshine

  boot:
    admin:
      context-path: /admin
      ui:
        public-url: http://localhost:9900/admin
        title: Sunshine Admin

management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always

3、客户端配置yaml文件

server:
  port: 9902
  tomcat:
    uri-encoding: UTF-8

eureka:
  instance:
    preferIpAddress: true
    instance-id: ${spring.cloud.client.ip-address}:${server.port}
  client:
    serviceUrl:
      defaultZone: http://${security.user.name}:${security.user.password}@localhost:9900/eureka/

spring:
  application:
    name: pay-server
  cloud:
    loadbalancer:
      retry:
        enabled: false
  flyway:
    baseline-on-migrate: true
    enabled: true
    validate-on-migrate: false
    locations: classpath:db/migration_pay
  datasource:
    url: jdbc:mysql://localhost:3306/spring_cloud_pay?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
    driver-class-name: com.mysql.jdbc.Driver
    username: root
    password: root
mybatis:
  mapper-locations: classpath:mappers/*.xml
  #  config-location: classpath:mybatis/mybatis-config.xml
  configuration:
    map-underscore-to-camel-case: true
    call-setters-on-nulls: true
#    interceptors: {com.example.sunshine_demo.mybatis_interceptor.InsertInterceptor}

##开放所有页面节点,默认只开放health.info
  #management.endpoints.web.exposure.include=*
  ##显示健康具体信息,默认不会显示详细信息
  #management.endpoint.health.show-details=always
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always

security:
  user:
    name: sunshine
    password: sunshine

4、启动服务即可

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值