Guest User

Untitled

a guest
May 7th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. heat_template_version: 2013-05-23
  2. description: AutoScaling Wordpress
  3. parameters:
  4. image:
  5. type: string
  6. description: Image used for servers
  7. key:
  8. type: string
  9. description: SSH key to connect to the servers
  10. flavor:
  11. type: string
  12. description: flavor used by the web servers
  13. database_flavor:
  14. type: string
  15. description: flavor used by the db server
  16. subnet_id:
  17. type: string
  18. description: subnet on which the load balancer will be located
  19. database_name:
  20. type: string
  21. description: Name of the wordpress DB
  22. default: wordpress
  23. database_user:
  24. type: string
  25. description: Name of the wordpress user
  26. default: wordpress
  27. resources:
  28. database_password:
  29. type: OS::Heat::RandomString
  30. database_root_password:
  31. type: OS::Heat::RandomString
  32. db:
  33. type: OS::Nova::Server
  34. properties:
  35. flavor: {get_param: database_flavor}
  36. image: {get_param: image}
  37. key_name: {get_param: key}
  38. user_data_format: RAW
  39. user_data:
  40. str_replace:
  41. template: |
  42. #!/bin/bash -v
  43. yum -y install mariadb mariadb-server
  44. chkconfig mariadb on
  45. service mariadb start
  46. mysqladmin -u root password $db_rootpassword
  47. cat << EOF | mysql -u root --password=$db_rootpassword
  48. CREATE DATABASE $db_name;
  49. GRANT ALL PRIVILEGES ON $db_name.* TO "$db_user"@"%"
  50. IDENTIFIED BY "$db_password";
  51. FLUSH PRIVILEGES;
  52. EXIT
  53. EOF
  54. params:
  55. $db_rootpassword: {get_attr: [database_root_password, value]}
  56. $db_name: {get_param: database_name}
  57. $db_user: {get_param: database_user}
  58. $db_password: {get_attr: [database_password, value]}
  59. web_server_group:
  60. type: OS::Heat::AutoScalingGroup
  61. properties:
  62. min_size: 1
  63. max_size: 3
  64. resource:
  65. type: lb_server.yaml
  66. properties:
  67. flavor: {get_param: flavor}
  68. image: {get_param: image}
  69. key_name: {get_param: key}
  70. pool_id: {get_resource: pool}
  71. metadata: {"metering.stack": {get_param: "OS::stack_id"}}
  72. user_data:
  73. str_replace:
  74. template: |
  75. #!/bin/bash -v
  76. yum -y install httpd wordpress
  77. chkconfig httpd on
  78. service httpd start
  79. setsebool -P httpd_can_network_connect_db=1
  80.  
  81. sed -i "/Deny from All/d" /etc/httpd/conf.d/wordpress.conf
  82. sed -i "s/Require local/Require all granted/" /etc/httpd/conf.d/wordpress.conf
  83. sed -i s/database_name_here/$db_name/ /etc/wordpress/wp-config.php
  84. sed -i s/username_here/$db_user/ /etc/wordpress/wp-config.php
  85. sed -i s/password_here/$db_password/ /etc/wordpress/wp-config.php
  86. sed -i s/localhost/$db_host/ /etc/wordpress/wp-config.php
  87.  
  88. service httpd restart
  89. params:
  90. $db_name: {get_param: database_name}
  91. $db_user: {get_param: database_user}
  92. $db_password: {get_attr: [database_password, value]}
  93. $db_host: {get_attr: [db, first_address]}
  94. web_server_scaleup_policy:
  95. type: OS::Heat::ScalingPolicy
  96. properties:
  97. adjustment_type: change_in_capacity
  98. auto_scaling_group_id: {get_resource: web_server_group}
  99. cooldown: 60
  100. scaling_adjustment: 1
  101. web_server_scaledown_policy:
  102. type: OS::Heat::ScalingPolicy
  103. properties:
  104. adjustment_type: change_in_capacity
  105. auto_scaling_group_id: {get_resource: web_server_group}
  106. cooldown: 60
  107. scaling_adjustment: -1
  108. cpu_alarm_high:
  109. type: OS::Ceilometer::Alarm
  110. properties:
  111. description: Scale-up if the average CPU > 50% for 1 minute
  112. meter_name: cpu_util
  113. statistic: avg
  114. period: 60
  115. evaluation_periods: 1
  116. threshold: 50
  117. alarm_actions:
  118. - {get_attr: [web_server_scaleup_policy, alarm_url]}
  119. matching_metadata: {'metadata.user_metadata.stack': {get_param: "OS::stack_id"}}
  120. comparison_operator: gt
  121. cpu_alarm_low:
  122. type: OS::Ceilometer::Alarm
  123. properties:
  124. description: Scale-down if the average CPU < 15% for 10 minutes
  125. meter_name: cpu_util
  126. statistic: avg
  127. period: 600
  128. evaluation_periods: 1
  129. threshold: 15
  130. alarm_actions:
  131. - {get_attr: [web_server_scaledown_policy, alarm_url]}
  132. matching_metadata: {'metadata.user_metadata.stack': {get_param: "OS::stack_id"}}
  133. comparison_operator: lt
  134. monitor:
  135. type: OS::Neutron::HealthMonitor
  136. properties:
  137. type: TCP
  138. delay: 3
  139. max_retries: 5
  140. timeout: 5
  141. pool:
  142. type: OS::Neutron::Pool
  143. properties:
  144. protocol: HTTP
  145. monitors: [{get_resource: monitor}]
  146. subnet_id: {get_param: subnet_id}
  147. lb_method: ROUND_ROBIN
  148. vip:
  149. protocol_port: 80
  150. lb:
  151. type: OS::Neutron::LoadBalancer
  152. properties:
  153. protocol_port: 80
  154. pool_id: {get_resource: pool}
Advertisement
Add Comment
Please, Sign In to add comment