Springcould (two) build service registration center Eureka cluster

In order to achieve the high availability of the service registry Eureka, we usually build Eureka into a cluster, so that when an Eureka goes down, the service providers registered in it can be accessed normally, thereby achieving high availability .

The previous article talked about building a stand-alone version of Eureka, continue the project in the previous article, create two new modules, eureka-server-7002 and eureka-server-7003, modify the application.yml configuration of 7001, 7002 and 7003 The files are as follows:

server:
  port: 7001 #eureka服务端的端口号

eureka:
  instance:
    hostname: eureka7001.com #eureka服务端的实例名称

  client:
    register-with-eureka: false  #不用把自己注册进注册中心
    fetch-registry: false
    service-url:
      #单机 defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
       defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/ #集群绑定,三台eureka互相知道对方
server:
  port: 7002 #eureka服务端的端口号

eureka:
  instance:
    hostname: eureka7002.com #eureka服务端的实例名称

  client:
    register-with-eureka: false  #不用把自己注册进注册中心
    fetch-registry: false
    service-url:
      #单机 defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
       defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7003.com:7003/eureka/
server:
  port: 7003 #eureka服务端的端口号

eureka:
  instance:
    hostname: eureka7003.com #eureka服务端的实例名称

  client:
    register-with-eureka: false  #不用把自己注册进注册中心
    fetch-registry: false
    service-url:
      #单机 defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
       defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/

 The instance names of the eureka server have been modified here. This is to distinguish the three eureka services. We use eurekaxxxx.com to access (on windows), so we need to modify the host file to modify the domain name mapping. Here are three eurekaxxxx. Com are mapped to 127.0.0.1, and then in defaultZone, because you need to build a cluster, you must write 7002 and 7003 service URLs in 7001, and so on, so that the three eureka services can sense each other and can Bind up to form a cluster. We visit 7001

You can see 7002 and 7003 below 7001. For the Eureka cluster, every node is equal, and there is no distinction between high and low priority. When the Eureka connection we visit times out, it will automatically connect to another Eureka server, thus seamlessly. In order to achieve high availability, this is different from Zookeeper. When the master in the zookeeper cluster is down, the remaining salver will select the master through the election mechanism, and this process takes about 30s-120s. During this period, the entire zookeeper The cluster is not available, so zookeeper cannot achieve high availability. This is the difference between the two.

 

Guess you like

Origin blog.csdn.net/weixin_37689658/article/details/88557676