| 131 | = 【補充:使用 Amazon EC2】 = |
| 132 | * 操作 EC2,有三種方法可以操作: |
| 133 | 1. Amazon EC2 API tools (指令介面) |
| 134 | 2. Elastic (Firefox 外掛) |
| 135 | 3. Management Console (網頁介面)[[BR]][[Image(Amazon.png)]] |
| 136 | * 這邊簡單介紹 API 的使用方法,剛好可以跟 Eucalyptus 做比較 |
| 137 | 0. 系統需安裝好 JAVA 和設定 JAVA_HOME (因 API 使用的 lib 都是 jar 檔) |
| 138 | 1. 安裝 [http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351&categoryID=88 API] |
| 139 | {{{ |
| 140 | $ wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip |
| 141 | $ unzip ec2-api-tools.zip |
| 142 | }}} |
| 143 | 2. 下載 Amazon 給你的 Security Credentials (下載 X.509 Certificate 和 private key),將這兩個檔案放置 ec2 目錄下 |
| 144 | 3. 設定環境變數 |
| 145 | {{{ |
| 146 | $ cd ec2 |
| 147 | $ echo "export EC2_HOME=~/ec2-api-tools-1.3-51254/bin" >> ~/ec2/ec2rc |
| 148 | $ echo "export EC2_PRIVATE_KEY=~/ec2/pk-APKAIBFA52PVKFBXMUJA.pe" >> ~/ec2/ec2rc |
| 149 | $ echo "export EC2_CERT=~/ec2/cert-M2CNECVUTHTPYJHPZVCTSBQTBF3KWAPW.pem" >> ~/ec2/ec2rc |
| 150 | $ echo "export PATH=$PATH:~/ec2-api-tools-1.3-51254/bin" |
| 151 | |
| 152 | $ source ~/ec2/ec2rc |
| 153 | }}} |
| 154 | 4. 測試 |
| 155 | {{{ |
| 156 | $ ec2-version |
| 157 | 1.3-51254 2009-11-30 |
| 158 | |
| 159 | $ ec2-describe-availability-zones |
| 160 | AVAILABILITYZONE us-east-1a available us-east-1 |
| 161 | AVAILABILITYZONE us-east-1b available us-east-1 |
| 162 | AVAILABILITYZONE us-east-1c available us-east-1 |
| 163 | AVAILABILITYZONE us-east-1d available us-east-1 |
| 164 | |
| 165 | $ ec2-describe-regions |
| 166 | REGION eu-west-1 ec2.eu-west-1.amazonaws.com |
| 167 | REGION us-east-1 ec2.us-east-1.amazonaws.com |
| 168 | REGION us-west-1 ec2.us-west-1.amazonaws.com |
| 169 | REGION ap-southeast-1 ec2.ap-southeast-1.amazonaws.com |
| 170 | |
| 171 | $ ec2-describe-images -a |
| 172 | $ ec2-describe-images -o amazon |
| 173 | |
| 174 | $ ec2-add-keypair mykeypair |
| 175 | //將畫面顯示的 key 資訊存到 mykeypair.pem |
| 176 | $ chmod 600 mykeypair.pem |
| 177 | $ ec2-describe-keypairs |
| 178 | |
| 179 | $ ec2-run-instances ami-225fba4b -k mykeypair |
| 180 | RESERVATION r-de50fab5 997070620294 default |
| 181 | INSTANCE i-e93ddf83 ami-225fba4b pending mykeypair 0 m1.small 2010-06-23T07:24:01+0000 us-east-1d monitoring-disabled instance-store |
| 182 | |
| 183 | $ ec2-describe-instances |
| 184 | RESERVATION r-de50fab5 997070620294 default |
| 185 | INSTANCE i-e93ddf83 ami-225fba4b ec2-204-236-192-34.compute-1.amazonaws.com ip-10-196-215-0.ec2.internal runningmykeypair 0 m1.small 2010-06-23T07:24:01+0000 us-east-1d monitoring-disabled 204.236.192.34 10.196.215.0 instance-store |
| 186 | |
| 187 | $ ssh -i mykeypair.pem root@ec2-204-236-192-34.compute-1.amazonaws.com |
| 188 | |
| 189 | $ ec2-terminate-instances i-e93ddf83 |
| 190 | INSTANCE i-e93ddf83 running shutting-down |
| 191 | }}} |
| 192 | 5. 其他的功能,有興趣的學員可自行玩玩 |
| 193 | ---- |