如何实现分布式文件上传解决方案?

发布于 2024-12-20 15:12:37 字数 675 浏览 2 评论 0原文

我有一个文件上传网站,目前位于单个服务器上,即使用同一服务器供用户上传文件,并使用同一服务器进行内容交付。

我想要实现的是 CDN(内容交付网络)。我想购买一个服务器场,如果我有一种机制将文件分布在不同的服务器上,那将更好地平衡我的负载。

但是,我对此有几个问题:

假设我的服务器场由 10 台用于内容交付的服务器组成,

  1. 由于在用户端,上传文件的脚本将只有一个位置,即

    ,它必须驻留在单个服务器上,对吗?如何将脚本复制到多台服务器上,并将用户的文件上传数据定向到负载最小的服务器上?

  2. 我应该如何确定将哪些文件发送到哪个服务器?在上传过程中,我应该随机化所有文件以发送到随机服务器吗?如果用户发送 10 个文件,我应该将它们发送到随机服务器吗?是否有一种机制可以将它们发送到负载最小的服务器?是否有其他算法可以帮助确定文件需要发送到哪个服务器?

  3. 文件如何从上传服务器发送到 CDN?使用FTP?这是否会带来额外的开销,并且需要错误检查功能来检查 FTP 连接是否中断、检查文件是否传输成功等?

I have a file uploading site which is currently resting on a single server i.e using the same server for users to upload the files to and the same server for content delivery.

What I want to implement is a CDN (content delivery network). I would like to buy a server farm and somehow if i were to have a mechanism to have files spread out across the different servers, that would balance my load a whole lot better.

However, I have a few questions regarding this:

Assuming my server farm consists of 10 servers for content delivery,

  1. Since at the user end, the script to upload files will be one location only, i.e <form action=upload.php>, It has to reside on a single server, correct? How can I duplicate the script across multiple servers and direct the user's file upload data to the server with the least load?

  2. How should I determine which files to be sent to which server? During the upload process, should I randomize all files to go to random servers? If the user sends 10 files should i send them to a random server? Is there a mechanism to send them to the server with the least load? Is there any other algorithm which can help determine which server the files need to be sent to?

  3. How will the files be sent from the upload server to the CDN? Using FTP? Wouldn't that introduce additional overhead and need for error checking capability to check for FTP connection break, and to check if file was transferred successfully etc.?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

掀纱窥君容 2024-12-27 15:12:37

假设您使用的是 Apache 服务器,有一个名为 mod_proxy_balancer 的模块。它在幕后处理所有负载平衡工作。用户永远不会知道其中的差异——除非他们的下载和上传速度快了 10 倍。

  1. 如果您使用此功能,您可以在每台服务器上拥有完整的副本。

  2. mod_proxy_balancer 将为您处理此问题。

  3. 每个服务器都可以有自己的子域。您的“主”服务器上将有一个数据库,它将所有下载页面与其所在的物理服务器相匹配。然后,基于某种哈希加密算法传递动态 URL,这可以防止使用硬链接进行下载并增加页面点击量。它可能是个人信息和杂项信息的混合,例如用户的 IP 和一天中的时间。然后,下载服务器检查哈希值,并接受或拒绝请求。

如果一切正常,则开始下载;你的负载是平衡的;用户不必担心任何幕后的事情。

注意:我已经完成了 Apache 管理和 Web 开发。我从未管理过大型 CDN,所以这是基于我在其他网站上看到的内容和其他知识。如果有人要在这里添加内容或进行更正,请这样做。

更新

还有一些公司可以为您管理它。简单的 Google 搜索即可为您提供一个列表。

Assuming you're using an Apache server, there is a module called mod_proxy_balancer. It handles all of the load-balancing work behind the scenes. The user will never know the difference -- except when their downloads and uploads are 10 times faster.

  1. If you use this, you can have a complete copy on each server.

  2. mod_proxy_balancer will handle this for you.

  3. Each server can have its own sub-domain. You will have a database on your 'main' server, which matches up all of your download pages to the physical servers they are located on. Then a on-the-fly URL is passed based on some hash encryption algorithm, which prevents using a hard link to the download and increases your page hits. It could be a mix of personal and miscellaneous information, e.g., the users IP and the time of day. The download server then checks the hashes, and either accepts or denies the request.

If everything checks out, the download starts; your load is balanced; and the users don't have to worry about any of this behind the scenes stuff.

note: I have done Apache administration and web development. I have never managed a large CDN, so this is based on what I have seen in other sites and other knowledge. Anyone who has something to add here, or corrections to make, please do.

Update

There are also companies that manage it for you. A simple Google search will get you a list.

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