springboot的监控 admin 和eureka

  1. admin监控
  • admin的service端
  1. pom.xml
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
        </dependency>
  1. application.yml
spring:
   application:
     name: admin-server
server:
   port: 9090
  1. springboot入口文件出加入@EnableAdminServer注解
  • admin的Client端
  1. pom.xml
       <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
        </dependency>
  1. application.yml
server:
   port: 8080
spring:
   application:
     name: Admin Client
   boot:
     admin:
       client:
         url: http://localhost:9090
management:
   endpoints:
     web:
       exposure:
        include: '*'

运行结果
在这里插入图片描述
2. eureka的service端

  1. pom.xml
       <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
  1. application.yml

server:
  port: 8000 # 你的端口
 
eureka:
  instance:
    hostname: localhost # 你的地址
  client:
    registerWithEureka: false # 表示是否注册自身到eureka服务器,因为当前这个应用就是eureka服务器,没必要注册自身,所以这里是false
    fetchRegistry: false # fetchRegistry表示是否从eureka服务器获取注册信息
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ 
      # defaultZone就比较重要了,是设置eureka服务器所在的地址,查询服务和注册服务都需要依赖这个地址。

  1. springboot入口文件处加入@EnableEurekaServer注解
  • eureka的Client端
  1. pom.xml
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
  1. application.yml
server:
  port: 8001  # 你的端口
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8000/eureka/  # 服务中心地址
spring:
  application:
    name: orcl # 客户端的名字

  1. springboot入口文件处加入@EnableEurekaClient注解

运行结果
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/lmsfv/article/details/105528142