What exactly are clusters and microservices?

The system framework is divided into the following categories:

1. Stand-alone architecture

This kind of architecture is very common. For example, there is a very small system that does not need to deal with a lot of things. It only needs a server, build the services you need on it, and you can start working.

The advantages of this architecture are obvious, easy to maintain, and easy to solve when problems occur.

The disadvantage is also obvious. If the processing increases, the resources will not be enough.

 

2. Cluster Architecture

The single-machine architecture cannot meet the requirements, and the clustered architecture can provide better and faster processing. Simply put, the clustered architecture is to extract the services running on the single-machine architecture, copy them, and deploy them on multiple servers, which can improve the work efficiency. In a cluster, each server is called a node, and each node provides different services, such as Database, Web, and logging tools.

After the cluster is built, there is such a role, which is responsible for scheduling which server the request from the client goes to, and then carries out the next workflow. This role is called "load balancer".

Clusters are also divided into high-availability clusters and load-balancing clusters (maybe the high-concurrency architecture is an upgraded version of the load-balancing architecture).

Common high-availability cluster tools are: heartbeat, pacemaker, keepalived

Common load balancer tools are: nginx, lvs, HAproxy

Advantages of cluster architecture: scalability, if server resources are not enough, you can add one to continue work

Disadvantages: difficult to maintain, it takes more time to trouble shoot

 

3. Microservice Architecture

Let's summarize the previous knowledge points first. From the stand-alone structure to the cluster structure, your code basically does not need to be modified. All you have to do is deploy a few more servers, and there are not too many servers running the same code. However, when you want to evolve from a cluster structure to a microservice structure, the previous set of code needs to undergo major changes. Therefore, for the new system, we recommend that the microservice architecture be adopted at the beginning of the system design, so that the cost of later operation and maintenance is lower. But if an old system needs to be upgraded to a microservice structure, it will take a lot of work on the code. Therefore, for the old system, whether to continue to maintain the cluster mode or upgrade to a microservice architecture requires your architects to carefully consider and weigh the input-output ratio.

Let's start with the introduction of so-called microservices. Microservice is to split a complete system into independent subsystems according to business functions. In the microservice structure, each subsystem is called a "service". These subsystems can run independently in the web container, and communicate with each other through RPC .

 

What is RPC communication?

Here is a brief introduction. If you want to know more about RPC, please Google it yourself.

  RPC (Remote Procedure Call Procotol) remote procedure call protocol, the popular explanation is: the client calls an object existing on the remote computer without knowing the details of the call, just like calling the object in the local application. Alibaba's Dubbo framework is a better framework for using the RPC protocol

 

For example, suppose you need to develop an online store. According to the idea of ​​microservices, we need to split into multiple independent services according to functional modules, such as: user services, product services, order services, background management services, data analysis services, and so on. Each of these services are independent projects that can run independently. If there is a dependency between services, call it by RPC.

The benefits of this are many:

  1. The degree of coupling between systems is greatly reduced, independent development, independent deployment, and independent testing are possible. The boundaries between systems are very clear, troubleshooting becomes quite easy, and development efficiency is greatly improved.
  2. Coupling between systems is reduced, making the system easier to expand. We can expand certain services in a targeted manner. Assuming that this mall is going to hold a big promotion, the number of orders may be greatly increased. Therefore, we can increase the number of nodes in the order system and product system in a targeted manner. For the background management system and data analysis system, the number of nodes remains the original. level.
  3. Services are more reusable. For example, when we use the user system as a separate service, all the products of the company can use the system as the user system without repeated development.

Then the problem comes. When the microservice structure is adopted, a complete system may be composed of many independent subsystems. When the business volume gradually develops, the relationship between these subsystems will be intricate, and in order to be able to target To increase the processing power of some services, there may be a cluster mode behind some services, which is composed of multiple nodes, which undoubtedly greatly increases the difficulty of operation and maintenance. The idea of ​​microservices is good, but the complexity of development and operation and maintenance is too high. In order to solve these problems, Alibaba's Dubbo was born.

4、Dubbo

Dubbo is the coordinator of a micro-service system. In its system, there are three roles: service provider (hereinafter referred to as provider), service consumer (hereinafter referred to as consumer), and registration center.

When you use it, you need to introduce Dubbo's jar package into your project, that is, each service must introduce Dubbo's jar package. Then when these services are initialized, Dubbo will send the services that the current system needs to publish, as well as the IP and port numbers of the current system to the registration center, and the registration center will record them. This is the process of service publishing. At the same time, when the system is initialized, Dubbo will also scan the services that the current system needs to reference, and then request the IP and port numbers of these services from the registration center. Then the system can run normally. When system A needs to call the service of system B, A will establish an RPC channel with B, and then call the corresponding service on system B.

This is what Dubbo does.

5, specific department

When we use the microservice architecture, we split an originally complete system into subsystems that can run independently according to business logic. In order to reduce the coupling between systems, we hope that these subsystems can run in independent environments, and these environments can be isolated from each other.

Before the emergence of Docker, if a virtual machine is used to isolate the running environment from each other, the cost is high, and the virtual machine consumes more computer hardware/software resources. Docker can not only realize the isolation of the operating environment, but also save computer resources to a great extent, and it has become a lightweight "virtual machine".

What exactly is docker or how to use it, I won't explain it here, just search it by yourself.

When we use the microservice architecture, with the gradual development of the business, the dependencies between the systems will become increasingly complex, and the order in which each module is constructed is particular. For a small system, maybe only a few modules, then you may not feel troublesome every time you build it with human flesh. However, with the development of the system business, the dependencies between your systems are becoming more and more complex, and the number of subsystems is gradually increasing. You have to be very careful every time you build it. If you are not careful, the entire service will not be able to start normally. Moreover, the work of these constructions is very low, but it requires a lot of energy, which undoubtedly reduces the efficiency of development. But that's okay, Jenkins is here to help you with that.

We only need to configure the code repository, the build order of each module and the build command in Jenkins. In future builds, just click the "Build Now" button, and Jenkins will automatically pull the latest code from your code repository. , and then build it according to the build command you configured in advance, and finally publish it to the specified container to run. You can also have Jenkins periodically check the repository version for changes, automatically start the build process once it finds changes, and have Jenkins send you an email when the build is successful. This way, you don't even have to press the "build now" button, and all of this build process is fully automated.

 

The above is my basic understanding of clusters and microservices. If there is an error, please contact qq787871867 to avoid misunderstanding. . . . .

Osssss

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325424787&siteId=291194637