pom.xml如下:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
配置文件:bootstrap.yml (也可以使用application.yml)
server:
port: 8001
spring:
profiles: eureka1
application:
name: eureka-server
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8001/eureka/,http://127.0.0.1:8002/eureka/
register-with-eureka: true #自身 不在向eureka注册
fetch-registry: false #启动时禁用client的注册
instance:
hostname: 127.0.0.1 ###最好使用IP地址,localhost的话也行,看个人习惯
preferIpAddress: true ###核心
---
server:
port: 8002
spring:
profiles: eureka2
application:
name: eureka-server
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8001/eureka/,http://127.0.0.1:8002/eureka/
register-with-eureka: true #自身 不在向eureka注册
fetch-registry: false #启动时禁用client的注册
instance:
hostname: 127.0.0.1
preferIpAddress: true