A short story to explain the implementation of load balancing technology: from tomcat to Nginx

What is load balancing? In layman's terms, it is a technology to decompress the server in a high concurrency and big data environment.

Load balancing is a problem that any Internet company of a certain scale will consider. There are many load methods, some rely on hardware to achieve load, and some rely on software to achieve load.

Today, let's talk about the way to use software to load.

You may have heard of their respective load methods. For example, common technical frameworks such as nginx, dubbo, springcloud, etc. can achieve load. As a software master, have you considered the difference between these load methods?

Let Xiaoyuan come to an imaginary case to talk about commonly used loads, I think it will be helpful to you.

[The following stories are purely fictitious, please do not take the right seat. If you want to learn Linux-related configuration and more load knowledge, please join the group 523916260]

 

from a tomcat

 

A long time ago, Xiaoyuan set up his own company and made a shopping website - "Xiaoyuan Shopping Network". At the beginning, the structure was very simple, the traditional java development framework, a tomcat container, after a month of no day No night coding, get it, go online.

One year later, the project was unexpectedly popular, and a large number of people came to buy dolls, clothes, cups, etc. every day. Suddenly found a tomcat can not handle, what should I do? Two tomcats!

So here comes the problem, two tomcats are no problem, and there are several servers, but I only have one domain name, what should I do?

 

Nginx debuts

 

Nginx is on the stage. Through the ups and downs of a stick of programmers, the introduction of nginx into the project can solve the concurrency problem. The research process is not simple, how to share sessions, how to configure configuration files, etc. In any case, at least the task is completed, and the two tomcats can work together.

However, the online mall is getting more and more popular. After two months, I found that two tomcats can't be done. What should I do? Only more tomcats can be integrated. Of course, it is no problem for Nginx to integrate many tomcats. The architecture diagram is as follows:

but……

Adding tomcat Xiaoyuan has to modify the configuration file nginx.conf. Of course, after modifying the configuration problem, I can reload and make nginx take effect, but there are often problems with reload, and I have to restart frequently.

Restarting will be a big trouble. My service must not be stopped. Customers are shopping well, but suddenly they find that they can't place orders or pay. Isn't this very bad?

In fact, it is not bad. Although the customer friendliness is not good, Xiaoyuan usually works overtime at 3 am to maintain it. Fortunately, it is hard work, but it is barely acceptable.

until one day……

 

nightmare day

 

Xiaoyuan was taking a nap that day, 3 volts, the sun was shining high, and there was a bang in his sleep, the electricity didn't stop, but the nginx server was already smoking.

How to do? The nginx server must have been reimbursed that day. It didn't take long for the customer's complaint calls to come endlessly, and it was just 10 minutes later...

I can only build a new server. Fortunately, the server still exists, but I forgot to back up the configuration files. It took me an hour to complete the server in a hurry, and it was still very proficient in nginx configuration files.

Although the problem was solved, Xiaoyuan was still scolded by the investment manager that day, he lost a lot of money in an hour, and the complaints from customers were still piled up.

What if this happens again in the future? I must remember to back up the configuration files, but it is unacceptable for nginx to crash again.

finally……

 

Nginx+keepalived is online

 

One nginx cluster is definitely not enough, then I have to use two nginx clusters. One nginx is smoking, and the other nignx is waiting to be replaced immediately. Wouldn't it be better?

Well, then the overall architecture diagram is as follows.

Finally, such an architecture solves a big problem.

But there is also a problem with this structure. As for what is the problem?

What does Dubbo, spring cloud, and zookeeper have to do with load?

Please listen to the next breakdown~

Guess you like

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