heat_template_version: 2014-10-16
description: A load-balancer server
parameters:
image:
type: string
description: Image used for servers
key_name:
type: string
description: SSH key to connect to the servers
flavor:
type: string
description: flavor used by the servers
pool_id:
type: string
description: Pool to contact
user_data:
type: string
description: Server user_data
metadata:
type: json
network:
type: string
description: Network used by the server
resources:
server:
type: OS::Nova::Server
properties:
flavor: {get_param: flavor}
image: {get_param: image}
key_name: {get_param: key_name}
metadata: {get_param: metadata}
user_data: {get_param: user_data}
networks:
- port: { get_resource: port }
member:
type: OS::Neutron::PoolMember
properties:
pool_id: {get_param: pool_id}
address: {get_attr: [server, first_address]}
protocol_port: 80
port:
type: OS::Neutron::Port
properties:
network: {get_param: network}
security_groups:
- base
outputs:
server_ip:
description: IP Address of the load-balanced server.
value: { get_attr: [server, first_address] }
lb_member:
description: LB member details.
value: { get_attr: [member, show] }
heat_template_version: 2014-10-16
description: A load-balancer server
parameters:
image:
type: string
description: Image used for servers
key_name:
type: string
description: SSH key to connect to the servers
flavor:
type: string
description: flavor used by the servers
pool_id:
type: string
description: Pool to contact
user_data:
type: string
description: Server user_data
metadata:
type: json
network:
type: string
description: Network used by the server
resources:
server:
type: OS::Nova::Server
properties:
flavor: {get_param: flavor}
image: {get_param: image}
key_name: {get_param: key_name}
metadata: {get_param: metadata}
user_data: {get_param: user_data}
networks:
- port: { get_resource: port }
member:
type: OS::Neutron::PoolMember
properties:
pool_id: {get_param: pool_id}
address: {get_attr: [server, first_address]}
protocol_port: 80
port:
type: OS::Neutron::Port
properties:
network: {get_param: network}
security_groups:
- base
outputs:
server_ip:
description: IP Address of the load-balanced server.
value: { get_attr: [server, first_address] }
lb_member:
description: LB member details.
value: { get_attr: [member, show] }
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Web アプリケーションを実行するインスタンス用に別のテンプレートを作成します。以下のテンプレートはロードバランサーを作成し、既存のネットワークを使用します。お使いの環境に応じてパラメーターを置き換え、テンプレートを /root/lb-webserver-rhel7.yaml などのファイルに保存します。
heat_template_version: 2014-10-16
description: AutoScaling RHEL 7 Web Application
parameters:
image:
type: string
description: Image used for servers
default: RHEL 7
key_name:
type: string
description: SSH key to connect to the servers
default: admin
flavor:
type: string
description: flavor used by the web servers
default: m2.tiny
network:
type: string
description: Network used by the server
default: private
subnet_id:
type: string
description: subnet on which the load balancer will be located
default: 9daa6b7d-e647-482a-b387-dd5f855b88ef
external_network_id:
type: string
description: UUID of a Neutron external network
default: db17c885-77fa-45e8-8647-dbb132517960
resources:
webserver:
type: OS::Heat::AutoScalingGroup
properties:
min_size: 1
max_size: 3
cooldown: 60
desired_capacity: 1
resource:
type: file:///etc/heat/templates/lb-env.yaml
properties:
flavor: {get_param: flavor}
image: {get_param: image}
key_name: {get_param: key_name}
network: {get_param: network}
pool_id: {get_resource: pool}
metadata: {"metering.stack": {get_param: "OS::stack_id"}}
user_data:
str_replace:
template: |
#!/bin/bash -v
yum -y install httpd php
systemctl enable httpd
systemctl start httpd
cat <<EOF > /var/www/html/hostname.php
<?php echo "Hello, My name is " . php_uname('n'); ?>
EOF
params:
hostip: 192.168.122.70
fqdn: sat6.example.com
shortname: sat6
web_server_scaleup_policy:
type: OS::Heat::ScalingPolicy
properties:
adjustment_type: change_in_capacity
auto_scaling_group_id: {get_resource: webserver}
cooldown: 60
scaling_adjustment: 1
web_server_scaledown_policy:
type: OS::Heat::ScalingPolicy
properties:
adjustment_type: change_in_capacity
auto_scaling_group_id: {get_resource: webserver}
cooldown: 60
scaling_adjustment: -1
cpu_alarm_high:
type: OS::Ceilometer::Alarm
properties:
description: Scale-up if the average CPU > 95% for 1 minute
meter_name: cpu_util
statistic: avg
period: 60
evaluation_periods: 1
threshold: 95
alarm_actions:
- {get_attr: [web_server_scaleup_policy, alarm_url]}
matching_metadata: {'metadata.user_metadata.stack': {get_param: "OS::stack_id"}}
comparison_operator: gt
cpu_alarm_low:
type: OS::Ceilometer::Alarm
properties:
description: Scale-down if the average CPU < 15% for 1 minute
meter_name: cpu_util
statistic: avg
period: 60
evaluation_periods: 1
threshold: 15
alarm_actions:
- {get_attr: [web_server_scaledown_policy, alarm_url]}
matching_metadata: {'metadata.user_metadata.stack': {get_param: "OS::stack_id"}}
comparison_operator: lt
monitor:
type: OS::Neutron::HealthMonitor
properties:
type: TCP
delay: 5
max_retries: 5
timeout: 5
pool:
type: OS::Neutron::Pool
properties:
protocol: HTTP
monitors: [{get_resource: monitor}]
subnet_id: {get_param: subnet_id}
lb_method: ROUND_ROBIN
vip:
protocol_port: 80
lb:
type: OS::Neutron::LoadBalancer
properties:
protocol_port: 80
pool_id: {get_resource: pool}
lb_floating:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: {get_param: external_network_id}
port_id: {get_attr: [pool, vip, port_id]}
outputs:
scale_up_url:
description: >
This URL is the webhook to scale up the autoscaling group. You
can invoke the scale-up operation by doing an HTTP POST to this
URL; no body nor extra headers are needed.
value: {get_attr: [web_server_scaleup_policy, alarm_url]}
scale_dn_url:
description: >
This URL is the webhook to scale down the autoscaling group.
You can invoke the scale-down operation by doing an HTTP POST to
this URL; no body nor extra headers are needed.
value: {get_attr: [web_server_scaledown_policy, alarm_url]}
pool_ip_address:
value: {get_attr: [pool, vip, address]}
description: The IP address of the load balancing pool
website_url:
value:
str_replace:
template: http://serviceip/hostname.php
params:
serviceip: { get_attr: [lb_floating, floating_ip_address] }
description: >
This URL is the "external" URL that can be used to access the
website.
ceilometer_query:
value:
str_replace:
template: >
ceilometer statistics -m cpu_util
-q metadata.user_metadata.stack=stackval -p 60 -a avg
params:
stackval: { get_param: "OS::stack_id" }
description: >
This is a Ceilometer query for statistics on the cpu_util meter
Samples about OS::Nova::Server instances in this stack. The -q
parameter selects Samples according to the subject's metadata.
When a VM's metadata includes an item of the form metering.X=Y,
the corresponding Ceilometer resource has a metadata item of the
form user_metadata.X=Y and samples about resources so tagged can
be queried with a Ceilometer query term of the form
metadata.user_metadata.X=Y. In this case the nested stacks give
their VMs metadata that is passed as a nested stack parameter,
and this stack passes a metadata of the form metering.stack=Y,
where Y is this stack's ID.
heat_template_version: 2014-10-16
description: AutoScaling RHEL 7 Web Application
parameters:
image:
type: string
description: Image used for servers
default: RHEL 7
key_name:
type: string
description: SSH key to connect to the servers
default: admin
flavor:
type: string
description: flavor used by the web servers
default: m2.tiny
network:
type: string
description: Network used by the server
default: private
subnet_id:
type: string
description: subnet on which the load balancer will be located
default: 9daa6b7d-e647-482a-b387-dd5f855b88ef
external_network_id:
type: string
description: UUID of a Neutron external network
default: db17c885-77fa-45e8-8647-dbb132517960
resources:
webserver:
type: OS::Heat::AutoScalingGroup
properties:
min_size: 1
max_size: 3
cooldown: 60
desired_capacity: 1
resource:
type: file:///etc/heat/templates/lb-env.yaml
properties:
flavor: {get_param: flavor}
image: {get_param: image}
key_name: {get_param: key_name}
network: {get_param: network}
pool_id: {get_resource: pool}
metadata: {"metering.stack": {get_param: "OS::stack_id"}}
user_data:
str_replace:
template: |
#!/bin/bash -v
yum -y install httpd php
systemctl enable httpd
systemctl start httpd
cat <<EOF > /var/www/html/hostname.php
<?php echo "Hello, My name is " . php_uname('n'); ?>
EOF
params:
hostip: 192.168.122.70
fqdn: sat6.example.com
shortname: sat6
web_server_scaleup_policy:
type: OS::Heat::ScalingPolicy
properties:
adjustment_type: change_in_capacity
auto_scaling_group_id: {get_resource: webserver}
cooldown: 60
scaling_adjustment: 1
web_server_scaledown_policy:
type: OS::Heat::ScalingPolicy
properties:
adjustment_type: change_in_capacity
auto_scaling_group_id: {get_resource: webserver}
cooldown: 60
scaling_adjustment: -1
cpu_alarm_high:
type: OS::Ceilometer::Alarm
properties:
description: Scale-up if the average CPU > 95% for 1 minute
meter_name: cpu_util
statistic: avg
period: 60
evaluation_periods: 1
threshold: 95
alarm_actions:
- {get_attr: [web_server_scaleup_policy, alarm_url]}
matching_metadata: {'metadata.user_metadata.stack': {get_param: "OS::stack_id"}}
comparison_operator: gt
cpu_alarm_low:
type: OS::Ceilometer::Alarm
properties:
description: Scale-down if the average CPU < 15% for 1 minute
meter_name: cpu_util
statistic: avg
period: 60
evaluation_periods: 1
threshold: 15
alarm_actions:
- {get_attr: [web_server_scaledown_policy, alarm_url]}
matching_metadata: {'metadata.user_metadata.stack': {get_param: "OS::stack_id"}}
comparison_operator: lt
monitor:
type: OS::Neutron::HealthMonitor
properties:
type: TCP
delay: 5
max_retries: 5
timeout: 5
pool:
type: OS::Neutron::Pool
properties:
protocol: HTTP
monitors: [{get_resource: monitor}]
subnet_id: {get_param: subnet_id}
lb_method: ROUND_ROBIN
vip:
protocol_port: 80
lb:
type: OS::Neutron::LoadBalancer
properties:
protocol_port: 80
pool_id: {get_resource: pool}
lb_floating:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: {get_param: external_network_id}
port_id: {get_attr: [pool, vip, port_id]}
outputs:
scale_up_url:
description: >
This URL is the webhook to scale up the autoscaling group. You
can invoke the scale-up operation by doing an HTTP POST to this
URL; no body nor extra headers are needed.
value: {get_attr: [web_server_scaleup_policy, alarm_url]}
scale_dn_url:
description: >
This URL is the webhook to scale down the autoscaling group.
You can invoke the scale-down operation by doing an HTTP POST to
this URL; no body nor extra headers are needed.
value: {get_attr: [web_server_scaledown_policy, alarm_url]}
pool_ip_address:
value: {get_attr: [pool, vip, address]}
description: The IP address of the load balancing pool
website_url:
value:
str_replace:
template: http://serviceip/hostname.php
params:
serviceip: { get_attr: [lb_floating, floating_ip_address] }
description: >
This URL is the "external" URL that can be used to access the
website.
ceilometer_query:
value:
str_replace:
template: >
ceilometer statistics -m cpu_util
-q metadata.user_metadata.stack=stackval -p 60 -a avg
params:
stackval: { get_param: "OS::stack_id" }
description: >
This is a Ceilometer query for statistics on the cpu_util meter
Samples about OS::Nova::Server instances in this stack. The -q
parameter selects Samples according to the subject's metadata.
When a VM's metadata includes an item of the form metering.X=Y,
the corresponding Ceilometer resource has a metadata item of the
form user_metadata.X=Y and samples about resources so tagged can
be queried with a Ceilometer query term of the form
metadata.user_metadata.X=Y. In this case the nested stacks give
their VMs metadata that is passed as a nested stack parameter,
and this stack passes a metadata of the form metering.stack=Y,
where Y is this stack's ID.
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Telemetry コレクションの間隔を更新します。デフォルトでは、Telemetry は CPU データに対して 10 分ごとにインスタンスをポーリングします。この例では、/etc/ceilometer/pipeline.yaml で間隔を 60 秒に変更します。
スタックの CPU 負荷を表示する Telemetry コマンド。スケーリングが予想通りに機能しているかどうかを確認することができます。
ダッシュボードでページは次のようになります。
Network Load Balancers を開いて、ロードバランサーを表示します。
Members をクリックします。このページには、負荷分散プールのメンバーが表示されます。これらは、Web サイトのトラフィックを分散できるインスタンスです。対応するインスタンスが作成され、Apache がインストールおよび設定されるまで、メンバーは Active ステータスにならないことに注意してください。
Web サーバーを起動すると、インスタンスはロードバランサーのアクティブなメンバーとして表示されます。
これで、http://IP/hostname.php で Web アプリケーションにアクセスできるようになりました。以下のような出力が表示されるはずです。
Hello, My name is we-zrwm-t4ezkpx34gxu-qbg5d7dqbc4j-server-mzdvigk2jugl
Hello, My name is we-zrwm-t4ezkpx34gxu-qbg5d7dqbc4j-server-mzdvigk2jugl
Copy to ClipboardCopied!Toggle word wrapToggle overflow
ダッシュボード のスタックの概要から Telemetry コマンドを実行して、スタックの CPU パフォーマンスデータを表示できるようになりました。コマンドは以下のようになります。
ceilometer statistics -m cpu_util -q metadata.user_metadata.stack=8f86c3d5-15cf-4a64-b9e8-70215498c046 -p 60 -a avg
追加のインスタンスを作成するかどうかを決定する際には、heat スタックのインスタンスの平均 CPU 使用率が考慮されます。2 番目のインスタンスは通常の CPU 使用率を持つ可能性が最も高いため、最初のインスタンスのバランスを取り除きます。ただし、2 番目のインスタンスもビジーになり、最初のインスタンスと 2 番目のインスタンスの平均 CPU 使用率が 95% を超えると、別のインスタンス(3 番目の)インスタンスが作成されます。