From 97b11ac29a040476f4cdd0b04dff4af15c52f877 Mon Sep 17 00:00:00 2001 From: Seth Chisamore Date: Tue, 12 Jul 2011 17:51:42 -0400 Subject: [PATCH] Import mysql version 1.0.8 --- cookbooks/mysql/README.md | 69 +++++++++++++++---- cookbooks/mysql/attributes/server.rb | 10 ++- cookbooks/mysql/libraries/helpers.rb | 33 +++++++++ cookbooks/mysql/metadata.json | 46 ++++++++++++- cookbooks/mysql/metadata.rb | 17 ++++- cookbooks/mysql/recipes/client.rb | 24 ++++--- cookbooks/mysql/recipes/server.rb | 20 ++---- cookbooks/mysql/recipes/server_ec2.rb | 4 +- .../mysql/templates/default/grants.sql.erb | 3 + cookbooks/mysql/templates/default/my.cnf.erb | 24 ++++--- 10 files changed, 194 insertions(+), 56 deletions(-) create mode 100644 cookbooks/mysql/libraries/helpers.rb diff --git a/cookbooks/mysql/README.md b/cookbooks/mysql/README.md index b4f63fb..252d6aa 100644 --- a/cookbooks/mysql/README.md +++ b/cookbooks/mysql/README.md @@ -12,6 +12,12 @@ Platform * Debian, Ubuntu * CentOS, Red Hat, Fedora +Tested on: + +* Debian 5.0 +* Ubuntu 10.04 +* CentOS 5.5 + Cookbooks --------- @@ -34,23 +40,26 @@ For example see the USAGE section below. Attributes ========== -* `mysql[:server_root_password]` - Set the server's root password with this, default is a randomly generated password with `OpenSSL::Random.random_bytes`. -* `mysql[:server_repl_password]` - Set the replication user 'repl' password with this, default is a randomly generated password with `OpenSSL::Random.random_bytes`. -* `mysql[:server_debian_password]` - Set the debian-sys-maint user password with this, default is a randomly generated password with `OpenSSL::Random.random_bytes`. -* `mysql[:bind_address]` - Listen address for MySQLd, default is node's ipaddress. -* `mysql[:datadir]` - Location for mysql data directory, default is "/var/lib/mysql" -* `mysql[:ec2_path]` - location of mysql datadir on EC2 nodes, default "/mnt/mysql" +* `mysql['server_root_password']` - Set the server's root password with this, default is a randomly generated password with `OpenSSL::Random.random_bytes`. +* `mysql['server_repl_password']` - Set the replication user 'repl' password with this, default is a randomly generated password with `OpenSSL::Random.random_bytes`. +* `mysql['server_debian_password']` - Set the debian-sys-maint user password with this, default is a randomly generated password with `OpenSSL::Random.random_bytes`. +* `mysql['bind_address']` - Listen address for MySQLd, default is node's ipaddress. +* `mysql['data_dir']` - Location for mysql data directory, default is "/var/lib/mysql" +* `mysql['conf_dir']` - Location for mysql conf directory, default is "/etc/mysql" +* `mysql['ec2_path']` - location of mysql data_dir on EC2 nodes, default "/mnt/mysql" Performance tuning attributes, each corresponds to the same-named parameter in my.cnf; default values listed -* `mysql[:tunable][:key_buffer]` = "250M" -* `mysql[:tunable][:max_connections]` = "800" -* `mysql[:tunable][:wait_timeout]` = "180" -* `mysql[:tunable][:net_write_timeout]` = "30" -* `mysql[:tunable][:net_write_timeout]` = "30" -* `mysql[:tunable][:back_log]` = "128" -* `mysql[:tunable][:table_cache]` = "128" -* `mysql[:tunable][:max_heap_table_size]` = "32M" +* `mysql['tunable']['key_buffer']` = "250M" +* `mysql['tunable']['max_connections']` = "800" +* `mysql['tunable']['wait_timeout']` = "180" +* `mysql['tunable']['net_write_timeout']` = "30" +* `mysql['tunable']['net_write_timeout']` = "30" +* `mysql['tunable']['back_log']` = "128" +* `mysql['tunable']['table_cache']` = "128" +* `mysql['tunable']['max_heap_table_size']` = "32M" +* `mysql['tunable']['expire_logs_days']` = "10" +* `mysql['tunable']['max_binlog_size']` = "100M" Usage ===== @@ -83,7 +92,7 @@ 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. +When the `ec2_path` doesn't exist we look for a mounted filesystem (eg, EBS) and move the data_dir there. The client recipe is already included by server and 'default' recipes. @@ -91,6 +100,36 @@ For more infromation on the compile vs execution phase of a Chef run: * http://wiki.opscode.com/display/chef/Anatomy+of+a+Chef+Run +Changes/Roadmap +=============== + +### v1.0.8: + +* [COOK-633] ensure "cloud" attribute is available + +### v1.0.7: + +* [COOK-614] expose all mysql tunable settings in config +* [COOK-617] bind to private IP if available + +### v1.0.6: + +* [COOK-605] install mysql-client package on ubuntu/debian + +### v1.0.5: + +* [COOK-465] allow optional remote root connections to mysql +* [COOK-455] improve platform version handling +* externalize conf_dir attribute for easier cross platform support +* change datadir attribute to data_dir for consistency + +### v1.0.4: + +* fix regressions on debian platform +* [COOK-578] wrap root password in quotes +* [COOK-562] expose all tunables in my.cnf + + License and Author ================== diff --git a/cookbooks/mysql/attributes/server.rb b/cookbooks/mysql/attributes/server.rb index 33c4b79..4748dcc 100644 --- a/cookbooks/mysql/attributes/server.rb +++ b/cookbooks/mysql/attributes/server.rb @@ -17,15 +17,17 @@ # limitations under the License. # -default['mysql']['bind_address'] = ipaddress -default['mysql']['datadir'] = "/var/lib/mysql" +default['mysql']['bind_address'] = attribute?('cloud') ? cloud['local_ipv4'] : ipaddress +default['mysql']['data_dir'] = "/var/lib/mysql" case node["platform"] when "centos", "redhat", "fedora", "suse" + set['mysql']['conf_dir'] = '/etc' set['mysql']['socket'] = "/var/lib/mysql/mysql.sock" set['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid" set['mysql']['old_passwords'] = 1 else + set['mysql']['conf_dir'] = '/etc/mysql' set['mysql']['socket'] = "/var/run/mysqld/mysqld.sock" set['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid" set['mysql']['old_passwords'] = 0 @@ -37,6 +39,7 @@ default['mysql']['ebs_vol_size'] = 50 end +default['mysql']['allow_remote_root'] = false default['mysql']['tunable']['back_log'] = "128" default['mysql']['tunable']['key_buffer'] = "256M" default['mysql']['tunable']['max_allowed_packet'] = "16M" @@ -59,4 +62,7 @@ default['mysql']['tunable']['log_slow_queries'] = "/var/log/mysql/slow.log" default['mysql']['tunable']['long_query_time'] = 2 +default['mysql']['tunable']['expire_logs_days'] = 10 +default['mysql']['tunable']['max_binlog_size'] = "100M" + default['mysql']['tunable']['innodb_buffer_pool_size'] = "256M" diff --git a/cookbooks/mysql/libraries/helpers.rb b/cookbooks/mysql/libraries/helpers.rb new file mode 100644 index 0000000..ec8510e --- /dev/null +++ b/cookbooks/mysql/libraries/helpers.rb @@ -0,0 +1,33 @@ +# +# Author:: Seth Chisamore () +# Copyright:: Copyright (c) 2011 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# 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. +# + +module Opscode + module Mysql + module Helpers + + def debian_before_squeeze? + platform?("debian") && (node.platform_version.to_f < 6.0) + end + + def ubuntu_before_lucid? + platform?("ubuntu") && (node.platform_version.to_f < 10.0) + end + + end + end +end \ No newline at end of file diff --git a/cookbooks/mysql/metadata.json b/cookbooks/mysql/metadata.json index f531e5a..b3ab7ec 100644 --- a/cookbooks/mysql/metadata.json +++ b/cookbooks/mysql/metadata.json @@ -1,7 +1,7 @@ { "name": "mysql", "description": "Installs and configures mysql for client or server", - "long_description": "Description\n===========\n\nInstalls and configures MySQL client or server.\n\nRequirements\n============\n\nPlatform\n--------\n\n* Debian, Ubuntu\n* CentOS, Red Hat, Fedora\n\nCookbooks\n---------\n\nRequires Opscode's openssl cookbook for secure password generation.\n\nRequires 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.\n\nResources and Providers\n=======================\n\nThe cookbook contains a LWRP, `mysql_database` which can be used to manage databases through calls to the MySQL API. The mysql gem is installed to make this usable. The provider currently supports three actions:\n\n* `flush_tables_with_read_lock` - sends the sql command \"flush tables with read lock\", used for setting up mysql master/slave replication.\n* `unflush_tables` - sends the sql command \"unflush tables\", used for setting up master/slave replication.\n* `create_db` - specify a database to be created.\n* `query` - send an arbitrary query to the database, this should be used with care. Pass the SQL statement to use with the `sql` resource attribute.\n\nFor example see the USAGE section below.\n\nAttributes\n==========\n\n* `mysql[:server_root_password]` - Set the server's root password with this, default is a randomly generated password with `OpenSSL::Random.random_bytes`.\n* `mysql[:server_repl_password]` - Set the replication user 'repl' password with this, default is a randomly generated password with `OpenSSL::Random.random_bytes`.\n* `mysql[:server_debian_password]` - Set the debian-sys-maint user password with this, default is a randomly generated password with `OpenSSL::Random.random_bytes`.\n* `mysql[:bind_address]` - Listen address for MySQLd, default is node's ipaddress.\n* `mysql[:datadir]` - Location for mysql data directory, default is \"/var/lib/mysql\"\n* `mysql[:ec2_path]` - location of mysql datadir on EC2 nodes, default \"/mnt/mysql\"\n\nPerformance tuning attributes, each corresponds to the same-named parameter in my.cnf; default values listed\n\n* `mysql[:tunable][:key_buffer]` = \"250M\"\n* `mysql[:tunable][:max_connections]` = \"800\"\n* `mysql[:tunable][:wait_timeout]` = \"180\"\n* `mysql[:tunable][:net_write_timeout]` = \"30\"\n* `mysql[:tunable][:net_write_timeout]` = \"30\"\n* `mysql[:tunable][:back_log]` = \"128\"\n* `mysql[:tunable][:table_cache]` = \"128\"\n* `mysql[:tunable][:max_heap_table_size]` = \"32M\"\n\nUsage\n=====\n\nOn client nodes,\n\n include_recipe \"mysql::client\"\n\nThis will install the MySQL client libraries and development headers on the system. It will also install the Ruby Gem `mysql`, so that the cookbook's LWRP (above) can be used. This is done during the compile-phase of the Chef run. On platforms that are known to have a native package (currently Debian, Ubuntu, Red hat, Centos, Fedora and SUSE), the package will be installed. Other platforms will use the RubyGem.\n\nThis 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:\n\n mysql_database \"create application_production database\" do\n host \"localhost\"\n username \"root\"\n password node[:mysql][:server_root_password]\n database \"application_production\"\n action :create_db\n end\n\nThis will connect to the MySQL server running on localhost as \"root\" and password as `mysql[:server_root_password]` attribute (see below) and create the database specified with the `database` parameter. The provider will attempt to determine whether the database exists first.\n\nOn server nodes,\n\n include_recipe \"mysql::server\"\n\nOn Debian and Ubuntu, this will preseed the mysql-server package with the randomly generated root password from the attributes file. On other platforms, it simply installs the required packages. It will also create an SQL file, /etc/mysql/grants.sql, that will be used to set up grants for the root, repl and debian-sys-maint users.\n\nOn EC2 nodes,\n\n include_recipe \"mysql::server_ec2\"\n\nWhen the `ec2_path` doesn't exist we look for a mounted filesystem (eg, EBS) and move the datadir there.\n\nThe client recipe is already included by server and 'default' recipes.\n\nFor more infromation on the compile vs execution phase of a Chef run:\n\n* http://wiki.opscode.com/display/chef/Anatomy+of+a+Chef+Run\n\nLicense and Author\n==================\n\nAuthor:: Joshua Timberman ()\nAuthor:: AJ Christensen ()\nAuthor:: Seth Chisamore ()\n\nCopyright:: 2009-2011 Opscode, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n", + "long_description": "Description\n===========\n\nInstalls and configures MySQL client or server.\n\nRequirements\n============\n\nPlatform\n--------\n\n* Debian, Ubuntu\n* CentOS, Red Hat, Fedora\n\nTested on:\n\n* Debian 5.0\n* Ubuntu 10.04\n* CentOS 5.5\n\nCookbooks\n---------\n\nRequires Opscode's openssl cookbook for secure password generation.\n\nRequires 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.\n\nResources and Providers\n=======================\n\nThe cookbook contains a LWRP, `mysql_database` which can be used to manage databases through calls to the MySQL API. The mysql gem is installed to make this usable. The provider currently supports three actions:\n\n* `flush_tables_with_read_lock` - sends the sql command \"flush tables with read lock\", used for setting up mysql master/slave replication.\n* `unflush_tables` - sends the sql command \"unflush tables\", used for setting up master/slave replication.\n* `create_db` - specify a database to be created.\n* `query` - send an arbitrary query to the database, this should be used with care. Pass the SQL statement to use with the `sql` resource attribute.\n\nFor example see the USAGE section below.\n\nAttributes\n==========\n\n* `mysql['server_root_password']` - Set the server's root password with this, default is a randomly generated password with `OpenSSL::Random.random_bytes`.\n* `mysql['server_repl_password']` - Set the replication user 'repl' password with this, default is a randomly generated password with `OpenSSL::Random.random_bytes`.\n* `mysql['server_debian_password']` - Set the debian-sys-maint user password with this, default is a randomly generated password with `OpenSSL::Random.random_bytes`.\n* `mysql['bind_address']` - Listen address for MySQLd, default is node's ipaddress.\n* `mysql['data_dir']` - Location for mysql data directory, default is \"/var/lib/mysql\"\n* `mysql['conf_dir']` - Location for mysql conf directory, default is \"/etc/mysql\"\n* `mysql['ec2_path']` - location of mysql data_dir on EC2 nodes, default \"/mnt/mysql\"\n\nPerformance tuning attributes, each corresponds to the same-named parameter in my.cnf; default values listed\n\n* `mysql['tunable']['key_buffer']` = \"250M\"\n* `mysql['tunable']['max_connections']` = \"800\"\n* `mysql['tunable']['wait_timeout']` = \"180\"\n* `mysql['tunable']['net_write_timeout']` = \"30\"\n* `mysql['tunable']['net_write_timeout']` = \"30\"\n* `mysql['tunable']['back_log']` = \"128\"\n* `mysql['tunable']['table_cache']` = \"128\"\n* `mysql['tunable']['max_heap_table_size']` = \"32M\"\n* `mysql['tunable']['expire_logs_days']` = \"10\"\n* `mysql['tunable']['max_binlog_size']` = \"100M\"\n\nUsage\n=====\n\nOn client nodes,\n\n include_recipe \"mysql::client\"\n\nThis will install the MySQL client libraries and development headers on the system. It will also install the Ruby Gem `mysql`, so that the cookbook's LWRP (above) can be used. This is done during the compile-phase of the Chef run. On platforms that are known to have a native package (currently Debian, Ubuntu, Red hat, Centos, Fedora and SUSE), the package will be installed. Other platforms will use the RubyGem.\n\nThis 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:\n\n mysql_database \"create application_production database\" do\n host \"localhost\"\n username \"root\"\n password node[:mysql][:server_root_password]\n database \"application_production\"\n action :create_db\n end\n\nThis will connect to the MySQL server running on localhost as \"root\" and password as `mysql[:server_root_password]` attribute (see below) and create the database specified with the `database` parameter. The provider will attempt to determine whether the database exists first.\n\nOn server nodes,\n\n include_recipe \"mysql::server\"\n\nOn Debian and Ubuntu, this will preseed the mysql-server package with the randomly generated root password from the attributes file. On other platforms, it simply installs the required packages. It will also create an SQL file, /etc/mysql/grants.sql, that will be used to set up grants for the root, repl and debian-sys-maint users.\n\nOn EC2 nodes,\n\n include_recipe \"mysql::server_ec2\"\n\nWhen the `ec2_path` doesn't exist we look for a mounted filesystem (eg, EBS) and move the data_dir there.\n\nThe client recipe is already included by server and 'default' recipes.\n\nFor more infromation on the compile vs execution phase of a Chef run:\n\n* http://wiki.opscode.com/display/chef/Anatomy+of+a+Chef+Run\n\nChanges/Roadmap\n===============\n\n### v1.0.8:\n\n* [COOK-633] ensure \"cloud\" attribute is available\n\n### v1.0.7:\n\n* [COOK-614] expose all mysql tunable settings in config\n* [COOK-617] bind to private IP if available\n\n### v1.0.6:\n\n* [COOK-605] install mysql-client package on ubuntu/debian\n\n### v1.0.5:\n\n* [COOK-465] allow optional remote root connections to mysql\n* [COOK-455] improve platform version handling\n* externalize conf_dir attribute for easier cross platform support\n* change datadir attribute to data_dir for consistency\n\n### v1.0.4:\n\n* fix regressions on debian platform\n* [COOK-578] wrap root password in quotes\n* [COOK-562] expose all tunables in my.cnf\n\n\nLicense and Author\n==================\n\nAuthor:: Joshua Timberman ()\nAuthor:: AJ Christensen ()\nAuthor:: Seth Chisamore ()\n\nCopyright:: 2009-2011 Opscode, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n", "maintainer": "Opscode, Inc.", "maintainer_email": "cookbooks@opscode.com", "license": "Apache 2.0", @@ -55,7 +55,7 @@ ] }, - "mysql/datadir": { + "mysql/data_dir": { "display_name": "MySQL Data Directory", "description": "Location of mysql databases", "default": "/var/lib/mysql", @@ -69,6 +69,20 @@ ] }, + "mysql/conf_dir": { + "display_name": "MySQL Conf Directory", + "description": "Location of mysql conf files", + "default": "/etc/mysql", + "choice": [ + + ], + "calculated": false, + "type": "string", + "required": "optional", + "recipes": [ + + ] + }, "mysql/ec2_path": { "display_name": "MySQL EC2 Path", "description": "Location of mysql directory on EC2 instance EBS volumes", @@ -211,6 +225,32 @@ "required": "optional", "recipes": [ + ] + }, + "mysql/tunable/expire_logs_days": { + "display_name": "MySQL Exipre Log Days", + "default": "10", + "choice": [ + + ], + "calculated": false, + "type": "string", + "required": "optional", + "recipes": [ + + ] + }, + "mysql/tunable/max_binlog_size": { + "display_name": "MySQL Max Binlog Size", + "default": "100M", + "choice": [ + + ], + "calculated": false, + "type": "string", + "required": "optional", + "recipes": [ + ] } }, @@ -222,5 +262,5 @@ "mysql::server": "Installs packages required for mysql servers w/o manual intervention", "mysql::server_ec2": "Performs EC2-specific mountpoint manipulation" }, - "version": "1.0.3" + "version": "1.0.8" } \ No newline at end of file diff --git a/cookbooks/mysql/metadata.rb b/cookbooks/mysql/metadata.rb index 70d011d..7a11299 100644 --- a/cookbooks/mysql/metadata.rb +++ b/cookbooks/mysql/metadata.rb @@ -3,7 +3,7 @@ license "Apache 2.0" description "Installs and configures mysql for client or server" long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "1.0.3" +version "1.0.8" recipe "mysql", "Includes the client recipe to configure a client" recipe "mysql::client", "Installs packages required for mysql clients using run_action magic" recipe "mysql::server", "Installs packages required for mysql servers w/o manual intervention" @@ -25,11 +25,16 @@ :description => "Address that mysqld should listen on", :default => "ipaddress" -attribute "mysql/datadir", +attribute "mysql/data_dir", :display_name => "MySQL Data Directory", :description => "Location of mysql databases", :default => "/var/lib/mysql" +attribute "mysql/conf_dir", + :display_name => "MySQL Conf Directory", + :description => "Location of mysql conf files", + :default => "/etc/mysql" + attribute "mysql/ec2_path", :display_name => "MySQL EC2 Path", :description => "Location of mysql directory on EC2 instance EBS volumes", @@ -75,3 +80,11 @@ attribute "mysql/tunable/max_heap_table_size", :display_name => "MySQL Tunable Max Heap Table Size", :default => "32M" + +attribute "mysql/tunable/expire_logs_days", + :display_name => "MySQL Exipre Log Days", + :default => "10" + +attribute "mysql/tunable/max_binlog_size", + :display_name => "MySQL Max Binlog Size", + :default => "100M" diff --git a/cookbooks/mysql/recipes/client.rb b/cookbooks/mysql/recipes/client.rb index c8e0b52..280e04b 100644 --- a/cookbooks/mysql/recipes/client.rb +++ b/cookbooks/mysql/recipes/client.rb @@ -17,14 +17,7 @@ # limitations under the License. # -package "mysql-devel" do - package_name value_for_platform( - [ "centos", "redhat", "suse", "fedora"] => { "default" => "mysql-devel" }, - ["debian", "ubuntu"] => { "default" => 'libmysqlclient-dev' }, - "default" => 'libmysqlclient-dev' - ) - action :install -end +::Chef::Resource::Package.send(:include, Opscode::Mysql::Helpers) package "mysql-client" do package_name value_for_platform( @@ -34,7 +27,20 @@ action :install end -if platform?(%w{debian ubuntu redhat centos fedora suse}) +package "mysql-devel" do + package_name begin + if platform?(%w{ centos redhat suse fedora }) + "mysql-devel" + elsif debian_before_squeeze? || ubuntu_before_lucid? + "libmysqlclient15-dev" + else + "libmysqlclient-dev" + end + end + action :install +end + +if platform?(%w{ debian ubuntu redhat centos fedora suse }) package "mysql-ruby" do package_name value_for_platform( diff --git a/cookbooks/mysql/recipes/server.rb b/cookbooks/mysql/recipes/server.rb index 33f28f4..f061c8c 100644 --- a/cookbooks/mysql/recipes/server.rb +++ b/cookbooks/mysql/recipes/server.rb @@ -48,7 +48,7 @@ notifies :run, resources(:execute => "preseed mysql-server"), :immediately end - template "/etc/mysql/debian.cnf" do + template "#{node['mysql']['conf_dir']}/debian.cnf" do source "debian.cnf.erb" owner "root" group "root" @@ -72,7 +72,7 @@ action :nothing end -template value_for_platform([ "centos", "redhat", "suse" , "fedora" ] => {"default" => "/etc/my.cnf"}, "default" => "/etc/mysql/my.cnf") do +template "#{node['mysql']['conf_dir']}/my.cnf" do source "my.cnf.erb" owner "root" group "root" @@ -94,26 +94,20 @@ unless platform?(%w{debian ubuntu}) execute "assign-root-password" do - command "/usr/bin/mysqladmin -u root password #{node['mysql']['server_root_password']}" + command "/usr/bin/mysqladmin -u root password \"#{node['mysql']['server_root_password']}\"" action :run only_if "/usr/bin/mysql -u root -e 'show databases;'" end end -grants_path = value_for_platform( - ["centos", "redhat", "suse", "fedora" ] => { - "default" => "/etc/mysql_grants.sql" - }, - "default" => "/etc/mysql/grants.sql" -) +grants_path = "#{node['mysql']['conf_dir']}/mysql_grants.sql" begin - t = resources("template[/etc/mysql/grants.sql]") + t = resources("template[#{grants_path}]") rescue Chef::Log.info("Could not find previously defined grants.sql resource") - t = template "/etc/mysql/grants.sql" do - path grants_path + t = template grants_path do source "grants.sql.erb" owner "root" group "root" @@ -125,5 +119,5 @@ execute "mysql-install-privileges" do command "/usr/bin/mysql -u root #{node['mysql']['server_root_password'].empty? ? '' : '-p' }#{node['mysql']['server_root_password']} < #{grants_path}" action :nothing - subscribes :run, resources("template[/etc/mysql/grants.sql]"), :immediately + subscribes :run, resources("template[#{grants_path}]"), :immediately end diff --git a/cookbooks/mysql/recipes/server_ec2.rb b/cookbooks/mysql/recipes/server_ec2.rb index d7cce51..2aa3bef 100644 --- a/cookbooks/mysql/recipes/server_ec2.rb +++ b/cookbooks/mysql/recipes/server_ec2.rb @@ -25,7 +25,7 @@ end execute "install-mysql" do - command "mv #{node['mysql']['datadir']} #{node['mysql']['ec2_path']}" + command "mv #{node['mysql']['data_dir']} #{node['mysql']['ec2_path']}" not_if do FileTest.directory?(node['mysql']['ec2_path']) end end @@ -34,7 +34,7 @@ group "mysql" end - mount node['mysql']['datadir'] do + mount node['mysql']['data_dir'] do device node['mysql']['ec2_path'] fstype "none" options "bind,rw" diff --git a/cookbooks/mysql/templates/default/grants.sql.erb b/cookbooks/mysql/templates/default/grants.sql.erb index da06c04..bfb77c6 100644 --- a/cookbooks/mysql/templates/default/grants.sql.erb +++ b/cookbooks/mysql/templates/default/grants.sql.erb @@ -9,4 +9,7 @@ GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, F GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' identified by '<%= node['mysql']['server_repl_password'] %>'; # Set the server root password. This should be preseeded by the package installation. +<% if node['mysql']['allow_remote_root'] -%> +GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '<%= node['mysql']['server_root_password'] %>' WITH GRANT OPTION; +<% end -%> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('<%= node['mysql']['server_root_password'] %>'); diff --git a/cookbooks/mysql/templates/default/my.cnf.erb b/cookbooks/mysql/templates/default/my.cnf.erb index 6703b15..fe2b1f1 100644 --- a/cookbooks/mysql/templates/default/my.cnf.erb +++ b/cookbooks/mysql/templates/default/my.cnf.erb @@ -48,7 +48,7 @@ pid-file = <%= node['mysql']['pid_file'] %> socket = <%= node['mysql']['socket'] %> port = 3306 basedir = /usr -datadir = <%= node['mysql']['datadir'] %> +datadir = <%= node['mysql']['data_dir'] %> tmpdir = /tmp skip-external-locking # @@ -59,9 +59,9 @@ bind-address = <%= node['mysql']['bind_address'] %> # * Fine Tuning # key_buffer = <%= node['mysql']['tunable']['key_buffer'] %> -max_allowed_packet = 16M -thread_stack = 128K -thread_cache_size = 8 +max_allowed_packet = <%= node['mysql']['tunable']['max_allowed_packet'] %> +thread_stack = <%= node['mysql']['tunable']['thread_stack'] %> +thread_cache_size = <%= node['mysql']['tunable']['thread_cache_size'] %> # This replaces the startup script and checks MyISAM tables if needed # the first time they are touched myisam-recover = BACKUP @@ -79,8 +79,8 @@ max_heap_table_size = <%= node['mysql']['tunable']['max_heap_table_size'] %> # # * Query Cache Configuration # -query_cache_limit = 1M -query_cache_size = 16M +query_cache_limit = <%= node['mysql']['tunable']['query_cache_limit'] %> +query_cache_size = <%= node['mysql']['tunable']['query_cache_size'] %> # # * Logging and Replication # @@ -100,8 +100,8 @@ log-queries-not-using-indexes # other settings you may need to change. #server-id = 1 #log_bin = /var/log/mysql/mysql-bin.log -expire_logs_days = 10 -max_binlog_size = 100M +expire_logs_days = <%= node['mysql']['tunable']['expire_logs_days'] %> +max_binlog_size = <%= node['mysql']['tunable']['max_binlog_size'] %> #binlog_do_db = include_database_name #binlog_ignore_db = include_database_name # @@ -112,6 +112,9 @@ max_binlog_size = 100M # You might want to disable InnoDB to shrink the mysqld process by circa 100MB. #skip-innodb innodb_buffer_pool_size = <%= node['mysql']['tunable']['innodb_buffer_pool_size'] %> + +<% case node['platform'] -%> +<% when "centos", "redhat", "fedora", "ubuntu" -%> # # * Federated # @@ -119,6 +122,7 @@ innodb_buffer_pool_size = <%= node['mysql']['tunable']['innodb_buffer_pool_size' # shipped with MySQL distributions (my-huge.cnf, my-medium.cnf, and so forth). # skip-federated +<% end %> # # * Security Features # @@ -134,13 +138,13 @@ skip-federated [mysqldump] quick quote-names -max_allowed_packet = 16M +max_allowed_packet = <%= node['mysql']['tunable']['max_allowed_packet'] %> [mysql] #no-auto-rehash # faster start of mysql but no tab completition [isamchk] -key_buffer = 16M +key_buffer = <%= node['mysql']['tunable']['max_allowed_packet'] %> # # * NDB Cluster