Skip to content

RS's MySQL cookbook, plus the ability to add a DB with the provider

Notifications You must be signed in to change notification settings

rgeyer-rs-cookbooks/mysql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DESCRIPTION:

Installs and configures MySQL client or server.

REQUIREMENTS:

Platform:

Best tested on Ubuntu 9.04,9.10. On EC2, requires platform that supports -o bind option for the ‘mount’ command.

Cookbooks:

Requires Opscode’s openssl cookbook for secure password generation.

Requires a C compiler and Ruby development package in order to build mysql gem with native extensions. On Debian and Ubuntu systems this is satisfied by installing the “build-essential” and “ruby-dev” packages before running Chef. See USAGE below for information on how to handle this during a Chef run.

ATTRIBUTES:

  • mysql - Set the server’s root password with this, default is a randomly generated password with OpenSSL::Random.random_bytes.

  • mysql - Set the replication user ‘repl’ password with this, default is a randomly generated password with OpenSSL::Random.random_bytes.

  • mysql - Set the debian-sys-maint user password with this, default is a randomly generated password with OpenSSL::Random.random_bytes.

  • mysql - Listen address for MySQLd, default is node’s ipaddress.

  • mysql - Location for mysql data directory, default is “/var/lib/mysql”

  • mysql - location of mysql datadir on EC2 nodes, default “/mnt/mysql”

Performance tuning attributes, each corresponds to the same-named parameter in my.cnf; default values listed

  • mysql[:key_buffer] = “250M”

  • mysql[:max_connections] = “800”

  • mysql[:wait_timeout] = “180”

  • mysql[:net_write_timeout] = “30”

  • mysql[:net_write_timeout] = “30”

  • mysql[:back_log] = “128”

  • mysql[:table_cache] = “128”

  • mysql[:max_heap_table_size] = “32M”

USAGE:

On client nodes,

include_recipe "mysql::client"

As the common use case is on systems with Ruby, we also install the MySQL RubyGem. Because we may want to be able to use the gem within another Chef recipe, we make sure the mysql development package and gem are installed first. The key is this:

r = package ... do
  action :nothing
end

r.run_action(:install)

This creates a resource object for the package and does the installation before other recipes are parsed. You’ll need to have the C compiler and such (ie, build-essential on Ubuntu) before running the recipes, but we already do that when installing Chef :-). If you want to be able to access a MySQL database via Ruby within another recipe, you could do so, like so:

Gem.clear_paths # needed for Chef to find the gem...
require 'mysql' # requires the mysql gem

execute "create #{node[:railsapp][:db][:database]} database" do
  command "/usr/bin/mysqladmin -u root -p#{node[:mysql][:server_root_password]} create #{node[:railsapp][:db][:database]}"
  not_if do
    m = Mysql.new("localhost", "root", @node[:mysql][:server_root_password])
    m.list_dbs.include?(@node[:railsapp][:db][:database])
  end
end

On server nodes,

include_recipe "mysql::server"

On Debian/Ubuntu this will preseed the MySQL package with the randomly generated root password. You can of course change the password afterward, but this makes sure that there’s a good password set. You can view it in the node data in the Chef Server webui. Sets a new password for debian-sys-maint user as well.

Also sets up ‘repl’ user grants for replication slaves.

On EC2 nodes,

include_recipe "mysql::server_ec2"

When the ec2_path doesn’t exist we look for a mounted filesystem (eg, EBS) and move the datadir there.

The client recipe is already included by server and ‘default’ recipes.

To make sure that a C compiler and the Ruby development libraries are installed, use the following run list in the node or in a role:

{

"run_list": [
  "recipe[build-essential]",
  "recipe[ruby]",
  "recipe[mysql::server]"
]

}

The build-essential and ruby cookbooks install the packages in question during the “execution” phase of the Chef client run, rather than the compile phase when the MySQL gem is installed. To work around this for now until the build-essential and ruby packages are updated, modify your local copies of the recipes:

In the Opscode build-essential default recipe:

%w{build-essential binutils-doc}.each do |pkg|
  p = package pkg do
    action :nothing
  end
  p.run_action(:install)
end

And the ruby recipe to have the following:

extra_packages.each do |pkg|

p = package pkg do
  action :nothing
end
p.run_action(:install)

end

These cookbooks aren’t strict dependencies, and not if the installation process already included installing build-essential and ruby1.8-dev (e.g. RubyGems installation).

For more infromation on the compile vs execution phase of a Chef run:

wiki.opscode.com/display/chef/Anatomy+of+a+Chef+Run

LICENSE and AUTHOR:

Author

Joshua Timberman (<[email protected]>)

Author

AJ Christensen (<[email protected]>)

Copyright

2009, Opscode, 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.

About

RS's MySQL cookbook, plus the ability to add a DB with the provider

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages