负载平衡服务器,我该如何实施? [英] Load balancing server, how can I implement it?

查看:79
本文介绍了负载平衡服务器,我该如何实施?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google上搜索了负载平衡,但我唯一能找到的就是工作原理,目前,这对我来说是轻松"的部分.但是有零个示例说明了如何实现一个.

I googled for load balancing but the only thing I can find is the working theory, which at the moment, is the "easy" part for me. But zero examples of how to implement one.

我有几个有关负载平衡的问题:

I have several questions pertaining load balancing:

  1. 我有一个域(example.com),在它的后面我有一个负载平衡服务器(简称为 A ),根据理论,该服务器将要求客户端执行以下操作:关闭与A的连接,然后连接至子服务器B,并与B进行请求.客户端在网络浏览器中是否会停止在地址栏中看到"example.com/page.html",而开始看到"B_ip_address/page.html"代替?

  1. I have a domain (example.com) and I behind it I have a load balancing server (lets call it A) which, according to the theory, will ask the client to close the connection with A, and connect to B, a sub-server and carry on the request with B. Will the client, in a web browser stop seeing "example.com/page.html" in the address bar and start seeing "B_ip_address/page.html" instead?

如何从头开始实现简单的负载均衡器?我的怀疑是针对HTTP部分.我需要发送一些特定的消息或一组消息来发送客户端,这会使他与我断开连接并连接到子服务器吗?

How can I implement a simple load balancer from scratch? My doubt targets the HTTP part. Is there some specific message or set of messages I need to send the client which will make him disconnect from me and connect to a sub-server?

比HTTP更低的协议(例如TCP/IP)怎么样?是否有任何标准数据包告诉客户端他刚刚连接到负载均衡器服务器,现在他需要连接到xxx.xxx.xxx. xxx进行请求?

What about lower level protocols than HTTP, such as TCP/IP, are there any standard packets to tell the client he just connected to a load balancer server and now he needs to connect to xxx.xxx.xxx.xxx to carry on the request?

最常用的方法是什么? (1)客户端连接到负载平衡服务器,并要求客户端直接连接到其中一个子服务器,或者(2)负载平衡服务器开始桥接所有从客户端到子服务器的流量,反之亦然以透明的方式?

What method is the most used? (1) client connects to load balancing server, and it asks the client to directly connect to one of the sub-servers, or (2) the load balancing server starts bridging all traffic from the client to the sub-server and vice-versa in a transparent fashion?

问题2,问题3和问题4是关于负载平衡协议的,第一个是将域名连接到负载平衡器的方式以及潜在的后果.

So question 2, 3 and 4 regard the load balancing protocol, and the 1st one the way a domain name can be connected to a load balancer and what are the underlying consequences.

推荐答案

您的方法是通过将调用重定向到另一台服务器来实现的一种静态负载平衡.接下来的所有调用都可能使用该其他服务器,或者再次发送到负载平衡器以进行重定向.

Your approach is a kind of static load balancing by redirect the calls to another server. All following calls may use this other server or are send to the load balancer again for redirect.

实现取决于系统的实现.负载平衡器最适合没有会话状态的独立请求.您需要在终端"服务器之间同步会话状态.或使用共享的会话存储为所有服务器提供会话状态.

An implementation depends on the implementation of your system. A load balancer works best for independent requests with no session state. You need to sync the session state otherwise between the "end" servers. Or use a shared session store to provide the session state to all servers.

存在一个简单透明的HTTP服务器负载平衡解决方案.您可以使用Nginx服务器的负载平衡模块( http://nginx.org/en /docs/http/load_balancing.html ).可以用于HTTP和HTTPS请求.如果负载增加,它可以动态地通过额外的服务器进行扩展.您需要编辑nginx配置并重新启动服务器.这对于现有连接可以是透明的.而且nginx不会导致更改域名或主机名的问题.

There exists a simple and transparent solution for HTTP server load balancing. You can use the load balancing module of an nginx server (http://nginx.org/en/docs/http/load_balancing.html). This can be used for HTTP and HTTPS requests. And it may be extended with extra servers dynamically if the load increases. You need to edit the nginx configuration and restart the server. This can be transparent to existing connections. And nginx does not cause problems with changing domain or host names.

其他协议需要客户端和服务器提供一些支持.如果在客户端和服务器之间存在专用设备,则负载平衡可能是透明的.或者通信协议需要支持连接重定向.

Other protocols need some support by the client and the server. Load balancing may be transparent if a specialized device is between the client and server. Or the communication protocol needs to support connection redirects.

负载均衡也可以通过DNS循环实现.每个DNS查找调用都会返回相同域名的另一个IP地址.客户端选择一个IP并连接到该服务器.另一个客户端可以使用下一个IP.地址栏名称始终都是相同的.

Load balancing can be implemented by DNS round robin too. Each DNS lookup call returns another IP address for the same domain name. The client choose an IP and connects to this server. Another client can use the next IP. The address bar name is the same all the time.

示例:

Non-authoritative answer:
Name:    www.google.com
Addresses:  2a00:1450:4001:80f::1010
      173.194.116.209
      173.194.116.210
      173.194.116.212
      173.194.116.211
      173.194.116.208

Non-authoritative answer:
Name:    www.google.com
Addresses:  2a00:1450:4001:80f::1010
      173.194.116.210
      173.194.116.212
      173.194.116.211
      173.194.116.208
      173.194.116.209

Non-authoritative answer:
Name:    www.google.com
Addresses:  2a00:1450:4001:80f::1010
      173.194.116.212
      173.194.116.211
      173.194.116.208
      173.194.116.209
      173.194.116.210

IP地址范围旋转.大多数HTTP负载平衡器都像nginx或其他反向代理实现一样,充当透明的负载平衡器.我认为重定向负载均衡器是一种技术含量较低的实施方式.

The IP address range rotates. Most HTTP load balancers work as transparent load balancer like nginx or other reverse proxy implementations. A redirecting load balancer is more a low tech implementation I think.

TCP/IP不是协议.它是用于传输实现特定通信协议的数据的传输层. TCP/IP本身是网络组件的协议.但不是应用程序.您可以检查 https://en.wikipedia.org/wiki/OSI_model .

TCP/IP is not a protocol. It's the transport layer used to transfer data implementing a specific communication protocol. While TCP/IP itself is a protocol for the network components. But not the applications. You may check https://en.wikipedia.org/wiki/OSI_model .

这篇关于负载平衡服务器,我该如何实施?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆