准备工作
Eureka-client 一个,Eureka-server 一个,config-server 一个
1.1 pom 的准备
config-server
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
eureka-client 和 Eureka-server 都添加
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
1.2 配置文件
eureka-client
server:
port: 8081
spring:
application:
name: eureka-client1
eureka:
instance:
hostname: localhost
prefer-ip-address: true
client:
service-url:
default-zone: http://localhost:8761/eureka/
eureka-server
server:
port: 8761
eureka:
instance:
hostname: localhost
prefer-ip-address: true
client:
service-url:
default-zone: http://${eureka.instance.hostname}:${server.port}/eureka/
register-with-eureka: false
fetch-registry: false
server:
wait-time-in-ms-when-sync-empty: 0
enable-self-preservation: false
config-server
目录结构
application.yml
server:
port: 8888
spring:
application:
name: config-server
profiles:
active: native
eureka-client.yml
server:
port: 8081
spring:
application:
name: eureka-client1
eureka:
client:
service-url:
default-zone: http://localhost:8761/eureka/
eureka-server-peer1.yml
server:
port: 8761
eureka:
instance:
hostname: localhost
prefer-ip-address: true
client:
service-url:
default-zone: http://localhost:8761/eureka/
register-with-eureka: true
fetch-registry: true
server:
wait-time-in-ms-when-sync-empty: 0
enable-self-preservation: false
然后先后启动 config-server、eureka-server、eureka-client