2013/03/31

AWS Auto Scaling 自動擴展(一)

AWS Auto Scaling 是用來處理 application 擴充性問題,根據當下的忙碌狀況來增減 instance。需要搭配 ELB 或是 CloudWatch 使用。

ELB (Elastic Load Balance) 的原理類似 DNS round-robin,在同一個 domain name 上綁定多組 instance IP,讓外部的 request 可以分散到各 instance 去處理。ELB 也會定期對底下的 instance 做 healthy check,若發現 instance 有問題,則 dispatch 時就會掠過這台,而 Auto Scaling 也會根據這個結果去 launch 新的 instance 並掛載 ELB 底下。ELB 下的 instance 是沒有上限值的。




Setup Auto Scaling

Auto Scaling 目前尚未提供 web 界面,只能用 command line 的方式去設定,在開始之前,請確定已經透過 web 設定好:
  • Create Image for a instance (ImageID: ami-7061fb19) 
  • Create ELB (with/without instance) (Load Balance Name: webserver)

Create auto scaling configuration
$ aws autoscaling create-launch-configuration \
--launch-configuration-name as-config \
--image-id ami-7061fb19 --instance-type t1.micro

Show the auto scaling configuration
$ aws autoscaling describe-launch-configurations

Create auto scaling group
$ aws autoscaling create-auto-scaling-group \
--auto-scaling-group-name as-group \
--launch-configuration-name as-config \
--availability-zones us-east-1a \
--load-balancer-names webserver \
--max-size 3 --min-size 2 \
--default-cooldown 300
這個指令一執行,auto scaling 就被啟動了。

為了避免 instance 重複被 launch,有個時間參數設定很重要:
  • --default-cooldown (integer)
    The amount of time, in seconds, after a scaling activity completes before any further trigger-related scaling activities can start.
這個時間至少要大於服務啓動的時間
服務啓動時間 = EC2 開機時間 + Web Service 啓動時間 (+ ELB check health 的時間)

Show the auto scaling group
$ aws autoscaling describe-auto-scaling-groups

照上面的設定最少會有 2 台 instance 在 list 上
            "Instances": [
                {
                    "InstanceId": "i-e0a77c8c",
                    "AvailabilityZone": "us-east-1a",
                    "HealthStatus": "Healthy",
                    "LifecycleState": "Pending",
                    "LaunchConfigurationName": "as-config"
                },
                {
                    "InstanceId": "i-e2a77c8e",
                    "AvailabilityZone": "us-east-1a",
                    "HealthStatus": "Healthy",
                    "LifecycleState": "Pending",
                    "LaunchConfigurationName": "as-config"
                }
            ],

Verify
可以試著把任一台 instance stop,auto scaling 機制偵測到後又會 launch 一台新的,並且掛到 ELB 底下。




Monitor ELB healthy

Create auto scaling group 時,預設是對每個 instance 做 healthy check,若要改為 check ELB,則要加上兩個參數:
  • --health-check-type ELB
  • --health-check-grace-period 60
$ aws autoscaling create-auto-scaling-group \
--auto-scaling-group-name as-group \
--launch-configuration-name as-config \
--availability-zones us-east-1a \
--load-balancer-names webserver \
--max-size 3 --min-size 2 \
--health-check-type ELB --health-check-grace-period 300

Verify
可以試著讓 ELB 的狀態變成 unhealthy,在此我的 ELB 狀態是去 check 各 instance 的 web service,所以我把全部的 instance web service都停止,果真會掛 instance 上來。

但我對於這邊的行為還沒完全掌握,當沒有一台 instance 能夠服務時,那些不能服務的 instance 從 ELB list 中移除並 terminate,auto scaling 會 detect 到,並且循序 launch 一台新的 instance,直到 ELB 正常為止,但如果 service 是因為太忙碌不是掛掉,應該要加更多的 instance 上去而不是移除。



Stop Auto Scaling

Update group setting
$ aws autoscaling update-auto-scaling-group \
--auto-scaling-group-name as-group \
--min-size 0 --max-size 0

如果不更新就直接刪除,會有 error message: You cannot delete an AutoScalingGroup while there are instances or pending Spot instance request(s) still in the group.

Detete auto scaling group
$ aws autoscaling delete-auto-scaling-group --auto-scaling-group-name as-group

要注意一點,刪除 auto scaling group 後,所有的 instance 都會被 terminate!



參考資料


2 則留言:

  1. Actually when someone doesn't understand afterward
    its up to other visitors that they will assist, so here it takes place.


    Here is my blog post; minecraft games

    回覆刪除
  2. If you need to|you should|you have to} make advanced metallic shapes for your business, particularly three-dimensional shapes, a CNC machine is right for you. CNC machining is one of two frequent methods of creating a prototype from a digital file, and it's typically utilized in manufacturing as well as|in addition to} different industries. The different way to make a prototype is 3D printing know-how, which makes use of fused-deposition modeling to create the part or product. Besides FDM, 3D printing know-how might additionally embrace stereolithography-SLA, selective-laser sintering-SLS and selective-laser melting-SLM. The main distinction between CNC machining and guide machining is the hands-on time requirement. Since CNC machining makes use of automation, a single Underwear for Men skilled operator might probably run several of} machining centers.

    回覆刪除