Skip to content

ELBのEC2のOut of Serviceへの移行について調査

mechamogera edited this page Sep 12, 2012 · 19 revisions

実験1

  • ELBに紐付いたEC2インスタンスのサーバーを停止させてOut of Serviceにする
  • 結果:サーバーが停止してOut of Serviceと判断されるまでリクエストが飛んでエラーとなる期間がある

前準備

  • EC2インスタンス1準備(Amazon Linux)
  • httpd導入
$ sudo yum install -y httpd
  • httpdファイル配置
$ echo a | sudo tee /var/www/html/index.html
$ sudo touch /var/www/html/ping
  • httpd起動
$ sudo /etc/init.d/httpd start
  • EC2インスタンス2準備(Amazon Linux)
  • EC2インスタンス1と同様に準備
  • ただし、httpdファイルは以下のように配置
$ echo a | sudo tee /var/www/html/index.html
$ sudo touch /var/www/html/ping

実験手順

  • クライアントから以下のrubyスクリプトを実施
require 'rest-client'

while true
  begin
    res = RestClient.get( 'http://testELB-181078839.ap-northeast-1.elb.amazonaws.com/index.html' )
    puts res.body
  rescue => e
    p e.message
  end
end
  • EC2インスタンス1でhttpdを停止
$ sudo /etc/init.d/httpd stop

実験結果

  • クライアントの出力が以下のようになった
# aとbが交互に
a
b
a
b
"Server broke connection"
b
"Server broke connection"
b
"Server broke connection"
b
b
# bが続く

実験2

前準備

  • 実験1と同じ

実験手順

  • 実験1と同じようにスクリプトを動かすが、EC2インスタンス1でhttpdを停止するのではなくhealth check用のファイルを取り除く
$ sudo mv /var/www/html/ping{,.bak}

実験結果

  • クライアントの出力が以下のようになった
# aとbが交互に
a
b
a
b
b
# bが続く
Clone this wiki locally