springCloud之Eureka高可用性配置(ha)
1: 添加主机名:
hosts 配置: 127.0.0.1 peer1 peer2
2:修改application.yml
---
spring:
profiles: peer1 # 指定profile=peer1
server:
port: 8761
eureka:
instance:
hostname: peer1 # 指定当profile=peer1时,主机名
client:
serviceUrl:
defaultZone: http://peer2:8762/eureka/ # 将自己注册到peer2这个Eureka上面去
---
spring:
profiles: peer2
server:
port: 8762
eureka:
instance:
hostname: peer2
client:
serviceUrl:
defaultZone: http://peer1:8761/eureka/
3:分别启动两个Eureka应用
java -jar microservice-discovery-eureka-0.0.1-SNAPSHOT.jar -- spring.profiles.active=peer1
java -jar microservice-discovery-eureka-0.0.1-SNAPSHOT.jar -- spring.profiles.active=peer2
4:现象:
访问 http://peer1:8761 ,我们会发现 registered-replicas 中已 经有 peer2 节点了,同样地,访问 http://peer2:8762 ,也能发现 其中的 registered-replicas 有 peer1 节点