spring-cloud / spring-cloud-netflix

Integration with Netflix OSS components
http://cloud.spring.io/spring-cloud-netflix/
Apache License 2.0
4.86k stars 2.44k forks source link

Document working with multiple zones in eureka #1327

Closed liangchouzhou closed 7 years ago

liangchouzhou commented 8 years ago

i google and read the doc and can't find some detailed description or example for config eureka server & client in multiple zones.

in cloud env, there are 2 zones in 1 region. i want to deploy eureka server1 in zone1, eureka server2 in zone2.

Service deployed in zone1, registered in eureka server1. service deployed in zone2, registered in eureka server2.

for request route to zone1, prefer to route to service in zone1; and route to service in zone2 in case of service in zone1 is down for request route to zone2, prefer to route to service in zone2; and route to service in zone1 in case of service in zone2 is down.

how to config the eureka server and client? Thanks.

ryanjbaxter commented 8 years ago

Having the services register with the correct Eureka Server for their zone is just a matter of setting the URL to the Eureka server in eureka.client.serviceUrl.defaultZone.

To enable the case where a request to route to a service in another zone when the service in its zone is unavailable you need to make sure the Eureka servers in all zones are set up as peers of each other. More information on that can be found in #1251.

To specify zone information you have two options.

  1. If the hostnames of the services will be different in each zone you can set ribbon.eureka.approximateZoneFromHostname to true and zone information for a service will be calculated based on the host name. (assuming you are using ribbon)
  2. You can specify the zone for a service by setting eureka.instance.metadataMap.zone.
liangchouzhou commented 8 years ago

@ryanjbaxter my eureka server and client config as below, eureka server 1 and server 2 replicated each other. eureka client in service or api-gateway (zuul), register for server 1 and server2.

eureka server1 config

eureka:
  instance:
    hostname: 10.8.0.1
  client:
    serviceUrl:
      defaultZone: http://10.8.0.2:8761/eureka/
  server:
    enable-self-preservation: false

eureka server2 config eureka:

  instance:
    hostname: 10.8.0.2
  client:
    serviceUrl:
      defaultZone: http://10.8.0.1:8761/eureka/
  server:
    enable-self-preservation: false

eureka client config (zone1 service)

eureka:
  client:
    serviceUrl:
      defaultZone: http://10.8.0.1:8761/eureka/, http://10.8.0.2:8761/eureka/
  instance:
    preferIpAddress: false

eureka client config (zone1 api gateway: zuul)

eureka:
  client:
    serviceUrl:
      defaultZone: http://10.8.0.1:8761/eureka/, http://10.8.0.2:8761/eureka/
  instance:
    preferIpAddress: false

how to config eureka server1 to zone1 and eureka server 2 to zone2?

at zuul, i config 2 URLs in serviceUrl.defaultZone, the 1st one is zone1 eureka server, the 2nd one is zone2 eureka server. if this config is enough when zone1 service is unavailable, the request is routed to zone2 service?

at zuul / service, how to config to route the request to service the same zone?

2. You can specify the zone for a service by setting eureka.instance.metadataMap.zone. this way? eureka client config (zone1 service)

eureka:
  client:
    serviceUrl:
      defaultZone: http://10.8.0.1:8761/eureka/, http://10.8.0.2:8761/eureka/
  instance:
    preferIpAddress: false
    metadataMap:
       zone: zone1

btw, how to config region info for eureka and config 2 zones under this region?

Thanks.

ryanjbaxter commented 8 years ago

In your Eureka Clients you should set defaultZone to the URL of the Eureka server in the same zone. So for example if Eureka server 1 is in zone 1 and Eureka server 2 is in zone 2, your client deployed to zone 1 would look like

eureka:
  client:
    serviceUrl:
      defaultZone: http://10.8.0.1:8761/eureka/
  instance:
    preferIpAddress: false
    metadataMap:
       zone: zone1

And you client deployed to zone 2 would look like

eureka:
  client:
    serviceUrl:
      defaultZone: http://10.8.0.2:8761/eureka/
  instance:
    preferIpAddress: false
    metadataMap:
       zone: zone2

Since the two Eureka servers are set to be peers of each other they will replicate service information with each other.

On the clients when a request is made to a service we will use the zone information obtained from Eureka about the various services to determine which service to try first.

liangchouzhou commented 8 years ago

thanks, @ryanjbaxter

i try the following config and it works:

eureka server config is just as above and the eureka client config in service is below:

service1 in zone1

eureka:
  instance:
    preferIpAddress: false
    metadataMap:
      zone: zone1
  client:
    serviceUrl:
      defaultZone: http://10.8.0.1:8761/eureka/, http://10.8.0.2:8761/eureka/
    preferSameZoneEureka: true

zuul1 in zone1

eureka:
  instance:
    preferIpAddress: false
    metadataMap:
      zone: zone1
  client:
    serviceUrl:
      defaultZone: http://10.8.0.1:8761/eureka/, http://10.8.0.2:8761/eureka/
    preferSameZoneEureka: true

then zuul1 will route request to services in zone1 first and if services in zone1 is down, will route request to services in zone2.

spencergibb commented 8 years ago

To document

ryanjbaxter commented 8 years ago

@liangchouzhou I am working on updating the documentation and after going back and looking at the configuration you said worked, I am wondering why in your Eureka clients you are setting the defaultZone property to point at both Eureka servers? Shouldn't you only need to point at the Eureka server in the same zone and let the peer replication functionality between the servers replicate the data to the other Eureka servers in the other zones?

ryanjbaxter commented 7 years ago

ping @liangchouzhou ^^^

ryanjbaxter commented 7 years ago

Closing due to lack of activity. Please provide feedback and reopen.

SeanWan1989 commented 7 years ago

@ryanjbaxter Beause if Eureka server in the same zone was shut down, if your client set only one serviceurl, the client can't look for a stand by server.so you should set one more below: defaultZone: http://10.8.0.1:8761/eureka/, http://10.8.0.2:8761/eureka/

ryanjbaxter commented 7 years ago

@SeanWan1989 would doing this cause the Eureka client to register with both Eureka servers or does it just try the first one in the list?

SeanWan1989 commented 7 years ago

@ryanjbaxter client will just try the first one in the list, if the first one was shut down, the client will auto register with the next one.

yaoyuanyy commented 7 years ago

@liangchouzhou can you write out your config eureka server and eureka client i do not understand prettily contents which your had talked about 'service1 in zone1' and 'zuul1 in zone1'

yaoyuanyy commented 7 years ago

@ryanjbaxter ask for you about the core concept of zone. btw,what is different between zone and region?

eacdy commented 7 years ago

@yaoyuanyy Each of region and zone is concept of AWS, you can follow this URL to learn about what it is. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html You can also follow this issue I raised: https://github.com/Netflix/eureka/issues/881 Moreover, If you are a Chinese, you can try this post: http://blog.csdn.net/awschina/article/details/17639191 .

yaoyuanyy commented 7 years ago

@eacdy lucky because of your help, i will study from it. but now the question:'config eureka server & client in multiple zones'. i can not work it @liangchouzhou @ryanjbaxter

yaoyuanyy commented 7 years ago

@eacdy Firstly thank you very much. you are right, i am a chinese who has been a high interesting with spring-cloud. But i am a beginner for spring-cloud. thanks again

eacdy commented 7 years ago

@yaoyuanyy My Honor. My open source book may help you get started.https://github.com/eacdy/spring-cloud-book. B.T.W, 我为啥要说英文?

yaoyuanyy commented 7 years ago

@eacdy Knowledge is belong to all over the world. 感谢周立同学的分享,太棒了,马上拜读,在这里我学到了很多。Thanks everyone

jprateekvmware commented 6 years ago

I am trying to get this worked with client able to discover them within the same zone and hop over in case they are not available in thier current zone. I have set up all the properties as mentioened and its going to below place for resolution of the eureka service name and zone is not getting used. I am on latest edgware release com.netflix.discovery.DiscoveryClient public List getInstancesByVipAddress

ryanjbaxter commented 6 years ago

@jprateekvmware please open a separate issue with a more detailed description on the problem. In this case your configuration would be particularly useful.

piyushkumar13 commented 6 years ago

Referring to @liangchouzhou comment https://github.com/spring-cloud/spring-cloud-netflix/issues/1327#issuecomment-245800603 and @SeanWan1989 comment https://github.com/spring-cloud/spring-cloud-netflix/issues/1327#issuecomment-262137314 . I had the similar usecase where I have to use the list of defaultZone and these comments were helpful for me. But unfortunately, I didn't find any Spring Cloud doc around it. @ryanjbaxter is it documented ?

ryanjbaxter commented 6 years ago

If you dont see it in our current docs (http://cloud.spring.io/spring-cloud-static/Finchley.SR1) than no. We always welcome PRs to enhance our docs.