添加依赖

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

启动类注解

@EnableEurekaServer 触发eureka服务器的自动配置

配置yml

spring:
  application:
    name: eureka-server
server:
  port: 2001
eureka:
  server:
    # 禁用自我保护模式
    enable-self-preservation: false
  instance:
    hostname: eureka1
  client:
    register-with-eureka: false #不向自身注册
    fetch-registry: false #不从自身拉取注册信息

配置多个eureka

在这里插入图片描述

eureka1:application-eureka1.yml

eureka:
  instance:
    hostname: eureka1
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://eureka2:2002/eureka

eureka2:application-eureka2.yml

eureka:
  instance:
    hostname: eureka2
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://eureka1:2001/eureka

更改启动参数

设置两个:

--spring.profiles.active=eureka1 --server.port=2001
--spring.profiles.active=eureka2 --server.port=2002

在这里插入图片描述

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐