事前確認事項

instanceをStopするとPublic DNSが変わります(root deviceに関係なく)。

ハマりどころ

1 instanceには1 IPしか紐づけできない。SSLが2つ以上ある場合は、別のinstanceを作る必要がある

帯域

250Mb/s max throughput per small instance
500Mb/s max throughput per large instance
1000Mb/s max throughput per xlarge instance

設定箇所

  • AWSにサインアップする
  • EC2のコンソールからAMIを選択
  • インストール
  • 設定

AMI情報

Debian/Microinstance/EBS --> ami-0c638165

確認方法

EBS

  1. とりあえずコンソールでEBSを作る
  2. ssh
  3. hoge@ec2:/mnt/vol1# mkfs -t ext3 /dev/sdf
    mke2fs 1.41.11 (14-Mar-2010)
    /dev/sdf is entire device, not just one partition! 
    Proceed anyway? (y,n) y <= yを選択
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks 
    327680 inodes, 1310720 blocks
    65536 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=1342177280
    40 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736
    
    Writing inode tables: done                           
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 26 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
  4. mkdir /mnt/vol1
  5. mount /dev/sdf /mnt/vol1
  6. 物を色々入れてみる
  7. df
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/sda1             10321208   2013796   7783124  21% / 
    devtmpfs                853816       120    853696   1% /dev
    none                    870508         0    870508   0% /dev/shm
    none                    870508        52    870456   1% /var/run
    none                    870508         0    870508   0% /var/lock
    none                    870508         0    870508   0% /lib/init/rw
    /dev/sdb             153899044    192076 145889344   1% /mnt
    /dev/sdf               5160576    183208   4715224   4% /mnt/vol1
  8. コンソールでdetach出来るが、一度 umount /mnt/vol1した方が何かといい気がする

S3

s3fsの使い方

  1. s3fsパッケージをダウンロードします。ここから
    wget  http://s3fs.googlecode.com/files/s3fs-1.19.tar.gz 
    ※1.25上だとFUSE 2.8.4必須な為(lennyは2.7.4-1.1+lenny1)使えない
    1. http://s3fs.googlecode.com/files/s3fs-1.19.tar.gz
  2. 自分のInstanceにアップロード、展開、コンパイルします。
    tar xvzf s3fs-1.19.tar.gz
    cd s3fs-1.19/
    ./configure --prefix=/usr
  3. make && make installする(大体パッケージ不足でエラーになる)
    make
    make install (as root)
  4. S3のバケットをマウントしたい場所にディレクトリを作成し、マウントする
    /usr/bin/s3fs my_src_pub -o accessKeyId=aaa -o secretAccessKey=bbb /var/www/src
    (旧式)
    ※↑この方法は使えないので、http://code.google.com/p/s3fs/wiki/FuseOverAmazonを確認
    ~/.passwd-s3fsに
    accessKeyId:secretAccessKey
    か
    bucketName:accessKeyId:secretAccessKey
    という形でおいてpermissionを変更
    chmod 600 ~/.passwd-s3fs
    /usr/bin/s3fs bucketname /mnt

アンマウントする

umount -l /var/www/src

参考URL

AutoScale?する方法

EC2を使っていればAutoscaleする準備はできている。
トリガーとなるCloudWatch?を導入する必要がある
AWS+AutoScaling

s3cmd

AWS+s3cmd

S3-phpの使い方

aptitude install php5-curl
/etc/init.d/apache2 restart

private AMIの作り方

  1. Account > Security Credentials > X.509 Certificateで既存の鍵ペアをダウンロードか新規作成する
    こんなのが手元にあるはず(本当はもっと長い名前)
    cert-UDC6CR.pem
    pk-UDC6CR.pem
  2. Account > Security Credentialsの右上にあるアカウントIDを確認する
    Welcome, Lovely Aya | Sign Out
    Account Number XXXX-XXXX-XXXX
  3. Account > Security Credentials > Access Keys でAPI用のアカウント情報を確認するか新規で作成する
    Access Key ID: ACCESSKEYID(例)
    Secret Access Key: SECRETACCESSKEY(例)
  4. S3にAMIを保存しておくbucketを作っておく(s3://ayaami)
  5. Ec2にSSHでログインする。
  6. Rootになる
  7. 以下のコマンドを打つ
    ec2-bundle-vol -d /mnt --privatekey pk-UDC6CR.pem--cert cert-UDC6CR.pem --user XXXX-XXXX-XXXX  --fstab /etc/fstab
  8. アーキテクチャを聞かれる
    Please specify a value for arch [i386]: (Enterだとi386)
    Copying / into the image file /mnt/image...
    Excluding: 
    	 /sys
    	 /proc/bus/usb
    	 /proc
    	 /dev/pts
    	 /dev
    	 /media
    	 /mnt
    	 /proc
    	 /sys
    	 /mnt/image
    	 /mnt/img-mnt
    1+0 records in
    1+0 records out
    1048576 bytes (1.0 MB) copied, 0.001799 s, 583 MB/s
    mke2fs 1.41.3 (12-Oct-2008)
    /etc/fstab:
    	 # Legacy /etc/fstab
    	 # Supplied by: ec2-ami-tools-1.3-34544 
    	 /dev/sda1 /     ext3    defaults 1 1
    	 /dev/sda2 /mnt  ext3    defaults 0 0
    	 /dev/sda3 swap  swap    defaults 0 0
    	 none      /proc proc    defaults 0 0
    	 none      /sys  sysfs   defaults 0 0
    Bundling image file...
    Splitting /mnt/image.tar.gz.enc...
    Created image.part.00
    Created image.part.01
    〜略〜
    Created image.part.37
    Created image.part.38
    Generating digests for each part...
    Digests generated.
    Unable to read instance meta-data for product-codes
    Creating bundle manifest...
    ec2-bundle-vol complete.
  9. 出来たimageをS3に移動させる為、以下のコマンドを打つ
    ※manifestの場所はAMIを作った場所(今回だと/mntの下にimage.manifest.xmlが生成されている)
    ec2-upload-bundle --bucket ayaami --manifest /mnt/image.manifest.xml --access-key ACCESSKEYID --secret-key SECRETACCESSKEY
    Uploading bundled image parts to the S3 bucket ayaami ...
    Uploaded image.part.00
    Uploaded image.part.01
    Uploaded image.part.02
    〜略〜
    Uploaded image.part.37
    Uploaded image.part.38
    Uploading manifest ...
    Uploaded manifest.
    Bundle upload completed.
  10. AMIとして登録させる
    ec2-register ayaami/image.manifest.xml -n MyCoolAmi --private-keypk-UDC6CR.pem --cert cert-UDC6CR.pem
    IMAGE	ami-s0b0sg7
  11. AWSコンソールから確認するとPrivate AMIが出来ているので、instanceとして立ち上げる

CloudFront?に登録されたObjectを削除する方法

一番簡単なのは、AWSから出ているSDKを使った簡単アプリを作る事

AMI

エラー時には

The specified bucket is not S3 v2 safe

The specified bucket is not S3 v2 safe (see S3 documentation for details):

これはS3の命名規則にそってないから。場所によっては_とか使えるんだけれど、基本は_は使えない

[解決済み]error reading certificate: nested asn1 error

ERROR: error reading certificate file ./.ssh/authorized_keys: error reading certificate: nested asn1 error

この問題はX509でもう一度鍵ペアを作って使えば解決する

[解決済み]Problem: Error: unsupported locale setting

hoge:/home/hogehoge/s3cmd-0.9.9.91# ./s3cmd --configure

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   An unexpected error has occurred.
 Please report the following lines to:
  s3tools-bugs@lists.sourceforge.net
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Problem: Error: unsupported locale setting
S3cmd:   0.9.9.91

Traceback (most recent call last):
 File "./s3cmd", line 1736, in <module>
   main()
 File "./s3cmd", line 1474, in main
   preferred_encoding = locale.getpreferredencoding() or "UTF-8"
 File "/usr/lib/python2.5/locale.py", line 514, in getpreferredencoding
   setlocale(LC_CTYPE, "")
 File "/usr/lib/python2.5/locale.py", line 478, in setlocale
   return _setlocale(category, locale)
Error: unsupported locale setting

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    An unexpected error has occurred.
    Please report the above lines to:
   s3tools-bugs@lists.sourceforge.net 

む、と思って

hoge:/home/hogehoge/s3cmd-0.9.9.91# locale

で確認

hoge:/home/hogehoge/s3cmd-0.9.9.91# export LANG=C;

で解決

[解決済み]make: pkg-config: Command not found

s3fs コンパイルしようと思ったらこんなエラーが。

example:/home/aya/s3fs# make
make: pkg-config: Command not found
make: pkg-config: Command not found
make: xml2-config: Command not found
g++ -ggdb -Wall    -lcrypto s3fs.cpp -o s3fs
s3fs.cpp:23:18: error: fuse.h: No such file or directory
s3fs.cpp:34:23: error: curl/curl.h: No such file or directory
s3fs.cpp:35:27: error: libxml/parser.h: No such file or directory
s3fs.cpp:36:25: error: libxml/tree.h: No such file or directory
s3fs.cpp:393:25: error: openssl/bio.h: No such file or directory
s3fs.cpp:394:28: error: openssl/buffer.h: No such file or directory
s3fs.cpp:395:25: error: openssl/evp.h: No such file or directory
s3fs.cpp:396:26: error: openssl/hmac.h: No such file or directory
s3fs.cpp:527:25: error: openssl/md5.h: No such file or directory
s3fs.cpp:124: error: 'CURL' was not declared in this scope
s3fs.cpp:124: error: template argument 1 is invalid
s3fs.cpp:124: error: template argument 2 is invalid
s3fs.cpp:124: error: invalid type in declaration before ';' token
s3fs.cpp:128: error: 'CURL' was not declared in this scope
s3fs.cpp:128: error: template argument 1 is invalid
s3fs.cpp:128: error: template argument 3 is invalid
s3fs.cpp:128: error: template argument 4 is invalid
s3fs.cpp:128: error: invalid type in declaration before ';' token
s3fs.cpp:129: error: 'CURL' was not declared in this scope
s3fs.cpp:129: error: template argument 1 is invalid
s3fs.cpp:129: error: template argument 3 is invalid
s3fs.cpp:129: error: template argument 4 is invalid
s3fs.cpp:129: error: invalid type in declaration before ';' token
s3fs.cpp: In function 'int my_curl_progress(void*, double, double, double,  double)':
s3fs.cpp:134: error: 'CURL' was not declared in this scope
s3fs.cpp:134: error: 'curl' was not declared in this scope
s3fs.cpp:134: error: expected type-specifier before 'CURL'
s3fs.cpp:134: error: expected `>' before 'CURL'
s3fs.cpp:134: error: expected `(' before 'CURL'
s3fs.cpp:134: error: expected primary-expression before '>' token
s3fs.cpp:134: error: expected `)' before ';' token
s3fs.cpp:151: error: 'CURLE_ABORTED_BY_CALLBACK' was not declared in this scope
s3fs.cpp: At global scope:
s3fs.cpp:157: error: expected initializer before '*' token
s3fs.cpp:51: warning: 'connect_timeout' defined but not used
s3fs.cpp:124: warning: 'curl_handles' defined but not used
s3fs.cpp:133: warning: 'int my_curl_progress(void*, double, double, double,  double)' defined but not used
make: *** [all] Error 1

むむむ、と思って以下のパッケージを入れたらmake出来たよ!

aptitude install pkg-config libxml2-dev libfuse-dev libcurl4-openssl-dev

[解決済み]warning: Unable to get device geometry for /mnt/image

コマンドラインでAMIを作っている時に出たエラー

〜略〜
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.00974847 s, 108 MB/s
mke2fs 1.41.11 (14-Mar-2010)
warning: Unable to get device geometry for /mnt/image
umount: /mnt/img-mnt: device is busy.
       (In some cases useful info about processes that use
        the device is found by lsof(8) or fuser(1))
ERROR: execution failed: "umount -d /mnt/img-mnt"

で、umountしようと思ったら

root@xxxx:~# umount -d /mnt/img-mnt/
umount: /mnt/img-mnt: device is busy.
       (In some cases useful info about processes that use
        the device is found by lsof(8) or fuser(1))

アンマウントしたくないんだよっ!!と暴れられたので、

root@xxxx:~# lsof | grep img-mnt
rsync      983     root  cwd       DIR        7,0     4096          2 /mnt/img-mnt
rsync      984     root  cwd       DIR        7,0     4096          2 /mnt/img-mnt
rsync      984     root    1u      REG        7,0   229376      16804 /mnt/img-mnt/var/cache/apt/archives/.libxml2-dev_2.7.6.dfsg-1ubuntu1.1_i386.deb.tRaQXM

↑お前か!>
ps afuxも確認

root       871  0.0  0.1   4704  1892 pts/0    Ss   03:32   0:00      \_ -bash
root       946  0.0  0.0   4264  1284 pts/0    T    03:34   0:00          \_ /bin/bash /home/ec2/bin/ec2-bundle-vol -d /mnt --privatekey .pk-hogehoge.pem --c
root       947  0.0  0.4  19464  8608 pts/0    T    03:34   0:00          |   \_ ruby -I /home/ec2/lib /home/ec2/lib/ec2/amitools/bundlevol.rb -d /mnt --privatekey .pk-hogehoge
root       981  0.0  0.0   1852   564 pts/0    T    03:34   0:00          |       \_ sh -c rsync -rlpgoD -t -r -S -l --exclude /sys/kernel/debug --exclude /sys/kernel/security --exclude /sys
root       982  0.3  1.5  36376 26768 pts/0    T    03:34   0:06          |           \_ rsync -rlpgoD -t -r -S -l --exclude /sys/kernel/debug --exclude /sys/kernel/security --exclude /sys -
root       983  0.0  0.1  29988  3132 pts/0    T    03:34   0:00          |               \_ rsync -rlpgoD -t -r -S -l --exclude /sys/kernel/debug --exclude /sys/kernel/security --exclude /s
root       984  0.6  0.2  50400  4244 pts/0    T    03:34   0:10          |                   \_ rsync -rlpgoD -t -r -S -l --exclude /sys/kernel/debug --exclude /sys/kernel/security --exclud
root      1797  0.0  0.0   3948   896 pts/0    R+   04:02   0:00          \_ ps afux

なので、一度プロセスを抜けて、再度ログイン、

root@xxxx:~# umount -d /mnt/img-mnt/

するとすんなりumountしてくれた
再度ec2-bundle-volをたたくと、

warning: Unable to get device geometry for /mnt/image

は依然出るが、AMIは作れる

[解決済み]Client.InvalidManifest?: HTTP 301 (Moved Permanently) response for URL

さてAMIファイルをS3にアップロードしたので登録させようとコマンドを打ったら

root@xxxx:~# ec2-register hogehoge/image.manifest.xml -n CloudStockAmi --private-key .pk-hogehoge.pem --cert .cert-hogehoge.pem 
Client.InvalidManifest: HTTP 301 (Moved Permanently) response for URL 
http://s3.amazonaws.com:80/hogehoge/image.manifest.xml: 
check your manifest path is correct and in the correct region.

なんだと!?S3の権限設定を見ても問題なさげ。
なので、AWSコンソールでやってみたら、一発で出来た。どういう事。。。

upload.png

参考URL


添付ファイル: fileupload.png 203件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2012-03-12 (月) 16:54:35 (197d)