Amazon EC2用Centos5イメージを作って、EC2上で動作させてみる(4)

logo_aws 前回までに作成したOSイメージを加工して、S3にアップし、EC2のマシンイメージとして登録する。

4.EC2向けのイメージ加工とアップロード

(1)EC2登録用バンドルイメージの作成

この処理は5分余りで終了。

【ec2-bundle-imageコマンドのオプション】

-i イメージ名:

 イメージファイルの名称

-k 秘密鍵ファイル名

-c 証明書ファイル名

-u アカウント番号

awsのユーザページなどにアクセスすると、
右上に表示される「Account Number」の数値部分(12桁)


$ cd /work/ec2
$ ec2-bundle-image -i centos5.img \
-k ~/.ec2/pk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pem \
-c ~/.ec2/cert-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pem -u NNNNNNNNNNNN

前述の環境変数が設定されている場合は、以下のように、環境変数で指定してもOK


$ time ec2-bundle-image -i centos5.img -k $EC2_PRIVATE_KEY -c $EC2_CERT -u NNNNNNNNNNNN
Please specify a value for arch [i386]:
Bundling image file...
Splitting /tmp/centos5.img.tar.gz.enc...
Created centos5.img.part.00
Created centos5.img.part.01
Created centos5.img.part.02
Created centos5.img.part.03
Created centos5.img.part.04
Created centos5.img.part.05
Created centos5.img.part.06
Created centos5.img.part.07
Created centos5.img.part.08
Created centos5.img.part.09
Created centos5.img.part.10
Created centos5.img.part.11
Created centos5.img.part.12
Created centos5.img.part.13
Created centos5.img.part.14
Created centos5.img.part.15
Created centos5.img.part.16
Created centos5.img.part.17
Created centos5.img.part.18
Created centos5.img.part.19
Created centos5.img.part.20
Created centos5.img.part.21
Created centos5.img.part.22
Created centos5.img.part.23
Created centos5.img.part.24
Created centos5.img.part.25
Created centos5.img.part.26
Created centos5.img.part.27
Created centos5.img.part.28
Created centos5.img.part.29
Created centos5.img.part.30
Created centos5.img.part.31
Created centos5.img.part.32
Generating digests for each part...
Digests generated.
Creating bundle manifest...
ec2-bundle-image complete.

real    5m6.823s
user    3m23.681s
sys     0m29.098s

(2)バンドルイメージのアップロード

この処理には30分以上かかった。光回線なのに、意外に時間がかる。

【ec2-upload-bundleコマンドのオプション】

-b バケット名:

 バケット名は、3文字以上63文字以下
 英小文字、数字、”.”、”-”のみ
 最初と最後の文字には”.”は不可
 ”-”の前後に”.”は不可
 詳しくは以下「Best Practices for Using Amazon S3」の「Naming Buckets and Keys

-m ec2-bundle-imageコマンドで生成されたマニュフェストファイル名

-a AmazonシークレットキーID

-s Amazonシークレットキー


$ time ec2-upload-bundle -b my-private-bucket -m centos5.img.manifest.xml \
-a aaaaaaaaaaaaaaaaaaaa -s ssssssssssssssssssssssssssssssssssssssss
Creating bucket...
Uploading bundled image parts to the S3 bucket va-private ...
Uploaded centos5.img.part.00
Uploaded centos5.img.part.01
Uploaded centos5.img.part.02
Uploaded centos5.img.part.03
Uploaded centos5.img.part.04
Uploaded centos5.img.part.05
Uploaded centos5.img.part.06
Uploaded centos5.img.part.07
Uploaded centos5.img.part.08
Uploaded centos5.img.part.09
Uploaded centos5.img.part.10
Uploaded centos5.img.part.11
Uploaded centos5.img.part.12
Uploaded centos5.img.part.13
Uploaded centos5.img.part.14
Uploaded centos5.img.part.15
Uploaded centos5.img.part.16
Uploaded centos5.img.part.17
Uploaded centos5.img.part.18
Uploaded centos5.img.part.19
Uploaded centos5.img.part.20
Uploaded centos5.img.part.21
Uploaded centos5.img.part.22
Uploaded centos5.img.part.23
Uploaded centos5.img.part.24
Uploaded centos5.img.part.25
Uploaded centos5.img.part.26
Uploaded centos5.img.part.27
Uploaded centos5.img.part.28
Uploaded centos5.img.part.29
Uploaded centos5.img.part.30
Uploaded centos5.img.part.31
Uploaded centos5.img.part.32
Uploading manifest ...
Uploaded manifest.
Bundle upload completed.

real    32m13.755s
user    0m3.960s
sys     0m1.872s

イメージの登録


$ ec2-register my-private-bucket/centos5.img.manifest.xml
IMAGE   ami-xxxxxxxx

登録済みイメージのリスト確認


$ ec2-describe-images -o self
IMAGE   ami-xxxxxxxx    my-private-bucket/centos5.img.manifest.xml     938654150775    available       private         i386    machine

さて、次はいよいよマシンイメージを実行する


1.AWSのアカウントを取得して、ツールのセットアップを行う 
2.Centos5のディスクイメージを作成する。
3.Centos5のイメージを、EC2向けにカスタマイズする。
4.作成したOSイメージを加工して、S3にアップし、EC2のマシンイメージとして登録する。
5.マシンイメージの実行、停止、マシンイメージの廃棄。

Leave a Reply