官网地址
https://cloud.spring.io/spring-cloud-static/Finchley.SR2/multi/multi_spring-cloud-eureka-server.html
1.pom文件引入netflix-eureka-server
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
2.SpringCloudEurekaApplication上加注解
@EnableEurekaServer
3.配置主机hostsC:\Windows\System32\drivers\etc\hosts
127.0.0.1 peer1
127.0.0.1 peer2
127.0.0.1 peer3
4.yml配置
spring:
application:
name: spring-cloud-eureka
eureka:
client:
serviceUrl:
defaultZone: http://peer1:8000/eureka/,http://peer2:8001/eureka/,http://peer3:8002/eureka/
---
spring:
profiles: peer1
server:
port: 8000
eureka:
instance:
hostname: peer1
---
spring:
profiles: peer2
server:
port: 8001
eureka:
instance:
hostname: peer2
---
spring:
profiles: peer3
server:
port: 8002
eureka:
instance:
hostname: peer3
5.访问
peer1:8000
peer2:8001
peer3:8002