Eureka 高可用 - 踩坑回忆

1、application.yml中eureka配置更改

## Eurake 公用配置
## 向其他注册中心注册
eureka.client.register-with-eureka=true
## 获取其他注册中心注册信息
eureka.client.fetch-registry=true

也可以删除此配置,默认是true

2、eureka.client.service-url.defaultZone的host不要使用嵌套配置

server:
  port: 8761

eureka:
  instance:
    hostname: peer2

eureka:
  client:
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

如上,嵌套了eureka.instance.hostname配置。这会导致注册中心集群构建出问题:其他注册中心的DS Replicas 无法显示此注册中心的节点信息

3、eureka.client.service-url.defaultZone的host不要使用127.0.0.1或者localhost,使用自定义的host

eureka:
  client:
    serviceUrl:
      defaultZone: http://peer2:8761/eureka/

同时更改系统hosts配置:

linux系统通过vim /etc/hosts

windows电脑,在c:/windows/systems/drivers/etc/hosts 修改

添加配置:

    127.0.0.1 peer1
    127.0.0.1 peer2

如果配置的时候使用localhost,注册中心上注册的其他服务实例会被莫名地剔除,即使开启eureka的自我保护机制,依然不能阻止服务被剔除,且无任何异常,且新注册的服务提供者实例也无法进行数据同步。

可能的原因:配置的时候使用localhost,这个是不会发给网卡的(回环地址),服务之间是无法通过这个互相通讯

posted @ 2018-10-09 16:36  Mr.Zhongzz  阅读(2009)  评论(0编辑  收藏  举报