AmazonEC2応用編-自作のCentOS5のOSイメージをS3にバックアップする。
![]() |
EC2では、マシンをシャットダウンしてしまうと、OS環境も失ってしまう。 だから、OSイメージをバックアップすることが特に重要。いかに、手順をメモしておく。 |
1.ローカルマシンから、証明書と秘密キーファイルを送信
$ scp -i ~/.ssh/id_rsa.xxxxxxxxxx $EC2_PRIVATE_KEY $EC2_CERT root@xxx.xxx.com:/mnt/.ec2/
pk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem 100% 926 0.9KB/s 00:00
cert-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem
2.EC2のインスタンスにログイン
$ ssh -i ~/.ssh/id_rsa.xxxxxxxxxx -l root
3.ツール類のセットアップ
(1)unzipの導入(未導入の場合)
# yum -y install unzip
(2)以前の記事で記載した「1.AWSのアカウントを取得して、ツールのセットアップを行う」の
「(3)Amazon EC2 API Toolsをセットアップ」と「(4)Amazon EC2 AMI Toolsをセットアップ」を実施。
4.カーネルモジュールの追加と反映
# cd /tmp
# wget http://s3.amazonaws.com/ec2-downloads/modules-2.6.16-ec2.tgz
# tar xzvf modules-2.6.16-ec2.tgz
# cp -rp lib/* /lib/
# depmod -a
5.イメージ格納ディレクトリ作成
# mkdir /mnt/img
6.不整合が心配なサービスがあれば、必要に応じてを落としておく<\h3>
7.AMI作成
time ec2-bundle-vol -d /mnt/img -r i386 -k /mnt/.ec2/pk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem -c /mnt/.ec2/cert-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem -u NNNNNNNNNNNN
Please specify a value for arch [i386]:
Copying / into the image file /mnt/img/image...
Excluding:
/sys
/proc
/dev/pts
/proc/sys/fs/binfmt_misc
/dev
/media
/mnt
/proc
/sys
/mnt/img/image
/mnt/img-mnt
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.003038 seconds, 345 MB/s
mke2fs 1.39 (29-May-2006)
Bundling image file...
Splitting /mnt/img/image.tar.gz.enc...
Created image.part.000
Created image.part.001
Created image.part.002
Created image.part.003
:
Created image.part.125
Created image.part.126
Created image.part.127
Created image.part.128
Created image.part.129
Created image.part.130
Generating digests for each part...
Digests generated.
Unable to read instance meta-data for ancestor-ami-ids
Unable to read instance meta-data for kernel-id
Unable to read instance meta-data for ramdisk-id
Unable to read instance meta-data for product-codes
Creating bundle manifest...
ec2-bundle-vol complete.
real 20m8.138s
user 3m51.990s
sys 1m13.610s
※データ量によるのか、1時間近くかかったこともある。
8.作成したAMIをS3へアップ
# time ec2-upload-bundle -b <任意のbucket名> -m /mnt/img/image.manifest.xml -a <アクセスキー> -s <秘密アクセスキー>
Uploading bundled image parts to the S3 bucket <指定したbucket名> ...
Uploaded image.part.000
Uploaded image.part.001
Uploaded image.part.002
Uploaded image.part.003
:
Uploaded image.part.128
Uploaded image.part.129
Uploaded image.part.130
Uploading manifest ...
Uploaded manifest.
Bundle upload completed.
real 7m18.363s
user 0m17.300s
sys 0m8.130s
9.イメージの登録
# ec2-register <指定したbucket名>/image.manifest.xml
IMAGE ami-xxxxxxxx
10.登録済みイメージの確認
# ec2-describe-images -o self
IMAGE ami-xxxxxxxx <指定したbucket名>/image.manifest.xml 938654150775 available private i386 machine
time ec2-bundle-vol -d /mnt/img -r i386 -k /mnt/.ec2/pk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem -c /mnt/.ec2/cert-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem -u NNNNNNNNNNNN
Please specify a value for arch [i386]:
Copying / into the image file /mnt/img/image...
Excluding:
/sys
/proc
/dev/pts
/proc/sys/fs/binfmt_misc
/dev
/media
/mnt
/proc
/sys
/mnt/img/image
/mnt/img-mnt
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.003038 seconds, 345 MB/s
mke2fs 1.39 (29-May-2006)
Bundling image file...
Splitting /mnt/img/image.tar.gz.enc...
Created image.part.000
Created image.part.001
Created image.part.002
Created image.part.003
:
Created image.part.125
Created image.part.126
Created image.part.127
Created image.part.128
Created image.part.129
Created image.part.130
Generating digests for each part...
Digests generated.
Unable to read instance meta-data for ancestor-ami-ids
Unable to read instance meta-data for kernel-id
Unable to read instance meta-data for ramdisk-id
Unable to read instance meta-data for product-codes
Creating bundle manifest...
ec2-bundle-vol complete.
real 20m8.138s
user 3m51.990s
sys 1m13.610s
※データ量によるのか、1時間近くかかったこともある。
# time ec2-upload-bundle -b <任意のbucket名> -m /mnt/img/image.manifest.xml -a <アクセスキー> -s <秘密アクセスキー>
Uploading bundled image parts to the S3 bucket <指定したbucket名> ...
Uploaded image.part.000
Uploaded image.part.001
Uploaded image.part.002
Uploaded image.part.003
:
Uploaded image.part.128
Uploaded image.part.129
Uploaded image.part.130
Uploading manifest ...
Uploaded manifest.
Bundle upload completed.
real 7m18.363s
user 0m17.300s
sys 0m8.130s
# ec2-register <指定したbucket名>/image.manifest.xml
IMAGE ami-xxxxxxxx
# ec2-describe-images -o self
IMAGE ami-xxxxxxxx <指定したbucket名>/image.manifest.xml 938654150775 available private i386 machine


Leave a Reply