springCloud系列——actuator和springbootAdmin集成安全框架security实现服务监控

一、actuator:

其实boot提供了actuator来实现服务监控,只是这种方式比较麻烦,要自己去请求不同的接口,查看json信息来判断服务的情况.

在这里插入图片描述
请求不同的端点(路径),查看不同的监控信息。

二、actuator虽然可以实现,但是没有可视化界面,所以就有了springbootAdmin,提供UI界面来监控服务信息。

三、再集成安全框架,不是谁都可以看这些信息的,除非指定账户密码:

四、依赖pom:

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

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

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

5、实现:

(1)、创建一个admin管理服务端:

在这里插入图片描述
主要配置:

admin登录的用户名和密码

spring:
  security:
        user:
          name: "***"
          password: "*****"

actuator默认不开放,所以要设置为开放

management:
  endpoints:
    web:
      exposure:
        include: "*"  #暴露所有的端点我们可以看到更多应用相关信息
  endpoint:
    health:
      show-details: ALWAYS  #health endpoint是否必须显示全部细节

注册admin项目到eureka服务中心

eureka:   
  instance:
    health-check-url-path: /actuator/health   #应用实例的相对运行状况检查URL路径默认为 /info/health ,2.0后actuator的地址发生了变化
  client:
    serviceUrl:
      defaultZone: http://miller:miller@eureka-server1:8761/eureka/ #注册到 EurekaServer

完整配置:

spring:
	  application:
	    name: admin-server
	# tag::configuration-eureka[]
	eureka:   #<1>
	  instance:
	    health-check-url-path: /actuator/health   #应用实例的相对运行状况检查URL路径默认为 /info/health ,2.0后actuator的地址发生了变化
	  client:
	    serviceUrl:
	      defaultZone: http://miller:miller@eureka-server1:8761/eureka/ #注册到 EurekaServer
	# 2.0开始,actuator默认不开放,所以要设置为开放
	management:
	  endpoints:
	    web:
	      exposure:
	        include: "*"  #暴露所有的端点我们可以看到更多应用相关信息
	  endpoint:
	    health:
	      show-details: ALWAYS  #health endpoint是否必须显示全部细节
	server:
	  port: 2222
	---
	#spring:
	  profiles: insecure
	
	---
	## admin登录的用户名和密码
	spring:
	  profiles: secure
	  security:
	        user:
	          name: "***"
	          password: "****¥"
	## 注册给eureka的时候告诉eureka自己的密码
	eureka:
	  instance:
	    metadata-map:
	      "user.name": ${spring.security.user.name}
	      "user.password": ${spring.security.user.password}

(2)、创建一个admin客户端(被admin项目监控的服务):

主要配置:

将当前微服务给springboot-admin监控平台管理

boot:
  admin:
    client:
      url: "http://localhost:2222"   #指定SpringBootAdmin服务端地址
      username: xxx
      password: xxxxx
      instance:
        prefer-ip: true

暴露所以端点给admin监控

management:
  endpoints:
    web:
      exposure:
        include: "*"   #暴露所有的端点我们可以看到更多的服务实例相关信息,
  endpoint:
    health:
      show-details: ALWAYS   #health endpoint是否必须显示全部细节

两个eureka服务注册中心,相互注册,记得实现了security账户密码的,在注册的时候,要,http://账号:密码@IP:端口号/eureka/,才能注册上。

spring:
  profiles: eureka-server1
server:
  port: 8761
eureka:
  instance:
    hostname: eureka-server1
  client:
    serviceUrl:
      defaultZone: http://miller:miller@eureka-server1:8761/eureka/,http://miller:miller@eureka-server2:8762/eureka/
#        defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@eureka-server2:8762/eureka/
---
spring:
  profiles: eureka-server2
server:
  port: 8762
eureka:
  instance:
    hostname: eureka-server2
  client:
    serviceUrl:
      defaultZone: http://miller:miller@eureka-server1:8761/eureka/,http://miller:miller@eureka-server2:8762/eureka/
#      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@eureka-server1:8761/eureka/

6、最终效果:

登录admin监控平台:http://localhost:2222

在这里插入图片描述

在这个可视化的界面上,查看所有注册到admin平台的微服务的各种信息!!!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值