搭建 Eureka 集群
为了
高可用
高可用 是微服务 RPC 远程服务调用的最核心思想。
如果你的注册中心只有一台,假如出现故障,直接欢声笑语打出GG。
这样子会导致整个服务环境不可用,所以我们要搭建集群环境,实现负载均衡+故障容错

文件位置:
############ SpringCloud_Eureka集群搭建 #####################
127.0.0.1 eureka7001.com
127.0.0.1 eureka7002.com

server:
port: 7001
spring:
application:
name: Eureka-server-7001
# 单机版本
#eureka:
# instance:
# hostname: localhost # eureka 服务端的实例名称
# client:
# register-with-eureka: false # 表示不向注册中心注册自己
# fetch-registry: false # 表示自己就是注册中心,职责是维护服务实例,并不需要去探索服务
# service-url:
# # 设置与 eureka server 交互的地址查询服务和注册服务都需要依赖这个地址
# defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
# 集群版本
eureka:
instance:
hostname: eureka7001.com # eureka服务端的实例名称
client:
register-with-eureka: false # 表示不向注册中心注册自己
fetch-registry: false # 表示自己就是注册中心,职责是维护服务实例,并不需要去探索服务
service-url:
# 集群的话 就需要互相配置对方的地址
defaultZone: http://eureka7002.com:7002/eureka/

server:
port: 7002
# 配置集群 是否就取消此别名
spring:
application:
name: Eureka-server-7002
# 单机版本
#eureka:
# instance:
# hostname: localhost # eureka 服务端的实例名称
# client:
# register-with-eureka: false # 表示不向注册中心注册自己
# fetch-registry: false # 表示自己就是注册中心,职责是维护服务实例,并不需要去探索服务
# service-url:
# # 设置与 eureka server 交互的地址查询服务和注册服务都需要依赖这个地址
# defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
# 集群版本
eureka:
instance:
hostname: eureka7002.com # eureka服务端的实例名称
client:
register-with-eureka: false # 表示不向注册中心注册自己
fetch-registry: false # 表示自己就是注册中心,职责是维护服务实例,并不需要去探索服务
service-url:
# 集群的话 就需要互相配置对方的地址
defaultZone: http://eureka7001.com:7001/eureka/
@SpringBootApplication
@EnableEurekaServer //设置为服务注册中心 EurekaServer
public class EurekaServer7001 {
public static void main(String[] args) {
SpringApplication.run(EurekaServer7001.class,args);
}
}
@SpringBootApplication
@EnableEurekaServer
public class EurekaServer7002 {
public static void main(String[] args) {
SpringApplication.run(EurekaServer7002.class,args);
}
}

可以看到两个服务 相互注册,互相帮助~