Spring-Cloud-Netflix-Eureka Cluster Setup

TOC

eureka cluster principle

  1. After the service starts to register with Eureka, Eureka Server registration information will be synchronized to other Eureka Server,
  2. When the service consumer to call the service provider, you get the service provider address registered to the service center, the service provider will then address in the local cache,
  3. The next time you call, get directly from the local cache, complete a call.

Build process

  1. Modify the host file C: \ Windows \ System32 \ drivers \ etc \ host the read-only attribute removed Here Insert Picture Description
  2. Adding host information Here Insert Picture Description
127.0.0.1   eureka
127.0.0.1   eureka1
127.0.0.1   eureka2
  1. New two submodules Eureka3001, Eureka3002 Here Insert Picture Description Here Insert Picture Description
  2. Configuration and Eureka3000 as (pom.xml, startup class) Here Insert Picture Description
  3. Eureka3000 yml modify the configuration file Here Insert Picture Description
server:
  port: 3000
spring:
  application:
    name: eurekaServer  
eureka:
  server:
    enable-self-preservation: false  #关闭自我保护机制
    eviction-interval-timer-in-ms: 4000 #设置清理间隔(单位:毫秒 默认是60*1000)
  instance:
    hostname: eureka

  client:
    registerWithEureka: true #不把自己作为一个客户端注册到自己身上
    fetchRegistry: true  #不需要从服务端获取注册信息(因为在这里自己就是服务端,而且已经禁用自己注册了)
    serviceUrl: #微服务要注册到的地址.
      defaultZone: http://eureka1:3001/eureka,http://eureka2:3002/eureka,


  1. Copy application.yml to Eureka3001, Eureka3002 Here Insert Picture Description Here Insert Picture Description
  2. In turn starts Eureka3000, Eureka3001, Eureka3002 start Eureka3000, Eureka3001 may be error, because the interdependence of the three services, as long as all three services start completed on the line Here Insert Picture Description Here Insert Picture Description Here Insert Picture Description
  3. The user, goods, goods1 clients registered to the server center 1. Open the user's application.yml Here Insert Picture Description
server:
  port: 5000
eureka:
  client:
    serviceUrl:
      #eureka服务端提供的注册地址 参考服务端配置的这个路径
      defaultZone: http://eureka:3000/eureka,http://eureka1:3001/eureka,http://eureka2:3002/eureka
  instance:
    instance-id: user-1 #此实例注册到eureka服务端的唯一的实例ID
    prefer-ip-address: true #是否显示IP地址
    #eureka客户需要多长时间发送心跳给eureka服务器,表明它仍然活着,默认为30 秒 (与下面配置的单位都是秒)
    leaseRenewalIntervalInSeconds: 10
    #Eureka服务器在接收到实例的最后一次发出的心跳后,需要等待多久才可以将此实例删除,默认为90秒
    leaseExpirationDurationInSeconds: 30

spring:
  application:
    name: client-user #此实例注册到eureka服务端的n

Note startup class notes Here Insert Picture DescriptionGoods, GOODS1 Here Insert Picture Description Here Insert Picture Description9. Access localhost: 3000 Here Insert Picture Descriptioncompletion

Guess you like

Origin www.cnblogs.com/joker-dj/p/12661474.html