Amazon EC2/S3 Tutorial

    版本為 02:01, 27 Dec 2024

    到這個版本。

    返回到 版本存檔.

    查閱目前版本

    Amazon EC2/S3 教學

    如何取得基本認證 Access Key ID & Secret Access Key

     

    使用 Putty 登入 Instance

    1. 在 AWS Console > Key Pairs,新增一組 key pair,並下載 xxx.pem 到本地電腦。(key pair 只有在新增時才能被下載,之後就無法再下載,如果遺失 key pair,就重新再新增一個,不過別忘了,也要一併修改 Instance  的設定)
    2. 下載 PuTTYgen,這工具將用來產生 PuTTY Private Key file(*.ppk)
      執行 PuTTYgen > Conversions > Import key, 載入 xxx.pem > Save private key(提示沒有輸入 key passphrase, 按 yes) > 存檔成 xxx.ppk
    3. 開啟 PuTTY > 輸入 IP > Connection type: SSH >
      Connection > SSH > Auth > Private key file for authentication: 載入 xxx.ppk > Open 連線
    4. 輸入 root,不用密碼就能進入 console。

    ( http://docs.amazonwebservices.com/AW...tml?putty.html )

    Creating AMI from existing instance

    Today I will describe in short how to create an AMI instance of EC2 and than upload it to S3 server. All you need to have is running instance of EC2 server (I’m using Debian) with EC2
    tools preinstalled.

    First of all, make sure that you don’t have any unnecessary files on your server filesystem which you don’t need to bundle in an image as it will only slow the process down and make
    your costs of storing backup images higher.
    Once you are sure that your instance is fine and EC2 tools are in place you have to transfer your private key file and certificate file to the server. Lets put the files under /root
    directory.
    If all is set up correctly, first of all, we create and image by running:

    ec2-bundle-vol -d /mnt -k /root/PrivateKey.pem --cert /root/Certificate.pem -u 012345678901
    

    The number after the -u flag is your Amazon account ID which you can find on the AWS website once logged in.
    Running above command will take a bit and will create a number of files under /mnt directory.
    Once we have the files and manifest ready (all happens auto-magically) we can start transferring the image onto S3 account.

    In order to transfer your image on S3 you would have to create a bucket there first, for this you can use famous firefox plugin (S3 Organizer) or do it using Affirma’s library (previous post).

    ec2-upload-bundle -b yourbucketname00404042009 -m /mnt/image.manifest.xml -a your_s3_access_key -s your_s3_secret_access_key
    

    If for some reason you encouter any problems during upload but your bundling went ok, you can retry the upload using –retry flag:

    ec2-upload-bundle -b yourbucketname00404042009 -m /mnt/image.manifest.xml -a your_s3_access_key -s your_s3_secret_access_key --retry
    

    註冊備份好的 AMI image

    ec2-register -K pk-*.pem -C cert-*.pem your-bucket/image.manifest.xml
    

    NOTES:

    * pk-*.pem, cert-*.pem 這兩個是 x509 的 key,需要透過 AWS Console 來產生。

    * 註冊後的 AMI,可以在 Elasticfox > Images > Filter: My AMIs 看到。

    安裝 EC2 API Tools

    // 下載 JRE 1.6 - jre-6u21-linux-i586.bin

    http://www.oracle.com/technetwork/ja...ads/index.html

    // 安裝 JRE 1.6

    # chmod u+x jre-6u21-linux-i586.bin
    # ./jre-6u21-linux-i586.bin
    # mv jre1.6.0_21/ /opt
    

    // 設定 JRE

    # vi /etc/profile.d/java.sh
    
    export JAVA_HOME=/opt/jre1.6.0_21
    export PATH=$JAVA_HOME/bin:$PATH 
    

    // 下載 ec2-api-tools

    http://developer.amazonwebservices.c...externalID=351

    // 安裝 ec2-api-tools

    unzip  ec2-api-tools.zip
    mv ec2-api-tools-1.3-53907/ ~/.ec2
    vi ~/.bashrc
    
    # for EC2 API Tools
    export EC2_HOME=~/.ec2
    export PATH=$PATH:$EC2_HOME/bin 
    

     

    如何增加 EBS volume 空間

    ( http://blog.edoceo.com/2009/02/amazo...w-storage.html )

    基本流程:umount > snapshot > create an new volume from snapshot > attach > FS check with e2fsck > resize > FS check again > mount

    NOTES:

    要增加一個線上系統的 EBS volume,系統必須要停機,只是參照本章節的程序,可以讓你盡可能的縮短 downtime。

    // Step1

    假設 EBS volume 是用於儲存資料庫之類,請務必關閉資料庫後,umount EBS volume 再繼續後續的作業;反之,若儲存的資料類型是屬於 off-line,且沒有鎖檔的顧慮,可以不需要 umount EBS volume。

    // Step2

     透過 EC2 command 或 Elasticfox 對 EBS volume 新增一份 snapshot

    // Step3

    透過 EC2 command 或 Elasticfox 對剛新增的 snapshot 新增一個 EBS volume

    // Step4

    透過 EC2 command 或 Elasticfox 附加(attach)新的 EBS volume 到一個 instance,例如為 /dev/sdb。

    TIPS:

    為了縮短 downtime,這裡可以另外啟動一個 instance,或者也可以用 production instance。

    // Step5

    SSH 登入 instance,執行:

    # e2fsck -f /dev/sdb
    # resize2fs -p /dev/sdb
    # e2fsck -f /dev/sdb
    # tune2fs -l /dev/sdb
    

    // Step6

    掛載 /dev/sdb,並檢查資料是否完整。

    心得總結:

    1. 依照本教學,需要 downtime 的作業只有作 snapshot 及 mount/umount 時。
    Powered by MindTouch Core