springbootの管理者とユーリカの監視

  1. 管理者の監視
  • 管理者のサービス側
  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アノテーションに追加されます
  • 管理者のクライアント側
  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.ユーレカのサービス側

  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アノテーションを追加します
  • ユーレカのクライアント側
  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