[AWSマイスターシリーズ]Amazon CloudWatch & Auto Scaling
Upcoming SlideShare
Loading in...5
×
 

[AWSマイスターシリーズ]Amazon CloudWatch & Auto Scaling

on

  • 17,313 views

 

Statistics

Views

Total Views
17,313
Views on SlideShare
10,743
Embed Views
6,570

Actions

Likes
27
Downloads
227
Comments
0

14 Embeds 6,570

http://www.hiroshix.net 3797
http://hiroshix.hatenablog.com 1349
http://blog.serverworks.co.jp 742
http://ichiy.hatenablog.com 545
http://notes.shuntak.net 53
http://kwms-aws.hatenablog.com 47
http://localhost 15
https://twitter.com 10
http://plus.url.google.com 3
http://webcache.googleusercontent.com 3
http://feedly.com 2
http://blog.hatena.ne.jp 2
http://www.google.co.jp 1
http://www.peeep.us 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

[AWSマイスターシリーズ]Amazon CloudWatch & Auto Scaling Presentation Transcript

  • 1. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.AWSマイスターシリーズCloudWatch & Auto Scaling2013.6.26アマゾンデータサービスジャパン株式会社ソリューション アーキテクト今井 雄太
  • 2. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.21. CloudWatch2. Auto Scalingアジェンダ
  • 3. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.3CloudWatch
  • 4. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Copyright © 2012 Amazon Web ServicesAWSの各種リソースをモニタリングするためのWebサービスAmazon CloudWatchとは?CloudWatch状況をレポート
  • 5. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.5Amazon CloudWatchの特徴 サービスごとに定義されたメトリクス(=監視項目) メトリクスをベースにアラームを設定可能EC2 ELB RDS
  • 6. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.6Amazon CloudWatchのアラーム設定WebサーバインスタンスのCPU利用率に対するアラームを作成• “Create Alarm”をクリック
  • 7. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.7Amazon CloudWatchのアラーム設定アラームが発動する条件を設定
  • 8. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.8Amazon CloudWatchのアラーム設定アラームが発動した際のアクションを指定• Send Notification  Create New Email Topic
  • 9. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.9アラーム時に取れるアクション通知を送る• Simple Notification Service (SNS)を使った通知を送る• 例: Emailの送信、HTTPのAPIを呼ぶ、などが可能Auto Scaling PolicyをトリガーするインスタンスをStop/Terminateする -- New!• 例:• 利用率の低いインスタンスをStopしてコスト削減• ステータスチェックが失敗したインスタンスをTerminate
  • 10. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.10請求通知機能(ビリングアラート)AWSクラウドの利用料金を監視・通知できるようにUS EastでしかAlarmが作れないが、全リージョンの合計金額で監視可能
  • 11. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.11請求通知機能(ビリングアラート)$400の利用料金を超えるとこんな通知メールがきます©2011 Amazon Web Services May not be reused or redistributed without permission
  • 12. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.12カスタムメトリクス独自のメトリクスを保存し、モニタリング、グラフ化できる“mon-put-data”コマンドラインツール“PutMetricData”もしくは、API コール“mon-list-metrics”でデータを参照サイズは最大8KB - HTTP GET40KB for - HTTP POST$ mon-put-data –metric-name RequestLatency--namespace "GetStarted“--timestamp 2010-10-29T20:30:00Z--value 87 --unit MillisecondsGetStartedという架空のアプリケーションの指定した時刻のRequestLatencyを登録する例
  • 13. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.13カスタムメトリクス値の登録例前頁と同様の例(引数に省略形)単一のデータポイントではなく統計値を登録する例$ mon-put-data -m RequestLatency -n "GetStarted" -t 2010-10-29T20:30:00Z-v 87 -u Milliseconds$ mon-put-data -m RequestLatency -n "GetStarted" -t 2010-10-29T21:30:00Z-s "Sum=577,Minimum=65,Maximum=189,SampleCount=5" -u Milliseconds注: タイムスタンプを省略すれば現時点のデータとして登録される
  • 14. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.14カスタムメトリクスの統計値取得mon-get-statsで統計値を取得可能もちろんマネージメントコンソールでも$ mon-get-stats -n GetStarted -m RequestLatency -s “Average” …
  • 15. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.15インスタンス監視用サンプルスクリプトOSでしか取れない情報をカスタムメトリクスとしてCloudWatchに登録• メモリ利用率、ディスク利用率、などなど• Cronなどで実行可• 5分おきにメモリ利用率とディスク利用率を登録するcronの設定例LinuxとWindows向けに提供• Linux: http://aws.amazon.com/code/8720044071969977• Windows: http://aws.amazon.com/code/7932034889155460*/5 * * * * ~/aws-scripts-mon/mon-put-instance-data.pl --mem-util --disk-space-util --disk-path=/ --from-cron
  • 16. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.16監視をEC2起動時に自動設定する(Linux) 1/2前頁で紹介したサンプルスクリプトhttp://aws.amazon.com/code/8720044071969977例えば mon-put-instance-data.pl --mem-util と起動するとメモリ利用率をCloudWatchにカスタムメトリクスとしてputしてくれる。Namespace: Sysmte/Linux,MetricName: MemoryUtilization,Dimension: InstanceId
  • 17. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.17監視をEC2起動時に自動設定する(Linux) 2/2IAM Roleで認証できるので、CloudWatchのput権限を持ったRole付けて下記のようなUser Data渡して起動すれば自動的にメモリとディスク利用率をCloudWatchで監視できる。#!/bin/shcd /home/ec2-userwget http://ec2-downloads.s3.amazonaws.com/cloudwatch-samples/CloudWatchMonitoringScripts-v1.1.0.zipunzip CloudWatchMonitoringScripts-v1.1.0.ziprm CloudWatchMonitoringScripts-v1.1.0.zipchown ec2-user:ec2-user aws-scripts-monecho "*/5 * * * * ec2-user /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-util --disk-space-util --disk-path=/ --from-cron" >> /etc/crontab
  • 18. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.18CloudWatchの料金もちろん初期費用無しの従量課金標準の監視は無料• EC2インスタンスの標準監視(5分間隔)含 ELB、RDSは1分間隔が無料課金対象及び料金(2013年6月現在 Tokyoリージョン)• カスタムメトリクス 1つにつき• $0.525/月• アラーム1つにつき• $0.10/月• APIリクエスト1000回につき• $0.0105(Get, List, Putごとに)• EC2インスタンスの詳細監視(1分間隔)• $3.675 (インスタンスごとに)最新の料金詳細は、こちら:http://aws.amazon.com/jp/cloudwatch/
  • 19. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.19CloudWatchの制約メトリクスの保存は2週間までEC2インスタンスのOS内の情報取得にはカスタムメトリクス登録が必要データポイントは最短で1分間隔
  • 20. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.20必要に応じて他の監視ツールによる補完ソフトウェア• Pros: 導入しやすく低コスト• Cons: 但し運用は自分で• 例:• Nagios• Cacti• Zabbix• Munin監視のサービス• Pros: 導入しやすく運用コストも不要• Cons: お任せする分、費用はかかる場合も• 例:• New Relic• satelliz
  • 21. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.CloudWatchのTIPS
  • 22. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.APIコールは少しばらつきをもたせる• カスタムメトリクスの登録や、別のシステムからの状態の取得などにおいて、同時APIコール数が多くなってくるとスロットリングが発生する。• APIコール時に数秒のジッタを挟むなどして対応する。CloudWatchのTips
  • 23. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.23Auto Scaling
  • 24. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Auto Scalingとは?定義した設定に従って自動でAmazon EC2の台数を増減させるメカニズム 需要が増加した時はシームレスに増やしてパフォーマンスを維持 需要が減少した時には自動的に減らしてコスト削減Auto ScalingとはAuto scaling GroupCloudWatchAlarmAuto ScalingElasticLoad Balancing
  • 25. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Auto ScalingはELB以外の環境でも利用できるElasticLoad BalancingSimple Queue Service
  • 26. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Netflixの実例リクエスト数の推移インスタンス数の推移CPU利用率Netflix techblogより:http://techblog.netflix.com/2012/01/auto-scaling-in-amazon-cloud.html
  • 27. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.サーバの増減に必要な情報Amazon EC2インスタンスの起動に必要な情報• AMIは?• セキュリティグループは?• キーペアは?何台インスタンスを起動すべきか• どのELB配下に?• どのAZに?• 最低何台?最大何台?どういうルールで増やすか(減らすか)• 例1: 2台増やす(2台減らす)• 例2: 50%増やす(50%減らす)Launch ConfigurationAutoscaling GroupAutoscaling Policy
  • 28. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Auto Scalingの各コンポーネントと動作LaunchConfiguration• AMI ID• Security Group• Key pair• …Auto scalingGroup• Min: X• Max: Y• ELB: elb-xxxAutoscalingPolicy1台増やすAutoscalingPolicy1台減らすhas-a1. アラーム発動2. アラームに対応するAuto ScalingPolicy駆動3. Auto ScalingがLaunchConfigurationに従ってインスタンスをグループに追加
  • 29. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Launch Configuration詳細インスタンスの起動設定を記述必須• AMI• インスタンスタイプ• Security group(s)任意• Keypair名• IAM Profile• kernel id• RAMDISK ID• Spot Price• Block Device Mappings• user-data• ebs-optimized• Detailed MonitoringAuto scaling GroupLaunch ConfigurationAdd!Auto ScalingどのAMIからどんな設定で起動するかを決めるインスタンス起動時の設定
  • 30. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Auto Scaling GroupAuto scaling GroupAdd!Auto Scaling起動しているインスタンスグループの設定必須• Launch Configuration• インスタンス最大数• インスタンス最小数• Availability Zones任意• Tag• VPC• Termination Policy• Health Check Type• Desired Capacity• Health Check Grace Period• Load Balancer起動するインスタンス数などの設定min maxDesiredcapacity
  • 31. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Auto Scaling PolicyAuto scaling GroupAdd!Auto Scalingインスタンス追加/削除時の挙動の設定Auto Scaling Group辺り25個までAdjustする台数最小Adjust台数Adjust Type• ChangeInCapacity: X台増減• ExactCapacity: X台に指定• PercentChangeInCapacity: 現キャパシティに対してX%増減スケール時の動作設定
  • 32. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Auto Scalingの設定手順(1/3)Auto ScalingのCLIツールを取得しておく• http://aws.amazon.com/developertools/2535• AWSの新CLIでも実施可能ですが、現状(2013/6)まだドキュメントが揃っていないのでこちらのツールでご案内します。まずはLaunch Configを作る$ as-create-launch-config LAUNCH_CONFIG_NAME--image-id hogehoge #AMIのID--instance-type c1.mediuma #インスタンスタイプ--group fugafuga #セキュリティグループ名--key foo #keypair名
  • 33. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Auto Scalingの設定手順(2/3)次はAuto Scaling Group作る• これが完了した時点でAuto Scaling Groupの設定に基いてインスタンス群が立ち上がってくるAuto Scaling Policy作る$ as-create-auto-scaling-group AUTO_SCALING_GROUP_NAME--launch-configuration LAUNCH_CONFIG_NAME # launch config名--min-size 4 # 最小台数--max-size 8 # 最大台数$ as-put-scaling-policy POLICY_NAME--type ChangeInCapacity #Scaling Type--auto-scaling-group AUTO_SCALING_GROUP_NAME #ASG名--adjustment 3 #スケールアクションごとのアジャスト値
  • 34. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.最後にCloudWatchのアラームをAuto Scaling Policyに設定するAuto Scalingの設定手順(3/3)
  • 35. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Auto Scalingの設定手順次はAuto Scaling Group作る• これが完了した時点でAuto Scaling Groupの設定に基いてインスタンス群が立ち上がってくるAuto Scaling Policy作る$ as-create-auto-scaling-group AUTO_SCALING_GROUP_NAME--launch-configuration LAUNCH_CONFIG_NAME # launch config名--min-size 4 # 最小台数--max-size 8 # 最大台数$ as-put-scaling-policy POLICY_NAME--type ChangeInCapacity #Scaling Type--auto-scaling-group AUTO_SCALING_GROUP_NAME #ASG名--adjustment 3 #スケールアクションごとのアジャスト値
  • 36. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Scaleしなくても Auto ScalingAuto Healingとして利用• Min N, Max Nとして設定すればN台のHealthyなインスタンスをキープAuto Scaling Groupをまとめて監視minmaxDesiredcapacity
  • 37. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.オンデマンドでAuto ScalingAuto Scaling Groupのdesired capacityを利用するとある程度手動でEC2の台数をコントロールできるDesired Capacityとは、「いま起動しておいてほしい台数」Auto Scaling Groupの最小台数と最大台数の間で設定可能。上記のコマンドだと、一旦5台起動している状態になるが、その後はポリシーに沿ってスケールアウト/インする。$ as-set-desired-capacity AUTOSCALING_GROUP_NAME --desired-capacity 5min maxDesiredcapacity
  • 38. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.スケジュールに従ってAuto ScalingAuto Scalingはスケジュールベースでも設定可能$ as-put-scheduled-update-group-action ScaleUp --auto-scaling-group AUTO_SCALING_GROUP --start-time "2013-05-12T08:00:00Z" --desired-capacity 3$ as-put-scheduled-update-group-action scaleup-schedule-year --auto-scaling-group AUTO_SCALING_GROUP --recurrence “30 0 1 1,6,12 0” --desired-capacity 3Auto Scaling Groupに単発スケジュールを追加Auto Scaling Groupに再帰的スケジュールを追加Auto Scaling Groupには複数のスケジュールを追加できる下記のコマンドで現在の設定を確認できる$ as-describe-scheduled-actions --auto-scaling-group AUTO_SCALING_GROUP--headers詳細http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/schedule_time.html
  • 39. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.負荷ベースとスケジュールベースの使い分け予測できる負荷はスケジュールベースで対応• バッチ処理• 予定されたメディア露出予測不可な負荷については負荷ベースのスケーリングで保険をかける• 必要に応じてスケジュールベースのスケールをしかけた上で、突発的な負荷に対する対策として負荷ベースの設定をしておく
  • 40. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Auto Scalingの高度な操作Auto Scaling Group内のインスタンスのHealthyステータスを外部から制御• 例:他の監視ツールやインスタンス自身のヘルスチェック結果をAuto Scalingに反映させる場合など一時的にAuto Scalingの動きを止める• 例:不具合インスタンスの調査を行う時など$ as-set-instance-health i-123abc45d –-status Unhealthy$ as-suspend-processes MyAutoScalingGroup
  • 41. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.ELBのヘルスチェックと連携ELBが行ったヘルスチェックの結果に基づいてAutoScalingを駆動• 例:アプリケーションレベルのヘルスチェック結果を反映したインスタンスの健全性維持Grace Periodとは?• Auto ScalingがELBのヘルスチェックの結果を無視する期間• 起動直後でELBから見たStatusがOutOfServiceの場合など• 上記の例ではインスタンス起動後300秒間はAuto ScalingはUnhealthyと見なさない$ as-update-auto-scaling-group my-test-asg-lbs –-health-check-type ELB–-grace-period 300
  • 42. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Terminateするインスタンスの選択標準では以下の手順1. (Terminationを行うAZの中で)最も古いLaunchConfigurationを使うインスタンスを選択2. 同条件のインスタンスが複数いたら次の課金が始まるタイミングが最も近いインスタンスを選択3. さらに同条件のインスタンスが複数いたらランダムに選択してTerminateカスタムポリシーも選択可(次ページ)
  • 43. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.カスタムTermination Policy下記のポリシーを1つまたは複数指定可• OldestInstance / NewestInstance — インスタンスの起動時刻を参照して、最も古い / 新しいインスタンスを優先的にTerminate• OldestLaunchConfiguration — 最も古いLaunch Configurationを使うインスタンスを優先的にTerminate• ClosestToNextInstanceHour — 次の課金が始まる時刻が最も近いインスタンスを優先的にTerminate• Default --- 標準動作複数指定した場合は指定順で適用全ポリシーを適用しても複数インスタンスが候補になったらランダムに選択
  • 44. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.44AutoscalingにスポットインスタンスAutoscalingのローンチコンフィグを作成時に”—spot-price”オプションを設定> as-create-launch-config spotlc-5cents --image-id ami-XXXXXX--instance-type m1.small --spot-price "0.05"インスタンスがTerminateされてもDesired Capacityを満たすよう継続的に入札が行われるスポット価格が入札額を上回っている場合はDesired Capacityを満たせないScale Outパターンhttp://aws.clouddesignpattern.orgスポットインスタンスに関するマイスターWebinarのリンク:http://www.slideshare.net/AmazonWebServicesJapan/aws-16524731
  • 45. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.ElasticBeanstalkのWeb UI45Autoscalingの閾値を設定変更  CPUUtilization変更  PercentClick変更  70変更  30
  • 46. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.ASGARD by Netflixhttps://github.com/Netflix/asgard/wiki/Quick-Start-Guide
  • 47. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.コードのデプロイメント
  • 48. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.48Auto Scaling使うとEC2の起動タイミングは任意に制御できない
  • 49. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.49うまく利用するにはアプリデプロイの自動化をしておく必要がある
  • 50. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.50Auto Scalingでデプロイコード コード新規サーバーをデプロイAuto ScalingではAMIからサーバーをデプロイするところまで面倒見てくれるAMIAMIにコードを埋め込んでおけばOK?ひとまずOK。ただし、コードを修正するたびにAMIを新しくする必要があるので、頻繁なデプロイを行う際は更に対策が必要。
  • 51. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.51Auto Scalingでデプロイコード修正のたびにAMIを新しくするのは手間がかかる。PHPやRuby, node.jsなどのLLを利用しているのであれば・・コード コード新規サーバーをデプロイAMI デプロイ時にSCMから最新のコードを取ってくるようにしよう
  • 52. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.52Auto ScalingでデプロイLaunch Configurationに以下のようなuser dataを渡しておけば起動時にgitから最新のコードを取得してきてくれる。上記は前提として、コードが”/var/www/html”にあって、gitで管理されている場合の話。より柔軟なデプロイについては下記を参照http://www.slideshare.net/AmazonWebServicesJapan/20130506-23096544#!/bin/shcd /var/www/htmlsudo -u httpd-user git pullservice httpd restart
  • 53. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Auto ScalingのTIPS
  • 54. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.トリガーにするメトリクスはアプリ次第。• 一般的にはCPUが多い。• WebSocketなどの環境ではメモリや接続数も重要。しきい値もアプリ次第だが、最初は厳し目に設定しておいて、様子を見ながらゆるくしていくのがベター。AZのキャパシティは均等に• 利用するAZの倍数で増やし、減らす、等
  • 55. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.Auto Scalingの発動はSNSでキャッチできる• as-put-notification-configuration コマンドを利用することにより、既存のSNSトピックに対してオートスケーリングイベントが発生したときに通知を出すように設定ができるAuto Scalingは時間がかかる• 基本的には、オートスケーリングは1台ずつのEC2増減をイテレーションで実行していく。• 3台増やす際には、1台増やして、cool down periodを待って、2台目増やして・・・という具合• as-set-desired-capacityを--no-honor-cooldownオプション付けて発行すると、一度に複数台の増減をすることも可能。
  • 56. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.増やす時は速く• サービスのレスポンスを落とさずに減らす時はゆっくりそれって本当にAuto Scaling必要か?ともう一度確認してみる• Auto Scalingは銀の弾丸ではないので、どんなユースケースにもマッチするわけではない。• デプロイや監視、しきい値設定など、それなりに手間を掛けて育てる必要がある。• 最初は、緩めのしきい値でアラームからメールを飛ばして対応、から始めるのもアリ。
  • 57. © 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.57ご参加ありがとうございました。トレーニングコース(有料)もあります!AWS実践入門1トレーニングAWS実践入門2トレーニングArchitectingon AWSトレーニングAWS 認定ソリューションアーキテクト-アソシエイトレベル認定試験http://aws.amazon.com/jp/training/