Kiki Zhao的英语学习天地

努力学习英语!!!
Amazon EC2之初体验(二)

运行实例

1.      运行‘C:\EC2\bin>ec2-describe-images -o self -o amazon’ 来查看所有公共的镜像

C:\EC2\bin>ec2-describe-images -o self -o amazon

IMAGE   ami-20b65349    ec2-public-images/fedora-core4-base.manifest.xml

amazon  available       public

IMAGE   ami-22b6534b    ec2-public-images/fedora-core4-mysql.manifest.xml

amazon  available       public

IMAGE   ami-23b6534a    ec2-public-images/fedora-core4-apache.manifest.xml

amazon  available       public

IMAGE   ami-25b6534c    ec2-public-images/fedora-core4-apache-mysql.manifest.xml

amazon  available       public

IMAGE   ami-26b6534f    ec2-public-images/developer-image.manifest.xml  amazon

available       public

IMAGE   ami-2bb65342    ec2-public-images/getting-started.manifest.xml  amazon

available       public

IMAGE   ami-bd9d78d4    ec2-public-images/demo-paid-AMI.manifest.xml    amazon

available       public  A79EC0DB

或者到这个页面选择一个适合的AMI:

http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=101

2.      运行‘C:\EC2\bin>ec2-add-keypair kiki-keypair’,然后创建一个名为 id_rsa-kiki-keypair的文件,粘贴从-----BEGIN RSA PRIVATE KEY---------END RSA PRIVATE KEY-----之间(包括它们本身)所有的内容。特别注意最后一行的换行。

-----BEGIN RSA PRIVATE KEY-----

MIIEoQIBAAKCAQBuLFg5ujHrtm1jnutSuoO8Xe56LlT+HM8v/xkaa39EstM3/aFxTHgElQiJLChp

HungXQ29VTc8rc1bW0lkdi23OH5eqkMHGhvEwqa0HWASUMll4o3o/IX+0f2UcPoKCOVUR+jx71Sg

5AU52EQfanIn3ZQ8lFW7Edp5a3q4DhjGlUKToHVbicL5E+g45zfB95wIyywWZfeW/UUF3LpGZyq/

ebIUlq1qTbHkLbCC2r7RTn8vpQWp47BGVYGtGSBMpTRP5hnbzzuqj3itkiLHjU39S2sJCJ0TrJx5

i8BygR4s3mHKBj8l+ePQxG1kGbF6R4yg6sECmXn17MRQVXODNHZbAgMBAAECggEAY1tsiUsI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QPbLknn7EqhXIjBaT

P8TTvW/6bdPi23ExzxZn7KOdrfclYRph1LHMpAONv/x2xALIf91UB+v5ohy1oDoasL0gij1houRe

2ERKKdwz0ZL9SWq6VTdhr/5G994CK72fy5WhyERbDjUIdHaK3M849JJuf8cSrvSb4g==

-----END RSA PRIVATE KEY-----

 

3.      运行是实例。这个过程需要几分钟的时间

C:\EC2\bin>ec2-run-instances ami-25b6534c -k kiki-keypair

RESERVATION     r-3e27c657      621657444030    default

INSTANCE        i-c3f31eaa      ami-25b6534c                    pending kiki-keypair  0

4.      通过以下命令查看状态

C:\EC2\bin>ec2-describe-instances i-c3f31eaa

RESERVATION     r-3e27c657      621657444030    default

INSTANCE        i-c3f31eaa      ami-25b6534c    ec2-72-44-51-222.z-1.compute-1.amazonaws.com    domU-12-31-36-00-30-74.z-1.compute-1.internal   running kiki-keypair  0

5.      给你的实例授以网络访问的权限。

C:\EC2\bin>ec2-authorize default -p 22

PERMISSION     default  ALLOWS  tcp     22      22      FROM    CIDR   0.0.0.0/0

C:\EC2\bin>ec2-authorize default -p 80

PERMISSION     default  ALLOWS  tcp     80      80      FROM    CIDR   0.0.0.0/0

C:\EC2\bin>ec2-authorize default -p 21

PERMISSION     default  ALLOWS  tcp     80      21      FROM    CIDR   0.0.0.0/0

6.      PuTTY连接你的实例

7.      通过浏览器查看你的实例.Http://ec2-72-44-51-222.z-1.compute-1.amazonaws.com

8.      如果需要,安装VSFTPD

yum –y install vsftpd

passwd root

/sbin/service vsftpd start

创建一个镜像

9.      在实例中,下载ec2-ami-tools然后安装

bash-3.2# wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.noarch.rpm.

rpm -Uvh ec2-ami-tools.noarch.rpm

注意:在有些实例中,你需要安装Ruby

10.  复制private key509 certificate文件于/mnt

11.  运行

bash-3.2#ec2-bundle-vol -d /mnt -k /mnt/privatekey.pem -c /mnt/509certificate.pem –u < AWS account ID >

注意:account ID可以从Amazon网上的Account Activity地方得到。它显示在页面的左上方,格式象9999-9999-9999。不过要移除中间的连接符只留下12位数字。

12.  运行ls -l /mnt/image.* 查看生成的文件

13.  运行如下命令上传AMIAmazonS3

bash-3.2#ec2-upload-bundle -b <your-s3-bucket> -m /mnt/image.manifest.xml -a <aws-access-key-id> -s <aws-secret-access-key>

14.  运行如下命令以注册你的AMI

C:\EC2\bin>ec2-register <your-s3-bucket>/image.manifest.xml

15.  运行如下命令产生一个实例基于你的AMI

C:\EC2\bin>ec2-run-instances ami-5bae4b32

 

Cleaning Up

16.  运行如下命令注销AMI

C:\EC2\bin>ec2-deregister <your-s3-bucket>

17.  运行如下命令从Amazon S3上移除你的AMI

bash-3.2#ec2-delete-bundle -b <your-s3-bucket> -p image -a <aws-access-key-id> -s <aws-secret-access-key>

18.  中止你的实例。一旦你的实例启动后,你就必须为它消耗掉的资源付钱。如果你决定不再使用它了,最好中止掉它

C:\EC2\bin>ec2-terminate-instances i-c3f31eaa

INSTANCE i-10a64379 running shutting-down

或直接关闭你的实例

bash-3.2#shutdown –h now

 

相关连接

l         Amazon EC2 Getting Started Guide (API Version 2007-03-01)

http://docs.amazonwebservices.com/AWSEC2/2007-03-01/GettingStartedGuide/

l         Setting up and Running Amazon EC2 from Windows

http://developer.amazonwebservices.com/connect/servlet/KbServlet/download/583-102-1043/ec2-tutorial-transcript-from-castingwords.html

 

 

posted on 2007-08-21 17:33  Kiki  阅读(2292)  评论(3编辑  收藏  举报