AWS Load Balancing設定

こちらを参考にしました。


管理ツールのインストール
Elastic Load Balancing APIをダウンロード&展開
Auto Scaling APIをダウンロード&展開
Cloud Watch APIをダウンロード&展開

環境変数の設定

export EC2_REGION=ap-northeast-1b
export EC2_PRIVATE_KEY=[パス]/XXXXXXXXXXXXXXXXXX.pem
export EC2_CERT=[パス]/XXXXXXXXXXXXXXXXXX.pem
export AWS_AUTO_SCALING_HOME=[パス]/AutoScaling
export AWS_ELB_HOME=[パス]/ElasticLoadBalancing
export AWS_CLOUDWATCH_HOME=[パス]/CloudWatch
export PATH=$PATH:$AWS_AUTO_SCALING_HOME:$AWS_AUTO_SCALING_HOME/bin:$AWS_ELB_HOME:$AWS_ELB_HOME/bin:$AWS_CLOUDWATCH_HOME:$AWS_CLOUDWATCH_HOME/bin


elb-create-lb HogeLB --headers --listener "lb-port=80, instance-port=80, protocol=http" --availability-zones ap-northeast-1a

elb-configure-healthcheck HogeLB --headers --target "http:80/index.html" --interval 30 --timeout 3 --unhealthy-threshold 5 --healthy-threshold 5

as-create-launch-config HogeLaunchConfig --image-id ami-XXXXXX --instance-type t1.micro --key XXXXXXXXX --group HogeAutoScalingG

as-create-auto-scaling-group HogeAutoScalingG --launch-configuration HogeLaunchConfig --availability-zones ap-northeast-1a --min-size 1 --max-size 5 --load-balancers HogeLB

as-put-scaling-policy HogeScaleOutPolicy --auto-scaling-group HogeAutoScalingG --adjustment=1 --type ChangeInCapacity

mon-put-metric-alarm HogeHighCPUAlarm --comparison-operator GreaterThanThreshold --metric-name CPUUtilization --namespace "AWS/EC2" --period 60 --statistic Average --threshold 70 --evaluation-periods 1 --dimensions "AutoScalingGroupName=HogeAutoScalingG" --alarm-actions arn:was:autoscaling:XXXXXXXXXXXXXXX(前のコマンドを実行後に表示された文字列)

as-put-scaling-policy HogeScaleInPolicy --auto-scaling-group HogeAutoScalingG --adjustment=-1 --type ChangeInCapacity

mon-put-metric-alarm HogeLowCPUAlarm --comparison-operator LessThanThreshold --metric-name CPUUtilization --namespace "AWS/EC2" --period 60 --statistic Average --threshold 30 --evaluation-periods 1 --dimensions "AutoScalingGroupName=HogeAutoScalingG" --alarm-actions arn:aws:autoscaling:XXXXXXXXXXXXXXX(前のコマンドを実行後に表示された文字列)