Amazon云计算服务EC2、S3介绍

- 编辑:admin -

Amazon云计算服务EC2、S3介绍

【IT168资讯】EC2主要功能
创建包含应用、库、数据和配置的机器映像。或者使用时限配置好的模板映像。
上传映像到Amazon S3。
用Web Service配置安全性和网络访问。
启动、终止、监视映像的任意多个运行实例。
只为实际使用的资源付费。

•EC2使用流程
Amazon Web Services上注册用户,输入支付方式
下载并安装最新的Java Runtime Environment,热点新闻,Amazon EC2 command-line tools ,PuTTY & PuTTYgen 。
创建并下载private key文件和X.509 certificate
运行‘C:\EC2\bin>ec2-describe-images -o self -o amazon’ 来查看所有公共的镜像
运行实例 C:\EC2\bin>ec2-run-instances ami-25b6534c -k kiki-keypair
通过以下命令查看状态 C:\EC2\bin>ec2-describe-instances i-c3f31eaa
给实例授以网络访问的权限。C:\EC2\bin>ec2-authorize default -p 22
用PuTTY连接实例
中止实例 C:\EC2\bin>ec2-terminate-instances i-c3f31eaa


•EC2模板映像
Standard Instances

Instances of this family are well suited for most applications.

$0.10 - Small Instance (Default)
1.7 GB of memory, 1 EC2 Compute Unit (1 virtual core with 1 EC2 Compute Unit), 160 GB of instance storage, 32-bit platform

$0.40 - Large Instance
7.5 GB of memory, 4 EC2 Compute Units (2 virtual cores with 2 EC2 Compute Units each), 850 GB of instance storage, 64-bit platform

$0.80 - Extra Large Instance
15 GB of memory, 8 EC2 Compute Units (4 virtual cores with 2 EC2 Compute Units each), 1690 GB of instance storage, 64-bit platform

High-CPU Instances

Instances of this family have proportionally more CPU resources than memory (RAM) and are well suited for compute-intensive applications.

$0.20 - High-CPU Medium Instance
1.7 GB of memory, 5 EC2 Compute Units (2 virtual cores with 2.5 EC2 Compute Units each), 350 GB of instance storage, 32-bit platform

$0.80 - High-CPU Extra Large Instance
7 GB of memory, 20 EC2 Compute Units (8 virtual cores with 2.5 EC2 Compute Units each), 1690 GB of instance storage, 64-bit platform

•EC2的流量和IP费用

Internet Data Transfer
$0.100 per GB - all data transfer in $0.170 per GB - first 10 TB / month data transfer out
$0.130 per GB - next 40 TB / month data transfer out
$0.110 per GB - next 100 TB / month data transfer out
$0.100 per GB - data transfer out / month over 150 TB

Elastic IP Addresses
    No cost for Elastic IP addresses while in use
$0.01 per non-attached Elastic IP address per complete hour
$0.00 per Elastic IP address remap - first 100 remaps / month
$0.10 per Elastic IP address remap - additional remap / month over 100


•S3功能

支持最小1byte,最大5G的存储对象;
无存贮对象个数上的限制;
每个存储对象存储在bucket中,且由有个用户定义的唯一性key来标识;
可以对每个存贮对象设置访问权限;
提供了REST和SOAP接口对对象进行读写、删除等操作;
可靠时间为99.9%;

•S3中的概念与操作
S3中的概念
Account
注册Amazon,申请开通S3后,得到AccessKey和Secret Key,你必须使用这两个key来调用API。

Bucket:
是S3中存储对象的容器,对应一个S3的域名,Bucket的名字不能重复,mydraw,每个Bucket中可以存储无限个对象。

Object:
是S3中的基本存储单元,单个Object最大5G,放在Bucket中,由Key唯一标识,有ObjectData和metaData组成,精选新闻,metaData可以是标准的metadata或者自定义的metadata。

KEY
KEY在Bucket中用来唯一标识一个Object,也就是说使用Bucket+KEY可以在S3中唯一标识一个Object。


S3中的操作
Services --list all buckets.
Bucket  --Create,Delete,List,Get/Set Access Control,Get/Set logging status;
Object  --Put,Get,Delete,Set/Get Access Control.

•S3客户端
S3的API和库
–REST 和SOAP
–JAVA
–C#
–Python
–Ruby
–PHP,PERL...
S3客户端工具
–S3cmd
–S3sync
–FireFox plug-in
–etc...

•S3使用实例
class Up2S3
 
  def initialize
    puts "start..."
    start = Time.now
    conf_file = YAML.load_file(File.expand_path('amazon_conf.yml'))
    @@s3 =  RightAws::S3Interface.new(conf_file['access_key_id'], conf_file['secret_access_key'])
    puts "@@s3=#{@@s3.to_s}"
    puts "Init Spend Time #{Time.now - start}"
  end
 
  #下载测试代码
  def self.download(bucket,key)
    start = Time.now
    foo = File.new(key, "wb+")
    @@s3.get(bucket, key) do |chunk|
      foo.write(chunk)
    end
    foo.close
    puts "Download Spend Time #{Time.now - start}"
  end
 
  #上传测试代码
  def self.upload(bucket,key,filename)
    start = Time.now
    @@s3.put(bucket,key, File.open(filename)) #=> true
    puts "Upload Spend Time #{Time.now - start}"
  end
 
end

•S3的价格
美国价格:
Storage
$0.15 per GB-Month of storage used Data Transfer
$0.100 per GB - all data transfer in