eureka服务注册与服务发现

1 eureka服务端编写

在这里插入图片描述

server:
  port: 8761
eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

2 eureka客户端编写

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
spring:
  application:
    name: client

启动如果报错,需要引入spring-boot-starter-web

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

3 eureka高可用

在这里插入图片描述
复制一个Application,改端口,一个8761,一个8762

-Dserver.port=8761

在这里插入图片描述

**分别启动EurekaApplication1 和 EurekaApplication2
EurekaApplication1 注册到8762

defaultZone: http://localhost:8762/eureka/

EurekaApplication2 注册到8761**

defaultZone: http://localhost:8761/eureka/

client端配置多个服务:

defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/

同理,三个服务
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_38950013/article/details/89511430