Eureka2.0高可用集群搭建

先搭建注册中心等:https://www.cnblogs.com/tripleDemo/p/11245357.html

Eureka高可用原理:

Eureka高可用实际上将自己作为服务向其他服务注册中心注册自己,这样就可以形成一组相互注册的服务注册中心,从而实现服务清单的互相同步,达到高可用效果。搭建eureka集群环境至少两台。

Eureka2.0高可用集群搭建

各注册中心配置文件(application.yml)

###服务端口号
server:
  port: 9100
###定义服务名称
spring:
  application:
    name: app-hclz-eureka 
eureka:
  instance:
    ###注册中心ip地址
    hostname: 127.0.0.1
  client:
    service-url:
      ###注册中心地址
      defaultZone: http://${eureka.instance.hostname}:8100/eureka/
    ###需要将我的服务注册到eureka上(集群的时候是需要是为true)      
    register-with-eureka: true
    ###需要检索服务
    fetch-registry: true
###服务端口号
server:
  port: 8100
###定义服务名称
spring:
  application:
    name: app-hclz-eureka 
eureka:
  instance:
    ###注册中心ip地址
    hostname: 127.0.0.1
  client:
    service-url:
      ###注册中心地址
      defaultZone: http://${eureka.instance.hostname}:9100/eureka/
    ###需要将我的服务注册到eureka上(集群的时候是需要是为true)       
    register-with-eureka: true
    ###需要检索服务
    fetch-registry: true

客户端调用Eureka2.0集群环境

扫描二维码关注公众号,回复: 6878522 查看本文章

服务提供者和服务消费者配置文件(application.yml)

###会员项目的端口号
server:
  port: 8010
###服务别名(服务注册到注册中心名称)
spring:
  application:
    name: app-hclz-member 
eureka:
  client:
    service-url:
      ###当前会员服务注册到eureka服务地址
      defaultZone: http://localhost:8100/eureka,http://localhost:9100/eureka
    ###需要将我的服务注册到eureka上
    register-with-eureka: true
    ###需要检索服务
    fetch-registry: true
###订单服务的端口号
server:
  port: 8001
###服务别名(服务注册到注册中心名称)
spring:
  application:
    name: app-hclz-order 
eureka:
  client:
    service-url:
      ###当前会员服务注册到eureka服务地址
      defaultZone: http://localhost:8100/eureka,http://localhost:9100/eureka
    ###需要将我的服务注册到eureka上
    register-with-eureka: true
    ###需要检索服务
    fetch-registry: true

在注册过程当中,只会保证有一台注册中心服务有对应服务信息数据

当9100注册中心宕机后,启动转移同步数据到8100

猜你喜欢

转载自www.cnblogs.com/tripleDemo/p/11254664.html