Springcloud (a) on Springcloud

Source: Internet
Author: User
Tags log log docker compose logstash haproxy redis cluster

Objective

Now micro-service is really too hot, so we are essential is to learn springcloud, service is the core of the traditional one-stop application
Split into one service based on the business, while microservices are more thoroughly decoupled on this basis (no longer share db, KV, remove the heavyweight ESB), and
and emphasis on devops and rapid evolution.

Components commonly used in Springcloud:

    • Service Discovery--netflix Eureka
    • Client Load Balancing--netflix Ribbon
    • Circuit Breaker--netflix Hystrix
    • Service Gateway--netflix Zuul
    • Distributed Configuration--spring Cloud Config
First, Springcloud architecture design 1.1 Springcloud frame composition Fine Solution


The architecture diagram of the above Spirngcloud, a hierarchical overview.

  • Web server selection, this I choose is Nginx+keepalived,haproxy is also an option, but haproxy in reverse proxy processing cross-domain
    There are a lot of problems when visiting. So we have some places in Nginx to do the keep-alive mode processing, reduce the number of three times handshake, improve the connection efficiency.
    keepalived do nginx load, virtual a VIP external, two nginx do high availability, Nginx itself reverse proxy zuul cluster.

  • API Gateway, here Zuul many people criticized, said is slow recommended directly with Nginx, here I still recommend the use of Zuul, after all, Zuul contains
    Interceptors and reverse proxies are useful when it comes to rights management, single sign-on, user authentication, and Zuul comes with ribbon load balancing, if you directly use
    Nginx, also need to do a separate feign or ribbon layer, used to do business cluster load layer, after all, directly exposing the interface to the Web server is too dangerous.
    Here Zuul with ribbon load balancer and Hystrix circuit breaker, the direct reverse proxy Serviceid can proxy the entire cluster.

  • Business cluster, this layer I have a number of projects are divided into two tiers, that is, the above added a load layer, the following is starting from the service, the bottom is just a simple interface,
    Controller is a separate layer implemented by feign, and then the internal different service interface Intermodulation, directly call controller layer, can only say that the effect of general, more
    A TCP connection. So I recommend merging, because the Spring cloud project knows that feign contains the ribbon, and Zuul also contains
    Ribbon, so that the Zuul call service cluster, and the service cluster interface between the intermodulation is highly available, to ensure the stability of the communication. Hystrix still have to have
    , it is difficult to achieve service demotion without a circuit breaker, and a large number of requests are sent to unavailable nodes. Of course the service can be retrofitted if it is modified into RPC side
    , that the service between the intermodulation is another situation, it will be done in the form of load pool and interface service pool, the load pool call interface pool, interface pool Mutual RPC
    Call, feign client just realizes the form of RPC by implementing interface, but the speed performance is still good.

  • Redis Cache pool, this is used to do session sharing, distributed system session sharing is a big problem. At the same time, Redis does a level two cache to reduce the overall
    The response time of the service, and it is helpful to reduce the number of accesses to the database. Of course Redis cluster is also the Redis Sentinel's choice.

  • Eureak Registration Center This high-availability cluster, where there are many details, such as how often to refresh the list once, how long to monitor the heartbeat and so on, is very important.

  • Spring Admin, this is very recommended, this feature is very powerful, can integrate the turbine circuit breaker monitor, and can define all classes of the log level,
    You can also view the local log log files, monitor the machine parameters and performance of different services, and be very powerful without having to configure them individually. It plus Elk Dynamic Log collection system
    It is very convenient for project operation and maintenance.

  • Zipkin, which is available in two ways, is collected directly from the Elk Dynamic log system using its own functional interface or stream. But
    I have to say that this damage to the performance of the system is very large, because the link tracking will cause the response to wait, and the wait time is very long close to 1 seconds, which in
    Production environment is unbearable, so the production environment is best off, there are problems when debugging and then open.

  • Message Queuing, this must, distributed system is not possible to meet strong consistency in all scenarios, this can only be buffered by Message Queuing, here I use
    Kafka.

  • Distributed things, I think this is the most difficult to distribute, because the different business clusters are corresponding to their own database, the database is not interoperability, mutual service
    Service calls can only be mutual interface, some even offsite, so the result is the network delay caused by the request waiting, network jitter caused by data loss,
    These are very scary issues, so you have to deal with distributed things. I recommend using Message Queuing to take a two-phase commit protocol with the thing compensation mechanism,
    The specific implementation needs to be combined with the business, where space is limited to say no.

  • Config configuration center, which is very necessary because the service too many profiles too much, no this is difficult to Operation dimension. This generally uses Message Queuing to create a
    Spring Cloud Bus, which stores configuration files by git, dynamically updates profile information with bus buses.

  • Real-time distributed log system, Logstash collect local log file stream, transfer to Elasticsearch,logstash there are two ways, 1, is each
    The machine starts a Logstash service, reads the local log file, and generates a stream to Elasticsearch. 2, Logback introduced Logstash bag, and then straight
    The production JSON is circulated to a central Logstash server, which is then passed to Elasticsearch. Elasticsearch again will be circulated to Kibana, dynamic check
    Look at the log, even the Zipkin stream can be passed directly to Elasticsearch. This works with Spring admin, a view dynamic log, a view local
    Logs, and the ability to remotely manage log levels of non-homogeneous logs is beneficial for integration and operations.

1.2 of two summaries
    • Many things in spring cloud are more accurate, such as breaker trigger time, things compensation time, HTTP response time, and so on, all of which require good design,
      And the number of points that can be optimized is very great. For example: HTTP communication can use OKHTTP,JVM optimization, NIO mode, data connection pool and so on, can greatly improve
      Performance.

    • Docker problem, many people say that without Docker is not a micro service. In fact, my personal opinion, Spring Cloud itself is microservices, only need the JDK environment
      Can. Writing dockerfile is nothing more than integrating a JDK, adding a jar package, executing a jar, or using Docker compose to convert the image of several different services
      Combine run into a container. But there are a lot of problems, such as communication problems, server performance loss problems, container process crashes, of course, if you have a
      Cooked k8s-based container management platform, this is no problem, if not possible to consider. And spring cloud itself is a microservices distributed architecture
      , so the individual is recommended for direct machine deployment, and of course good devops tools will be much easier.

Second, Springcloud common components introduced 2.1 Eureka

A restful service that locates middle-tier services running in the AWS region. Consists of two components: the Eureka server and the Eureka client.
The Eureka server serves as the service registration server. The Eureka client is a Java client that simplifies interaction with the server, acts as a polling load balancer, and
Provides failover support for the service. Netflix uses additional clients in its production environment, which provides data based on traffic, resource utilization, and error status.
Weighted load balancing.

2.2 Ribbon

The Ribbon, a remote procedure call, contains a software load balancing algorithm.

The Ribbon client component provides a complete set of configuration options, such as connection timeouts, retries, retry algorithms, and so on. The ribbon incorporates pluggable, customizable load balancing components.
Here are some of the load balancing strategies that are used:

    • Simple Poll Load Balancing
    • Weighted response Time Load balancing
    • Zone-aware polling load balancing
    • Random Load Balancing

The Ribbon also includes the following features:

    • Easy integration with service discovery components like Netflix's Eureka
    • Using Archaius to complete runtime configuration
    • Use JMX to expose operational metrics and publish using servo
    • Multi-pluggable serialization options
    • Asynchronous and batch Operations
    • Automatic SLA Framework
    • System Management/Indicators console
2.3 Hystrix


A circuit breaker can prevent an application from trying to perform an operation multiple times, which is likely to fail, allowing it to continue without waiting for a recovery or wasting CPU cycles, and it
Make sure that the fault is persistent. The circuit breaker mode also enables the application to detect if a failure has been resolved. If the problem seems to have been corrected??, the application can try to tune
With the operation.

The circuit breaker adds stability and flexibility to a system that provides stability while the system recovers from the failure and minimizes the performance impact of this failure. It can help
Quickly rejects a request for an operation that is likely to fail rather than wait for the operation to time out (or not return) to maintain the system's response time. If the circuit breaker improves
Each time the event changes state, the information can be used to monitor the health status of the parts of the system protected by the circuit breaker, or to alert the administrator when the circuit breaker trips to the
Open state.

Flow chart:

2.4 Zuul


Similar to Nginx, the function of reverse proxy, but Netflix itself added some features to cooperate with other components.

2.5 Spring Cloud Config


When a configuration file in a system changes, we need to restart the service in order for the new configuration file to take effect, and Spring cloud Config can actually
The unified management of all the system's configuration files in the micro-service, but also can realize when the configuration file changes, the system will automatically update to get the new configuration

Springcloud (a) on Springcloud

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.