query: tag:EC2

EC2のSpotインスタンスの価格変動がどんなものか把握するのが面倒だったので、直近の相場をグラフで表示するwebサービスを作りました。

ss

相場はリージョン、OS毎に違うので、適当な組み合わせを選択してみてください。
データはだいたい5分ごとに更新されています。

実は SpotHistory.com という良さそうな既存サービスがあったのですが、
なぜか1月ぐらいでデータ更新が止まっていて残念な感じだったので、
適当に作ったほうが早そうだということで製作しました。

posted by genki genki on Fri 26 Aug 2011 at 07:32 with 0 comments

しばらく前から安定性が悪くなってきたのですが、ここに来て頻繁にPassengerのプロセスが暴走するようになってきました。

  • ruby 1.8.7 (2009-04-08 patchlevel 160) [i686-linux]
  • Passengerのバージョンは2.2.8
  • Rails 2.3.5

プログラムやシステム構成はここしばらくほとんど変えておらず、トラフィックも大きな変動はないので、うわさのEC2のサービス劣化の影響でしょうか。

posted by genki genki on Thu 25 Feb 2010 at 02:06 with 0 comments

Reserved Instanceを使ってみるために、ec2-api-toolsをアップデートしてみました。

pre>>
% wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip
% unzip ec2-api-tools.zip
<<--

/usr/local/ec2-api-toolsあたりに移動させて、
環境変数EC2_HOMEを設定します。

Reserved Instanceを使う場合、最初に、自分が使いたいインスタンスが提供されているかどうか、以下のようにして調べます。

pre>>
% ec2drio -z us-east-1b -t m1.small
OFFERING 3a98bf7d-96c3-4d2f-a263-123fa6b46d61 us-east-1b m1.smal3y 500.0 0.03 Linux/UNIX
OFFERING 60dcfab3-a56c-4092-8c90-3677e9da02b7 us-east-1b m1.smal1y 325.0 0.03 Linux/UNIX
<<--

ゾーンとタイプを指定しています。

2カラム目にあるUUID風の文字列がoffering IDなので、これを覚えておきます。

続いて、実際にReserved Instanceを購入します。

pre>>
% ec2prio -c 1 -o 60dcfab3-a56c-4092-8c90-3677e9da02b7
<<--

-cで台数、-oで先ほどのoffering IDを指定します。
これで購入完了です。

pre>>
% ec2dri
RESERVEDINSTANCES (*****) us-east-1b m1.small Linux/UNIX 1y 0.03 325.0 1 2009-03-27T06:51:18+000payment-pending
<<--

しばらくすると(この記事を執筆時点では結構待ちました)、payment-pendingがactiveになります。

あとは、us-east-1bで、通常通りにm1.smallのインスタンスを起動すれば、
自動的にReserved Instanceの料金プランが適用されるようです。

See Also

posted by genki genki on Fri 27 Mar 2009 at 15:44 with 0 comments

Macの開発環境にEC2 ami toolsを入れる手順のメモ。
今回はmacportsのrpmを使ってインストールしました。

pre>>
% wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.noarch.rpm
% sudo rpm -i ec2-ami-tools.noarch.rpm --nodeps --ignoreos
<<--

これだけです。

あとは、.zshrcなどで、RUBYLIB環境変数に/usr/lib/site_rubyを加えておきます。

See Also

posted by genki genki on Mon 9 Mar 2009 at 14:34 with 0 comments

EC2でパッケージのRubyではなく、srcからRubyを入れて使う場合、
イメージの状態によってはAMI-toolsがLOAD_PATH不足で正しく起動できない場合がある。

その場合、以下のようにAMI-toolsのスクリプトを書き換える。

/usr/local/bin/ec2-bundle-vol

sh>>
#!/bin/bash
ruby -I/usr/lib/site_ruby /usr/lib/site_ruby/aes/amiutil/bundlevol.rb $*
<<--

-IオプションでLOAD_PATHを補っている。

posted by genki genki on Fri 22 Aug 2008 at 04:14 with 0 comments

EC2onRailsのAMIイメージはUbuntuのパッケージRubyが入っていますが、
これを最新のruby-1.8.7 p17に置き換える手順のメモです。

  1. 入っているRubygemsを全てアンインストール
  2. rubyをpurge。その結果、
    pre>>
    bash: /usr/local/ec2onrails/bin/rails_env: /usr/bin/ruby: bad interpreter: No such file or directory
    <<--
    というエラーが出るようになるが、とりあえず無視。
    ruby
    irb
    irb1.8
    rdoc
    rdoc1.8
    ri
    ri1.8
    ruby1.8-dev
    このあたりのパッケージを全部削除する。
  3. /usr/local/ec2onrails/bin/rails_env のshbangを/usr/local/bin/ruby
    に書き換える。
  4. ruby-1.8.7 p17 をソースから入れる
  5. rubygemsをインストール
  6. 必要なGemをインストール

大体こんな感じですね。

posted by genki genki on Thu 12 Jun 2008 at 21:38 with 0 comments

EC2onRailsの0.9.8.1を使って、0.9.7時代のAMIイメージに
cap deployしようとした場合、なぜか/etc/init.d/以下のいくつかの
起動スクリプトの実行パーミッションが剥奪されてしまい、
デプロイ処理の途中でエラーが起きて中断してしまうようです。

とりあえず対処療法として、Capfileの中で

ruby>>
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
load 'config/deploy'
gem 'ec2onrails', '=0.9.7'
require 'ec2onrails/recipes'
<<--

のように0.9.7を明示的に指定するようにして回避しています。
本家筋のAMIイメージへの変更をマージしていく必要がありそうですね。

posted by genki genki on Tue 27 May 2008 at 11:31 with 0 comments

本家のフォーラム
Thread: ec2-bundle-vol fails
にも上がっていますが、EC2のイメージを作成する時にrsync関連の
警告が出ることがあるようです。

NOTE: rsync with preservation of extended file attributes failed. Retrying rsync
without attempting to preserve extended file attributes...
NOTE: rsync seemed successful but exited with error code 23. This probably means
that your version of rsync was built against a kernel with HAVE_LUTIMES defined,
although the current kernel was not built with this option enabled. The bundling
process will thus ignore the error and continue bundling. If bundling completes
successfully, your image should be perfectly usable. We, however, recommend that
you install a version of rsync that handles this situation more elegantly.

警告は出るものの、イメージ自体は作成されている模様。

posted by genki genki on Thu 22 May 2008 at 11:13 with 0 comments

EC2onRailsを使って、既存のRailsアプリをEC2上で動くようにするための手順のメモです。
EC2onRailsを複数アプリ対応にする方法のメモ
を適用した状態を想定しています。

  1. config/deploy.rb を用意
    サンプルファイルはこちら
    :server_config_files_rootを適当に設定し、指定したPATHにディレクトリを作る。
  2. Capfileを以下のような感じで用意。
    rails>>
    load 'deploy' if respond_to?(:namespace) # cap2 differentiator
    load 'config/deploy'
    require 'ec2onrails/recipes'

set :deploy_to, "/mnt/app/"

override default start/stop/restart tasks

namespace :deploy do
desc <<-"DESC"
Overrides the default Capistrano deploy:start, directly calls
/etc/init.d/mongrel #{application}
DESC
task :start, :roles => :app do
run "/etc/init.d/mongrel start #{application}"
end

desc <<-"DESC"
Overrides the default Capistrano deploy:stop, directly calls
/etc/init.d/mongrel #{application}
DESC
task :stop, :roles => :app do
run "/etc/init.d/mongrel stop #{application}"
end

desc <<-"DESC"
Overrides the default Capistrano deploy:restart, directly calls
/etc/init.d/mongrel #{application}
DESC
task :restart, :roles => :app do
run "/etc/init.d/mongrel restart #{application}"
end
end
<<--
EC2onRailsが上書きしたデフォルトのタスクをさらに上書きして、複数アプリ対応できるようにしています。
 3. 最後に、mongrel_clusterを使うので、config/mongrel_cluster.yml
ファイルを用意します。

yaml>>

cwd: /mnt/app//current
port: 8000
environment: production
pid_file: log/mongrel.pid
servers: 3
<<--
ポート番号はサーバをシェアするアプリ間で適当に割り振ります。

あとは、以下のコマンドを実行してデプロイします。

pre>>
cap ec2onrails:setup
cap deploy:cold
<<--

最後に、EC2onRailsを複数アプリ対応にする方法のメモに書いてあるような、EC2上のApacheのVirtualHostの設定と、ProxyBalancerの設定を行います。

posted by genki genki on Wed 21 May 2008 at 21:02 with 0 comments

EC2onRailsでpostfixを使ってaliasesを設定する方法のメモです。

まずはaliasesの定義ファイルの場所ですが、/etc/aliasesにあります。
これを開くと

pre>>
postmaster: root
<<--

というようなエイリアスのリストがあるので、これを編集します。
あて先が複数ある場合はコンマで区切ります。
"@"や":"などの記号を含む場合は二重引用符で囲みます。

あて先に指定できる項目は以下の通り。

  • ユーザ名 or メールアドレス 所定のあて先に転送されます。
  • PATH 指定のファイルに追記されます。
  • | command 指定したコマンドが実行され、標準入力に渡されます。

他にもありますが、詳細は下記のSee Alsoを参考にしてください。

編集し終わったら、DBを更新するために以下のコマンドを実行します。

pre>>

postalias /etc/aliases

<<--

以上で完了。

See Also

posted by genki genki on Fri 9 May 2008 at 17:27 with 0 comments

Amazonからrpmパッケージを持ってきてインストールするメモ。

sh>>

cd /usr/src

wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.noarch.rpm

alien --to-deb ec2-ami-tools.noarch.rpm

dpkg -i ec2-ami-tools_1.3-20042_all.deb

<<--

でOK。/usr/lib/site_ruby/の下に当該ファイル群がインストールされています。

See Also

posted by genki genki on Wed 7 May 2008 at 17:32 with 0 comments

EC2onRails
は、EC2上でRailsアプリケーションを走らせる環境として提供されている
AMIイメージと管理用スクリプト群です。
これを使うと、非常に簡単にRailsアプリケーションをEC2上で動かす
環境を用意することが出来ます。
基本的にCapistranoのタスクとして実装されていて、

sh>>
% cap deploy
<<--

するだけで、開発環境からEC2上にデプロイが完了します。

EC2onRailsは非常に便利でありがたいのですが、
基本的に1アプリケーション1インスタンスの構成でデプロイされるように
なっているので、ちょっとしたサンプルアプリケーションや、
内々に評価中のアルファ版のサービスなどを気軽にデプロイするのには、
コスト面が気になるところです。

ということで、1インスタンスで複数アプリケーションをデプロイするために
施した修正のメモを以下に書いておきます。

  • EC2onRailsの各種設定ファイルのデプロイ先を/mnt/app/から
    /mnt/app/<app_name>に変更
  • /etc/init.d/mongrel の中身を修正し、第二引数でアプリケーション名を
    受け取るようにする。
    • 受け取ったアプリケーション名を元に、/mnt/app/<app_name>/currentにcdして、config/mongrel_cluster.ymlを参照してmongrel_rails cluster::restart するようにする。
  • /etc/apache2/conf.d/の中身をapp.proxy_frontend.confとcharset以外削除。
  • /etc/apache2/sites-enabled/の中身を削除し、アプリケーションごとのVirtualHostの設定を記述したファイルを<app_name>という名前で作成する。
    pre>>
    ServerSignature Off

<VirtualHost *:80>
ServerName blog.s21g.com

(---略---)

DocumentRoot /mnt/app/blog/current/public

<Directory "/mnt/app/blog/current/public">
(---略---)

<Proxy balancer://mongrel_cluster>
BalancerMember http://127.0.0.1:8000
BalancerMember http://127.0.0.1:8001

(---以下略---)
<<--

  • アプリケーションごとに80n* のようなポート番号を割り当てるとか。

大体こんな感じで複数アプリ対応化できた気がします。
何か漏れがあるのを思い出したら追記します。

See Also

posted by genki genki on Wed 7 May 2008 at 15:25 with 2 comments

EC2のインスタンスのイメージをバックアップする手順のメモです。
以下はEC2上のインスタンスにSSHでログインしての作業です。
まずは以下のようなコマンドでイメージを書き出します。

shell>>

ec2-bundle-vol -d /mnt -k /mnt/pk-XXXXXXXXXX.pem -c /mnt/cert-XXXXXXXXXX.pem -u <AWSのユーザID>

<<--

AWSのユーザIDはAWSの「Your AWS Profile」のページから参照できます。
XXXX-XXXX-XXXXのような数字の羅列でした。

結果として、/mnt/の下にimage.manifest.xmlimage.part.XXというファイルが書き出されます。

処理が終了するまでの間に、10分弱ぐらいかかったかな。
Have a coffee break!

続いてはイメージのS3へのアップロードです。以下のコマンドで先ほど生成されたファイル群をS3にアップロードします。

shell>>

ec2-upload-bundle -b s21g-ubuntu -m /mnt/image.manifest.xml -a <アクセスキー> -s <秘密アクセスキー>

<<--

アクセスキーと秘密アクセスキーはAWSのページで確認してください。
-bで指定した名前は、S3のバケット名になります。

こちらは2分ぐらいで終了。トータルで10分ちょっとですね。

最後に、ローカル環境から以下のコマンドを実行して、作成したイメージを登録します。

sh>>
% ec2-register s21g-ubuntu/image.manifest.xml
IMAGE ami-8a789de3
<<--

これによって、AMIを指定してインスタンスを起動できるようになります。

posted by genki genki on Fri 25 Apr 2008 at 16:55 with 0 comments

近々使うかもしれないので。

http://www.amazon.com/gp/browse.html?node=201590011

###用語

  • Amazon Elastic Compute Cloud (Amazon EC2)
  • Amazon Machine Image (AMI)
  • Amazon S3 (Amazon Simple Storage Service)

###まずはGettingStartedから
http://docs.amazonwebservices.com/AWSEC2/2008-02-01/GettingStartedGuide/
(注)下記は2006年10月12日時点での記事ですが、内容がGettingStartedと今も大体同じ感じです(コマンドもそのままぽい)。
ここギコ!さん乙!
http://kokogiko.net/m/archives/001772.html

###必要なもの

  • SSHクライアント
  • JRE:version 5

###何ができるのか
defaltで用意されているイメージに自由にツールインストールできる。
ただし、インスタンスを止めてしまうと加えた変更は全て破棄されてしまう。加えた変更も併せ再現可能な状況にしようと思えば、現在のインスタンスの状況をイメージ化して登録すればよい。

###Refs

###疑問
AMIインスタンスの再起動とOSの再起動って違うんだろうか。後で調べる。

Amazon EC2を人に勧めると必ず言われるのが、「インスタンスを再起動したらディスクが消えるのが怖い」。

これは「インスタンス」を再起動であって、OSを再起動してもディスクは消えないのだが、確かに起動に必要なファイルを消してしまって、OSが起動できなくなってしまうと、確かに取り出せなくなってしまいます。
http://blog.masuidrive.jp/index.php/2008/04/14/ec2-ersistent-storage/

posted by satoko satoko on Tue 22 Apr 2008 at 07:33 with 3 comments

AWS (Amazon Web Service) including S3 and EC2 had downed again (See here)

We may have a need of balancing our services over the several EC2 clones.
Fortunately, there have already been several computing clouds on the Internet.
But there are no compatibilities between them.
Their interfaces should be standardized.
I think that the spec would become similar to EC2 because of its accumulated experiences.

BTW, I can't stop recalling the story of Permutation City of Egan.

posted by takiuchi takiuchi on Tue 8 Apr 2008 at 08:58 with 0 comments
posted by genki genki on Sun 6 Apr 2008 at 06:49 with 0 comments