What is Eureka getting started with?
Eureka is a restful service for Netflix Open source, primarily for service registration and discovery.
It consists of Eureka Server and Eureka client.
Eureka server provides services such as registration, deletion, query, renewal and other functions, is the Service Management center.
Eureka Cliet is used to register services with the server, query services, invoke services, and so on.
3 characters in the Eureka
Eureka has three roles:
- Service Registy Services registry to provide registration and enquiry services
- Provider registration service and renewal service to the service registration form
- Consumer queries the service instance from the service registry to provider, and selects the instance for direct invocation.
Service Registy Services Registration Center
- How the data is stored. Can be kept in memory, local files, databases, etc.
- The Eureka is kept in memory.
- How to provide registration services. Http, RPC, and so on
- Eureka provides HTTP registration services
- How to provide query services.
- The service consumer queries the service registry for service provider information and caches it locally.
- Provider change, how to notify consumer. Adopt push way or pull way, real time or timing etc.
- Eureka with real-time push
- How information is synchronized and replicated between nodes of the service registry
- Simply put, the request is forwarded, and the following will unfold
- How to regain registration information when all service registry nodes are down and restarted. Reload from database, read from cache, or provider when Heartbeat is sent
- Eureka is re-saved when provider sends a heartbeat.
Service Provider Provider
- Send registration information to the service registry at startup: Service Registration
- Send cancellation message to service registry when closed: Service offline
- Keep your heartbeat so that the service registry can get the latest information about provider: Service renewal
Service Consumer Services Consumer
- Querying an instance of provider through the Service registry: Service acquisition
- Client Load Balancing: Ribbon
- Client cache: Local cache
Getting Started Demo sample
Online demo a lot, for reference only.
The simplest Springcloud tutorial in history | Second article: Service Consumers (Rest+ribbon)
Eureka Advanced Eureka How to manage services?
The essence of Service governance: Service additions and deletions to check.
Add: Register. There are services provided by the Orientation Service Registration Center registration.
Delete: Service cleanup. The service registry will periodically clear the failed service.
Change: None
Search: Service discovery, Access. The service consumer obtains the provider information from the Service Registration center.
Service Renewal: The service provider periodically sends a heartbeat to the service registry (which is sent by default of 30 seconds) and the service provider does not send a heartbeat to the service registry for more than a period of time (by default, 90 seconds), and the service registry sends the service offline.
Since the data is cached locally, the main thing is to manipulate the registry variable.
private final ConcurrentHashMap<String, Map<String, Lease<InstanceInfo>>> registry =new ConcurrentHashMap<String, Map<String, Lease<InstanceInfo>>>();
High Availability--cluster
How do I build a cluster?
Eureka server can also be a Eureka client, pointing to another Eureka server.
Eureka Sever A
spring: profiles: development_ha1 application: name: eureka-server-ha1eureka: server: enable-self-preservation: false #关闭自我保护,仅在开发环境中采用此配置。 eviction-interval-timer-in-ms: 3000 instance: prefer-ip-address: true lease-expiration-duration-in-seconds: 10 lease-renewal-interval-in-seconds: 3 client: registry-fetch-interval-seconds: 3 # 默认为30秒 serviceUrl: defaultZone: http://ziyun:[email protected]:10001/eureka/
Eureka Sever B
spring: profiles: development_ha2 application: name: eureka-server-ha2eureka: server: enable-self-preservation: false #关闭自我保护,仅在开发环境中采用此配置。 eviction-interval-timer-in-ms: 3000 instance: prefer-ip-address: true lease-expiration-duration-in-seconds: 10 lease-renewal-interval-in-seconds: 3 client: registry-fetch-interval-seconds: 3 # 默认为30秒 serviceUrl: defaultZone: http://ziyun:[email protected]:10001/eureka/
The key configuration is
client: serviceUrl: defaultZone: http://ziyun:[email protected]:10001/eureka/ client: serviceUrl: defaultZone: http://ziyun:[email protected]:10001/eureka/
How Peer replicates is the cluster synchronized?
Implementation method: Receives the service provider request Eureka Server, forwards the request again to the other Eureka server, invokes the same interface, passes in the same parameter, except will mark in the header isreplication= True, thus avoiding duplication of replicate.
How new Peer initializes node initialization
At startup, consider yourself as a service consumer customer and get the registration information (i.e., the access list) of all services from other peer Eureka (get Registry). It then iterates through the list of services, executes the register,isreplication=true on its own, and completes the initialization for each service.
Why isn't use HA proxy for load balancing?
- When it is not related to the session, you can use HA proxy;
- The elasticity and flexibility of Haproxy is not Eureka client high, because Eureka server may change dynamically.
Resilience elasticity
Eureka clients is built to handle the failure of one or more Eureka servers. Since Eureka clients has the registry cache information in them, they can operate reasonably well, even if all of the E Ureka servers go down. Eureka clients caches the data locally, and even if all Eureka servers are hung up, it will work.
Eureka Servers is resilient to other Eureka peers going down. Even during a network partition between the clients and servers, the servers has built-in resiliency to prevent a large s Cale outage.
Server can still work independently when other servers are hung or the network is interrupted
Non-java Services and clients
For services that are not in the Java language:
- Use this language to realize the function of the client
- Implemented by side car mechanism.
Why isn't use Curator/zookeeper as a service registry? (I have not used in Zookeeper, do not delve into this)
Official statement:
There is some overlaps in certain areas of what Zookeeper and Eureka provide especially in the areas of replicating Regis Try information. Eureka could use zookeeper to cache registry information and replicate the same, but replication was just a small part of W Hat Eureka provides.
Eureka deals with various other things apart from replication:
- REST end points that deal with registrations, renewals, expirations and cancels.
- Keeping the instance information up-to-date dealing with the intricacies of EIP binding, deployment rollbacks, autoscaling In a resilient manner.
- Being resilient to network outages between clients and servers and between peers.
Zookeeper ' s power comes to the fore with leader election, ordered updates, distributed synchronization along with its cons Istency guarantees (Quorums).
None of the above except the replication registry really applies to Eureka to justify a other dependency that we had to Deal with the following complications:
- You'll have to now find a by-assign eips to zookeeper similar to Eureka.
- Deal with failures when zookeeper fails.
and further more, Eureka have been built carefully without any hard dependency on any external components.
- Most services rely the Eureka to bootstrap themselves.
- To reduce the complexity.
- Avoid another failure point.
Another article also made a comparison: zookeeper to do the registration center defects.
The paper mainly presents three disadvantages:
- Zookeeper does not handle the network partitioning problem well, when the client node in the network partition fails to reach quorum, it loses contact with zookeeper and therefore cannot use its service discovery mechanism. (In zookeeper, if the number of nodes (nodes) in the same network partition (partition) does not reach zookeeper to select the "quorum" of leader nodes, they will be disconnected from zookeeper, Of course, service discovery is not available at the same time. )
- The service discovery system should be an AP system designed for usability, while zookeeper is a CP system.
- Zookeeper is very difficult to set up and maintain, and can be error-prone when it comes to operation, such as when the client rebuilds the watcher, handles the session and the exception.
Of course, Peter Kelley's question is not insurmountable, and does not mean that a service discovery system cannot be done based on zookeeper, but we may have more concise solutions such as Eureka.
Secure Identity Verification
Eureka Server Security Certification website link-old version
In the latest version of the Config in the client
If the client's Eureka.client.serviceUrl.defaultZone parameter value (that is, the address of the Eureka Server) contains the HTTP Basic authentication information, such as Http://user:[ Email protected]: 8761/eureka, then the client will automatically use the user name, password information and Eureka server to verify. If you need more complex validation logic, you must register a Discoveryclientoptionalargs component and inject the clientfilter component, The logic defined here is executed each time the client initiates a request to the server.
Server-side configuration:
security: user: name: ziyun password: dd2016 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId></dependency>
Client Configuration
http://user:[email protected]:EurekaPort/eureka/eureka: client: serviceUrl: defaultZone: http://ziyun:[email protected]:10001/eureka/
Note: passwords cannot be signed with special symbols !!!
FAQs and Solutions
- Eureka into the self-protection mode,
The following information is indicated: emergency! EUREKA may incorrectly claiming INSTANCES is up when the they ' RE not. Renewals is LESSER THAN THRESHOLD and HENCE the INSTANCES is not BEING EXPIRED JUST to be SAFE.
Solution:
1、 注册中心关闭自我保护机制,修改检查失效服务的时间。eureka: server: enable-self-preservation: false eviction-interval-timer-in-ms: 30002、 微服务修改减短服务心跳的时间。# 默认90秒lease-expiration-duration-in-seconds: 10# 默认30秒lease-renewal-interval-in-seconds: 3eureka: server: enable-self-preservation: false #关闭自我保护,仅在开发环境中采用此配置。 eviction-interval-timer-in-ms: 3000 续期时间,即扫描失效服务的间隔时间(缺省为60*1000ms) instance: prefer-ip-address: true lease-expiration-duration-in-seconds: 10 # 发呆时间,即服务续约到期时间(缺省为90s) lease-renewal-interval-in-seconds: 3 # 心跳时间,即服务续约间隔时间(缺省为30s) client: registry-fetch-interval-seconds: 3 # 默认为30秒
Cause: Eureka server During the run, will be counted whether the rate of heartbeat failure is less than 85% in 15 minutes, if there is less than the situation (when the single-machine debugging is easy to meet, the actual production environment is usually caused by network instability), Eureka Server will protect the current instance registration information and prompt for this warning. Protected mode is primarily used for protection in a network partition scenario between a group of clients and Eureka Server. Once in protected mode, Eureka server will attempt to secure the information in its service registry and no longer delete the data in the service registry (that is, it will not unregister any microservices).
How to handle service hangs or after manually shutting down the service, ribbon load balancer still calls the service, and then calls the @hystrixcommand circuit breaker annotation method: Using Hystrix, the error The callback method can shutdown the specified server
ZoneAwareLoadBalancer<Server> lb = (ZoneAwareLoadBalancer<Server>) springClientFactory.getLoadBalancer("CLOUD-SERVICE");Server server = lb.chooseServer();System.out.println("error->" + server.getHostPort());lb.markServerDown(server);
In addition, you can configure the Ribbon request retry in CAMDEN.SR3, you can refer to DD great God's new works: Configure Request retry for Spring Cloud Ribbon (camden.sr2+)
Change the health detection method for services registered in Eureka Server
The default heartbeat implementation is an effective way to check that the Eureka client process is functioning properly, but there is no guarantee that the client application will serve properly.
Since most microservices applications will have some other external resource dependencies, such as databases, Redis caches, and so on, if our application is unable to communicate with these external resources, it is not actually able to provide normal external services, but because the client heartbeat is still running, it will still be called by the service consumer, Such calls do not actually have the desired consequences.
We can change the way Eureka Server eureka.client.healthcheck.enabled=true the client health by configuring it in the Eureka client, instead of the actuator/ Health endpoint to detect.
Change the health detection method for services registered in Eureka Server
Spring Cloud Practical tips: Health Check
Alternative Technologies
Springcloud provides 3 service discovery components: Eureka/consul/zookeeper. In the PPT of the public springcloud practice of worship, the consul is adopted.
Reference documents
- Official Wiki
- Spring Cloud Netflix
- Spring Cloud Brochure (most complete here)
- Depth profiling service Discovery component Netflix Eureka
- Overview of micro-Service registration discovery
- Using Eureka to do service discovery (i)
- Eureka Service Registration and Discovery
- The simplest Springcloud tutorial in history | Second article: Service Consumers (Rest+ribbon)
- Deep understanding of Eureka Source Parsing
Springcloud Practice (i) Service discovery: Eureka