关于 DNS 轮询

发布于 2024-07-19 13:02:36 字数 183 浏览 7 评论 0原文

目前我们对四个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

〆一缕阳光ご 2024-07-26 13:02:36

好的,我相信你的意思是“循环 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.

儭儭莪哋寶赑 2024-07-26 13:02:36

Web服务器可以使用通用的数据库服务器来存储会话信息吗?

Can the web servers use a common database server to store the session information?

我只土不豪 2024-07-26 13:02:36

我知道某些基于硬件的负载均衡器会在用户和服务器之间创建“粘性”关系,以避免此类问题。

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.

冷夜 2024-07-26 13:02:36

你有很多选择。

  • 您可以将会话存储在键:值存储中,fe memcached(我个人最喜欢的)
  • 您可以将会话存储在数据库中
  • 您可以将反向代理负载平衡器(例如DNS)和您的服务器放在后面。 然后将其设置为使来自相同 IP 的所有请求都转到相同的服务器,无论它们经过哪个负载均衡器。 在 HAProxy 中,此选项称为平衡源。 请注意:如果节点数量发生变化,会话可能会丢失。 您可以使用 cookieurl_param 功能来避免这种情况。

请参阅 HAProxy 文档。 确实值得一读。

You have quite a few options.

  • You can store sessions in a key:value storage, f.e. memcached (my personal favorite)
  • You can store sessions in a database
  • You can put reverse-proxy loadbalancers like in DNS and Your servers in the back. Then set it to make all requests from the same IPs go to the same servers, regardless of which loadbalancer they go through. In HAProxy this option is called balance source. Beware: if the number of node changes, the sessions can be lost. You can use the cookie or url_param features to avoid this.

See the HAProxy documentation. It's worth reading, really.

我不会写诗 2024-07-26 13:02:36

这四个 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.

恍梦境° 2024-07-26 13:02:36

可以根据客户端位置进行响应的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文