负载均衡服务器的文件上传最佳解决方案
我有 2 个负载均衡的网络服务器,连接到 1 个 Mysql 服务器。服务器上的 php 应用程序的功能之一是允许用户上传必须可以从任一 Web 服务器访问的图片。这样做的最佳解决方案是什么?
- 将图片上传至云端?
- 将图片存储在数据库
- 中将图片上传到MySQL服务器(不是数据库,文件系统)
- ...?
感谢您的建议。
I got 2 webservers load balanced, connected to 1 Mysql Server. One of the functionality of the php application on the servers allows the users to upload pictures which have to be accessible from either of the Web server . What would be the best solution to do so ?
- Upload the pictures to the clouds ?
- Store the pictures in the database
- Upload the pictures to the MysQL server (not the database, the filesystem)
- ... ?
Thanks for your advices.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
像上面这样的 rsync 可以工作,但是如果您在 WordPress 平台等平台上运行高流量站点,则上传的图像数量很快就会变得太多,rsync 无法在目录树中遍历,并且您首先会看到 rsync 在爬行过程中速度变慢。校验和部分,然后它将停止工作,就像您在包含太多文件的目录中执行
ls
时一样。但在您遇到这些问题之前,这是最好的解决方案。另一个解决方案是远程安装 nfs 分区,但这非常不安全,除非您处于真正可信的环境中。
另一种解决方案是立即将文件“放置”到 Amazon S3 上,然后将 URL 链接存储在数据库中,并在页面加载时呈现该链接。
不要将图片存储在数据库中 - 这确实会减慢数据库表的速度。
Rsync like above works, but if your running a high traffic site off something like wordpress platform the number of images uploaded can quickly become too many for rsync to traverse in the directory tree, and you'll first see rsync slow down too a crawl during the checksum part, and then it will just stop working like when you do an
ls
in a directory with too many files. But this is the best solution until you encounter these problems.Another solution is a remote mounted nfs partition but thats pretty insecure unless you are in a really trusted environment.
Another solution would be to immediately 'put' the file on Amazon S3 and then store the URL link in your database and just render that on page loads.
Don't store the pictures in the database - that really slows down the db table.
我使用复制文件系统 GlusterFS 和用于云存储的 Amazon S3 都取得了非常好的结果。
I've had very good results both using GlusterFS, which is a replicated filesystem, and Amazon S3 for cloud storage.
我建议上传到文件系统上的文件夹。然后定期运行 cron 作业,rsync 是两台服务器之间的文件夹。您还可以在图像上传的过程中运行 rsync。在数据库中存储图像可能会变得复杂,并且会使数据库膨胀。
I would recommend uploading to a folder on the filesystem. Then run a cron job periodically that rsync's the folder between the two servers. You could also have the rsync run in process with the image upload. Storing images in the database can get complicated and can bloat your database.