-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rightscale-cookbooks/white_13_07_acu111890…
…_migrate_rs_mysql_application_cookbook White 13 07 acu111890 migrate rs mysql application cookbook
- Loading branch information
Showing
23 changed files
with
868 additions
and
27 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,6 @@ bin/* | |
VERSION | ||
.kitchen/ | ||
.kitchen.local.yml | ||
|
||
doc/ | ||
.yardoc/ |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
language: ruby | ||
rvm: | ||
- 2.0.0 | ||
- 1.9.3 | ||
before_script: bundle exec berks install | ||
script: bundle exec strainer test --except kitchen | ||
notifications: | ||
irc: | ||
channels: ["chat.freenode.net#rightscale"] | ||
use_notice: true | ||
skip_join: true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--markup markdown |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
site :opscode | ||
|
||
metadata | ||
|
||
cookbook 'collectd', github: 'EfrainOlivares/chef-collectd', ref: 'ec50609ed6eb193e0411f30aced91befa571940f' | ||
|
||
group :integration do | ||
cookbook 'apt', '~> 2.3.0' | ||
cookbook 'yum', '~> 2.4.2' | ||
cookbook 'fake', path: './test/cookbooks/fake' | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,42 @@ | ||
# rs-mysql cookbook | ||
|
||
[![Build Status](https://travis-ci.org/rightscale-cookbooks/rs-mysql.png?branch=master)](https://travis-ci.org/rightscale-cookbooks/rs-mysql) | ||
|
||
Sets up a MySQL server and tunes the attributes used in `my.cnf` based on available system memory and the server usage | ||
type. | ||
|
||
Github Repository: [https://github.com/rightscale-cookbooks/rs-mysql](https://github.com/rightscale-cookbooks/rs-mysql) | ||
|
||
# Requirements | ||
|
||
* Requires Chef 11 or higher | ||
* Platform | ||
* Ubuntu 12.04 | ||
* CentOS 6 | ||
* Cookbooks | ||
* [marker](http://community.opscode.com/cookbooks/marker) | ||
* [mysql](http://community.opscode.com/cookbooks/mysql) | ||
* [collectd](http://community.opscode.com/cookbooks/collectd) | ||
|
||
# Usage | ||
|
||
To setup a MySQL server, place the `rs-mysql::server` recipe in the runlist. | ||
|
||
# Attributes | ||
|
||
* `node['rs-mysql']['server_usage']` - The server usage type. It should be either `'dedicated'` or `'shared'`. Default | ||
is `'dedicated'`. | ||
|
||
# Recipes | ||
|
||
## `rs-mysql::server` | ||
|
||
Installs the MySQL server and tunes the attributes used in the `my.cnf` based on the available system memory and the | ||
server usage type. If the server usage type is `'dedicated'`, all resources in the system are dedicated to the MySQL | ||
server and if the usage type is `'shared'`, only half of the resources are used for the MySQL server. This `'shared'` | ||
usage will be used in building a LAMP stack where the same system is used to run both the MySQL server and the PHP | ||
application server. This recipe also installs the collectd plugins for MySQL. | ||
|
||
# Author | ||
|
||
Author:: RightScale, Inc. (<[email protected]>) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
knife: bundle exec knife cookbook test $COOKBOOK | ||
foodcritic: bundle exec foodcritic -f any $SANDBOX/$COOKBOOK | ||
rspec: bundle exec rspec --color --format documentation | ||
kitchen: bundle exec kitchen test --parallel |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# | ||
# Cookbook Name:: rs-mysql | ||
# Attribute:: server | ||
# | ||
# Copyright (C) 2013 RightScale, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# The server usage method. It should either be 'dedicated' or 'shared'. In a 'dedicated' server, all | ||
# resources are dedicated to MySQL. In a 'shared' server, MySQL utilizes only half of the server resources. | ||
# | ||
default['rs-mysql']['server_usage'] = 'dedicated' | ||
|
||
# The MySQL server's root password | ||
default['rs-mysql']['server_root_password'] = nil | ||
|
||
# The MySQL database application username | ||
default['rs-mysql']['application_username'] = nil | ||
|
||
# The MySQL database application password | ||
default['rs-mysql']['application_password'] = nil | ||
|
||
# The previleges given to the application user | ||
default['rs-mysql']['application_user_privileges'] = [:select, :update, :insert] | ||
|
||
# The name of MySQL database | ||
default['rs-mysql']['application_database_name'] = nil |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# | ||
# Cookbook Name:: rs-mysql | ||
# Library:: tuning | ||
# | ||
# Copyright (C) 2013 RightScale, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# The top level module for helpers in this cookbook. | ||
module RsMysql | ||
# The helper for calculating the MySQL tuning attributes. | ||
module Tuning | ||
|
||
# The constant multiplied with megabytes to obtain the value in gigabytes | ||
GB = 1024 | ||
|
||
# Tunes the MySQL attributes based on the available memory and server usage type. | ||
# | ||
# @param node_tuning [Chef::Node] the chef node containing the MySQL tuning attributes | ||
# @param memory [String, Integer] the total available system memory | ||
# @param server_usage [String, Symbol] the server usage type. should be `'dedicated'` or `'shared'` | ||
# | ||
def self.tune_attributes(node_tuning, memory, server_usage) | ||
factor = server_usage.to_s == 'dedicated' ? 1 : 0.5 | ||
memory = memory_in_megabytes(memory) | ||
node_tuning['query_cache_size'] = (memory * factor * 0.01).to_i.to_s + 'M' | ||
node_tuning['innodb_buffer_pool_size'] = (memory * factor * 0.8).to_i.to_s + 'M' | ||
|
||
# Fixed parameters, common value for all memory categories. | ||
# | ||
node_tuning['thread_cache_size'] = (50 * factor).to_i | ||
node_tuning['max_connections'] = (800 * factor).to_i | ||
node_tuning['wait_timeout'] = (28800 * factor).to_i | ||
node_tuning['net_read_timeout'] = (30 * factor).to_i | ||
node_tuning['net_write_timeout'] = (30 * factor).to_i | ||
node_tuning['back_log'] = (128 * factor).to_i | ||
node_tuning['max_heap_table_size'] = (32 * factor).to_i.to_s + 'M' | ||
node_tuning['read_buffer_size'] = (1 * factor).to_i.to_s + 'M' | ||
node_tuning['read_rnd_buffer_size'] = (4 * factor).to_i.to_s + 'M' | ||
node_tuning['long_query_time'] = 5 | ||
|
||
# Sets buffer sizes and InnoDB log properties. Overrides buffer sizes for really small servers. | ||
# | ||
if memory < 1 * GB | ||
node_tuning['key_buffer_size'] = (16 * factor).to_i.to_s + 'M' | ||
node_tuning['max_allowed_packet'] = (20 * factor).to_i.to_s + 'M' | ||
node_tuning['innodb_log_file_size'] = (4 * factor).to_i.to_s + 'M' | ||
node_tuning['innodb_log_buffer_size'] = (16 * factor).to_i.to_s + 'M' | ||
else | ||
node_tuning['key_buffer_size'] = (128 * factor).to_i.to_s + 'M' | ||
node_tuning['max_allowed_packet'] = (128 * factor).to_i.to_s + 'M' | ||
node_tuning['innodb_log_file_size'] = (64 * factor).to_i.to_s + 'M' | ||
node_tuning['innodb_log_buffer_size'] = (8 * factor).to_i.to_s + 'M' | ||
end | ||
|
||
# Adjusts tunable values based on available system memory range. | ||
# The memory ranges used are: | ||
# < 3 GB | ||
# 3 GB - 10 GB | ||
# 10 GB - 25 GB | ||
# 25 GB - 50 GB | ||
# > 50 GB | ||
# | ||
if memory < 3 * GB | ||
node_tuning['table_open_cache'] = (256 * factor).to_i | ||
node_tuning['sort_buffer_size'] = (2 * factor).to_i.to_s + 'M' | ||
node_tuning['innodb_additional_mem_pool_size'] = (50 * factor).to_i.to_s + 'M' | ||
node_tuning['myisam_sort_buffer_size'] = (64 * factor).to_i.to_s + 'M' | ||
elsif memory < 10 * GB | ||
node_tuning['table_open_cache'] = (512 * factor).to_i | ||
node_tuning['sort_buffer_size'] = (4 * factor).to_i.to_s + 'M' | ||
node_tuning['innodb_additional_mem_pool_size'] = (200 * factor).to_i.to_s + 'M' | ||
node_tuning['myisam_sort_buffer_size'] = (96 * factor).to_i.to_s + 'M' | ||
elsif memory < 25 * GB | ||
node_tuning['table_open_cache'] = (1024 * factor).to_i | ||
node_tuning['sort_buffer_size'] = (8 * factor).to_i.to_s + 'M' | ||
node_tuning['innodb_additional_mem_pool_size'] = (300 * factor).to_i.to_s + 'M' | ||
node_tuning['myisam_sort_buffer_size'] = (128 * factor).to_i.to_s + 'M' | ||
elsif memory < 50 * GB | ||
node_tuning['table_open_cache'] = (2048 * factor).to_i | ||
node_tuning['sort_buffer_size'] = (16 * factor).to_i.to_s + 'M' | ||
node_tuning['innodb_additional_mem_pool_size'] = (400 * factor).to_i.to_s + 'M' | ||
node_tuning['myisam_sort_buffer_size'] = (256 * factor).to_i.to_s + 'M' | ||
else | ||
node_tuning['table_open_cache'] = (4096 * factor).to_i | ||
node_tuning['sort_buffer_size'] = (32 * factor).to_i.to_s + 'M' | ||
node_tuning['innodb_additional_mem_pool_size'] = (500 * factor).to_i.to_s + 'M' | ||
node_tuning['myisam_sort_buffer_size'] = (512 * factor).to_i.to_s + 'M' | ||
end | ||
end | ||
|
||
private | ||
|
||
# Given the memory in either kilobytes as a String or in bytes as an Integer (the formats Ohai returns), | ||
# this method will return the memory in megabytes. | ||
# | ||
# @param memory [String, Integer] memory in kilobytes or bytes | ||
# | ||
# @return [Numeric] memory in megabytes | ||
# | ||
def self.memory_in_megabytes(memory) | ||
# If ohai returns the total memory in String, it is assumed to be in kB. | ||
if memory.is_a?(String) && memory =~ /\d+kB/i | ||
memory.to_i / 1024 | ||
# If it returns an integer, it is assumed to be in bytes. | ||
else | ||
memory / (1024 * 1024) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.