免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1364 | 回复: 0
打印 上一主题 下一主题

Amazon的s3服务 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-22 08:52 |只看该作者 |倒序浏览
<span class="Apple-style-span" style="color: rgb(51, 0, 0); font-family: Arial; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; line-height: normal; "><p style="line-height: normal; ">现在在搞一个类似于s3的项目。学习了一下Amazon 的s3.</p><p style="line-height: normal; "><em style="line-height: normal; "><br style="line-height: normal; "></em></p><p style="line-height: normal; "><em style="line-height: normal; ">Amazon</em>网络服务(Amazon Web Service,简称AWS)由多个核心服务组成,包括储存、数据库、计算和队列。本文将只讨论S3(Simple Storage Service,简单储存服务)的独特优点,尤其针对独立开发者而言。<br style="line-height: normal; "><br style="line-height: normal; "><em style="line-height: normal; ">Amazon</em>&nbsp;S3这个存储服务有一些错位特性。许多人将其视作Web服务器的替代品,但<strong style="line-height: normal; "><em style="line-height: normal; ">Amazon</em>&nbsp;S3不是Web服务器</strong>。S3有一些融合了Web服务器的特性,正式这些特性使得其定位有些含混不清。我们从一个例子来看,假设有一个叫做"47hats.png"的文件:<br style="line-height: normal; "><br style="line-height: normal; "><strong style="line-height: normal; ">每个文件都有一个URI并能通过http协议来访问</strong>:<br style="line-height: normal; "><br style="line-height: normal; ">你将文件存放在<em style="line-height: normal; ">S3</em>的一个“桶”中。桶是存放文件的容器。S3给每个桶和桶中每个文件分配一个URI地址,因此你可以通过http或者https协议进行访问。如果你把文件上传到一个叫做"mybucket"的桶中,你就可以通过如下URI进行访问:<br style="line-height: normal; "><br style="line-height: normal; ">http://mybucket.s3.amazonaws.com/47hats.png<br style="line-height: normal; "><br style="line-height: normal; ">http://s3.amazonaws.com/mybucket/47hats.png<br style="line-height: normal; "><br style="line-height: normal; ">你还可以在URI末尾加上"?torrent"使之成为一个torrent地址。<br style="line-height: normal; "><br style="line-height: normal; "><strong style="line-height: normal; ">允许多层次的权限控制:</strong><br style="line-height: normal; "><br style="line-height: normal; ">你可以将文件上传到<em style="line-height: normal; ">S3</em>并且只让自己可以访问。如果你对文件进行过加密,那么事实上除了你没有其他任何人能够读取该文件。相反的,你也可以将文件开放给全世界。一个能用http访问、具备URI地址的对象,其实就和Web服务器上的对象是一样的。<br style="line-height: normal; "><br style="line-height: normal; "><strong style="line-height: normal; ">允许DNS别名:</strong><br style="line-height: normal; "><br style="line-height: normal; ">如 果桶的名字符合域名规范,那么它就能通过DNS别名被访问。假设创建一个叫images.example.com的桶,将47hats.png放入其中, 并将该桶的CNAME指向s3.amazonaws.com,那么我们就能通过这个URI地址访问到 它:http://images.example.com/47hats.png<br style="line-height: normal; "><br style="line-height: normal; "><strong style="line-height: normal; ">你可以创建最多100个桶:</strong><br style="line-height: normal; "><br style="line-height: normal; ">当 我用web-site-grader(一个网站SEO工具)检查47hats.com的主页时,它提示我说“图片太多”。当时的主页上有29张图片,这算 是正常的,然而用户访问该页时需要下载各类文件(图片、css、javascript等等)。一般浏览器对同一个站点只能有4个并发连接,所以总体下载速 度会变慢。有了<em style="line-height: normal; ">S3</em>,你可以将这些文件放在好几个桶里面,一旦它们被当作不同的网站,浏览器的下载速度就能大大加快了。<br style="line-height: normal; "><br style="line-height: normal; "><strong style="line-height: normal; ">带有到期时间的认证请求:</strong><br style="line-height: normal; "><br style="line-height: normal; ">注册<em style="line-height: normal; ">Amazon</em>&nbsp;S3的时候,你会得到一份公钥和一份私钥。大多数发送至S3的http请求需要携带这些密钥。你可以在S3中为某些文件在其协议请求头部加上“到期时间”信息,这样你就能把这些私人文件的地址提供给其他人,放心,这些文件会在未来某一时刻自动过期。</p><p style="line-height: normal; "><strong style="line-height: normal; ">带范围的GET请求(常用于断点续传):</strong><br style="line-height: normal; "><br style="line-height: normal; ">你可以向<em style="line-height: normal; ">S3</em>请 求文件的某段数据。所以对于大型文件,你可以做到先下载起初的几兆数据,并在处理的同时下载后续的内容。这一点让S3成了一个完美的Web服务器,因为这 都可以被称作多媒体文件服务器了。像Flash这样的播放器就能跳过前面的内容而直接定位到文件后部某一段,从中间开始播放。<br style="line-height: normal; "><br style="line-height: normal; "><strong style="line-height: normal; ">文件的用户元数据:</strong></p><p style="line-height: normal; ">每个文件都可以附加一些由你指定的元数据。用户元数据就是一个个“名-值”对,<em style="line-height: normal; ">S3</em>可以在每个文件上都附加这样元数据。人们可以用它来模拟Web服务器所能提供的http应答数据,这里有两个例子:<br style="line-height: normal; "><em style="line-height: normal; ">S3</em>会 自动在文件请求的返回头部中加上最后修改(last modified)信息,如果浏览器要访问47hats.png,它会先向S3询问文件是否修改过,以此来决定是否进行下载。你可以在头部加上"过期信 息"(Expires),这样浏览器甚至不会每次去检查是否需要下载,而是每隔一段时间进行。<br style="line-height: normal; ">我们还能将47hats.png压缩后上传到<em style="line-height: normal; ">S3</em>,并且加上"Content-Encoding: gzip"的头部信息,浏览器就能正确将文件解压缩。这样做能够大大节省带宽和存储空间。<br style="line-height: normal; "><br style="line-height: normal; "><strong style="line-height: normal; ">能够扩展(高性能)</strong><br style="line-height: normal; "><br style="line-height: normal; "><em style="line-height: normal; ">S3</em>不仅能够扩展,而且能够扩展到极大的尺度。<br style="line-height: normal; ">所有的<em style="line-height: normal; ">Amazon</em>服 务都是适合并发访问的,你可以同时发起多个请求,S3能确保正确响应。S3支持RFC 1323所定义的TCP窗口缩放,简而言之,数据将传输得非常快。当你需要发布一个产品的最新版本、突然遭受大规模访问流量时,访问者的请求都会涌向你的 服务器,而使用S3,瓶颈将是访问者们自己的连接带宽,而不再是服务器自身。因为Amazon在全球多个区域都部署有数据中心。<br style="line-height: normal; "><br style="line-height: normal; ">就像我一开始所说的,<em style="line-height: normal; ">S3</em>不是Web服务器,<em style="line-height: normal; ">Amazon</em>还宣称它并不是一个内容递送网(Content Delivery Network,简称CDN),因为他并没有边界缓存功能。不过因其所提供的高性能,和低廉的价格,并被大众成为穷人的CDN。</p></span>
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP