Eureka Server: How to achieve high availability

点点圈 提交于 2019-12-02 16:17:51

Eureka Discovery Server should be used in the Peer-Aware config mode in production setups. Check: http://cloud.spring.io/spring-cloud-static/spring-cloud.html#_peer_awareness

For instance your first eureka server instance will have config like this:

server:
   port: 1111
eureka:
   instance:
      hostname: peer1
   client:
      serviceUrl:
           defaultZone: http://peer2:1112/eureka/

..and second server instance like this:

server:
   port: 1112
eureka:
   instance:
      hostname: peer2
   client:
      serviceUrl:
           defaultZone: http://peer1:1111/eureka/

When Eureka server instances will boot up they will look for each other. All microservices will register with them automatically, so if one goes down the other server instance will be always there. On both Eureka instances you will be able to see all the registered microservices. Like this you can scale-up and have multiple server instances in a production environment.

Note: If you are trying this on a single system, dont forget to edit the /etc/hosts file:
127.0.0.1 peer1
127.0.0.1 peer2

xchunzhao

I met the same error as yours,config like this will work:

eureka:
    instance:
        hostname: localhost
    client:
        registerWithEureka: false
        fetchRegistry: false
        serviceUrl:
            default: http://${eureka.instance.hostname}:${server.port}/eureka/
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!