关于 DNS 轮询
目前我们对四个 Web 服务器使用 DNS 轮询。
我们遇到的问题是:当用户刷新时,他可能会去其他Web服务器。 当用户已经登录时,这种感觉非常糟糕。因为我们使用会话来记住登录状态,但是当刷新到其他Web服务器时,会话会丢失。
所以最好的解决方案应该是让用户刷新时仍然在同一个Web服务器上。 有出路吗?
Currently we use DNS polling for four web servers.
The problem we met is that: When the user refreshes, he might go to other web servers. This feels very bad when a user has already logged in. Because we use a session to remember login status, but when refreshing to other web servers, the session is lost.
So the best solution should be to make the user still be on the same web server when he refreshes. Is there a way out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
好的,我相信你的意思是“循环 DNS”。 嗯,您所描述的是非常常见的问题并且没有“正确的”解决方案,因为可能的答案取决于许多变量:您是想提供自动故障转移还是只是负载平衡? 您愿意在负载均衡器上花费时间和/或金钱吗? 您使用什么技术? Java EE? PHP? 阿帕奇? IIS?
话虽如此,如果您只是在负载平衡和故障转移不是什么大问题之后,您可能需要为每个服务器使用不同的名称(www1、www2、www3 等)并从您的“主”网络重定向到它们首次访问时的服务器 (www)。 它很简单(而且简单化),但在某些情况下很实用。
Ok, I believe you mean "Round Robin DNS". Well, what you describe is a very common problem and there is no "right" solution for it, since the possible answers depend on many variables: are you trying to provide automatic failover or just load balancing? Are you willing to spend time and/or money in a load balancer? What technologies are you using? Java EE? PHP? Apache? IIS?
Having said that, if you're just after load balancing and failover is not much of an issue you may want to use different names for each server (www1,www2,www3 and so on) and redirect to them from your "main" web server (www) upon first access. It's simple (and simplistic) but practical in a few settings.
Web服务器可以使用通用的数据库服务器来存储会话信息吗?
Can the web servers use a common database server to store the session information?
我知道某些基于硬件的负载均衡器会在用户和服务器之间创建“粘性”关系,以避免此类问题。
I know that certain hardware based load balancers will create a "sticky" relationship between a user and a server to avoid this type of problem.
你有很多选择。
平衡源
。 请注意:如果节点数量发生变化,会话可能会丢失。 您可以使用cookie
或url_param
功能来避免这种情况。请参阅 HAProxy 文档。 确实值得一读。
You have quite a few options.
balance source
. Beware: if the number of node changes, the sessions can be lost. You can use thecookie
orurl_param
features to avoid this.See the HAProxy documentation. It's worth reading, really.
这四个 Web 服务器是否都位于同一站点和网络上,还是分布在同一站点和网络上?
如果是前者,您可以在 HTTP 响应中的某处包含服务器 ID,以便真实服务器前面的反向代理可以识别哪个服务器负责会话。
Are the four web servers all on the same site and network, or are they distributed?
If the former, you can include a server ID somewhere in the HTTP response, such that a reverse proxy in front of the real servers can identify which server is responsible for the session.
可以根据客户端位置进行响应的 DNS 服务器可以解决这个问题。 带有 geoip 模块的 PowerDNS 或 GeoIPdns 是一些示例。 您需要确保 IP 地址集不重叠,以便客户端始终得到相同的响应。
这本身不会提供任何类型的故障转移。
A DNS server that can respond based on the location of client could solve this problem. PowerDNS with the geoip module or GeoIPdns are some examples. You would need to make sure that the IP address sets were non-overlapping so a client always got the same response.
This would not provide any sort of fail over on its own.