Created
April 7, 2014 03:33
-
-
Save nvhbk16k53/10014468 to your computer and use it in GitHub Desktop.
Autoscale Elasticsearch Cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heat_template_version: 2014-03-29 | |
description: > | |
Template create single instance stack to deploy elasticsearch | |
parameters: | |
flavor: | |
description: Instance flavor | |
label: Instance Type | |
type: string | |
default: nix.512m_1c | |
constrains: | |
- allow_values: [nix.512m_1c, nix.1g_1c, nix.2g_2c, nix.4g_4c, nix.8g_8c, nix.16g_12c, nix.32g_16c] | |
description: Value must be one of nix.512m_1c, nix.1g_1c, nix.2g_2c, nix.4g_4c, nix.8g_8c, nix.16g_12c, or nix.32g_16c | |
image: | |
description: Image ID or Image logical name | |
label: Image ID | |
type: string | |
key_name: | |
description: A key name of keypairs | |
label: Key Name | |
type: string | |
cluster_name: | |
label: Elasticsearch Cluster Name | |
type: string | |
es_heap_size: | |
description: Elasticsearch maximum ram for heap | |
label: Elasticsearch Heap Size | |
type: string | |
shards: | |
description: Number of shards used by elasticsearch cluster | |
label: Shards | |
type: string | |
default: '5' | |
replicas: | |
description: Number of replicas used by elasticsearch cluster | |
label: Replicas | |
type: string | |
default: '1' | |
volume_size: | |
description: Size of Volume attach to instance in GB | |
label: Volume Size | |
type: number | |
default: 100 | |
resources: | |
ElasticsearchCluster: | |
type: OS::Heat::AutoScalingGroup | |
properties: | |
min_size: 1 | |
max_size: 3 | |
resource: | |
type: OS::Nova::Server | |
properties: | |
flavor: { get_param: flavor } | |
image: { get_param: image } | |
key_name: { get_param: key_name } | |
user_data: | |
str_replace: | |
template: | | |
#!/bin/bash | |
apt-get update -y | |
apt-get install -y openjdk-7-jre | |
wget -O /tmp/elasticsearch.deb https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.0.deb | |
dpkg -i /tmp/elasticsearch.deb | |
sed -i 's/# cluster.name: elasticsearch/cluster.name: $CLUSTER_NAME/' /etc/elasticsearch/elasticsearch.yml | |
sed -i 's/# index.number_of_shards: 5/index.number_of_shards: $SHARDS/' /etc/elasticsearch/elasticsearch.yml | |
sed -i 's/# index.number_of_replicas: 1/index.number_if_replicas: $REPLICAS/' /etc/elasticsearch/elasticsearch.yml | |
sed -i 's/#ES_HEAP_SIZE=2g/ES_HEAP_SIZE=$RAM/' /etc/init.d/elasticsearch | |
#mkfs -t ext4 /dev/vdb | |
#echo '/dev/vdb /var/lib/elasticsearch ext4 defaults 0 0' >> /etc/fstab | |
#mountall | |
#chown -R elasticsearch /var/lib/elasticsearch | |
service elasticsearch start | |
params: | |
$CLUSTER_NAME: { get_param: cluster_name } | |
$RAM: { get_param: es_heap_size } | |
$SHARDS: { get_param: shards } | |
$REPLICAS: { get_param: replicas } | |
es_scaleup_policy: | |
type: OS::Heat::ScalingPolicy | |
properties: | |
adjustment_type: change_in_capacity | |
auto_scaling_group_id: { get_resource: ElasticsearchCluster } | |
cooldown: 60 | |
scaling_adjustment: 1 | |
es_scaledown_policy: | |
type: OS::Heat::ScalingPolicy | |
properties: | |
adjustments_type: change_in_capacity | |
auto_scaling_group_id: { get_resource: ElasticsearchCluster } | |
cooldown: 60 | |
scaling_adjustment: -1 | |
cpu_alarm_high: | |
type: OS::Ceilometer::Alarm | |
properties: | |
description: Scale-up if the average CPU > 50% for 1 minute | |
meter_name: cpu_util | |
statistic: avg | |
period: 60 | |
evaluation_periods: 1 | |
thresh_hold: 50 | |
alarm_actions: | |
- {get_attr: [es_scaleup_policy, alarm_url]} | |
matching_metadata: {'metadata.user_metadata.groupname': {get_resource: web_server_group}} | |
comparison_operator: gt | |
cpu_alarm_low: | |
type: OS::Ceilometer::Alarm | |
properties: | |
description: Scale-down if the average CPU < 20% for 1 minute | |
meter_name: cpu_util | |
statistic: avg | |
period: 60 | |
evaluation_periods: 1 | |
thresh_hold: 20 | |
alarm_actions: | |
- {get_attr: [es_scaledown_policy, alarm_url]} | |
matching_metadata: {'metadata.user_metadata.groupname': {get_resource: web_server_group}} | |
comparison_operator: lt | |
outputs: | |
instance_ip: | |
description: The IP address of deployed instance | |
value: { get_attr: [Elasticsearch, first_address] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment