如果是单节点的注册中心,是无法保证系统稳定性的,当然现在项目部署架构不可能是单节点的。
集群节点的部署思路:通过运行多个实例并请求他们相互注册,来完成注册中心的高可用性(结伴注册)
1、添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
2、添加配置
application.yml
spring:
application:
name: EUREKA-HA
profiles:
active: peer3
---
server:
port: 8761
spring:
profiles: peer1
eureka:
instance:
hostname: peer1
prefer-ip-address: false
client:
serviceUrl:
defaultZone: http://peer2:8762/eureka/,http://peer3:8763/eureka/
---
server:
port: 8762
spring:
profiles: peer2
eureka:
instance:
hostname: peer2
prefer-ip-address: false
client:
serviceUrl:
defaultZone: http://peer1:8761/eureka/,http://peer3:8763/eureka/
---
server:
port: 8763
spring:
profiles: peer3
eureka:
instance:
hostname: peer3
prefer-ip-address: false
client:
serviceUrl:
defaultZone: http://peer1:8761/eureka/,http://peer2:8762/eureka/
启动的时候我只需要修改,spring.profiles.active指定环境即可
配置host
最后启动三个Eureka服务,还有一个用户服务注册到Eureka我们可以看到
同理peer2、peer3我们也能看到同样的user服务。