diff --git a/cookbooks/mysql/.gitignore b/cookbooks/mysql/.gitignore new file mode 100644 index 0000000..852d35c --- /dev/null +++ b/cookbooks/mysql/.gitignore @@ -0,0 +1,7 @@ +.bundle +.cache +.kitchen +bin +*.sw[op] + +Gemfile.lock diff --git a/cookbooks/mysql/.kitchen.yml b/cookbooks/mysql/.kitchen.yml new file mode 100644 index 0000000..d709242 --- /dev/null +++ b/cookbooks/mysql/.kitchen.yml @@ -0,0 +1,48 @@ +--- +driver_plugin: vagrant +driver_config: + require_chef_omnibus: true + +platforms: +- name: ubuntu-12.04 + driver_config: + box: opscode-ubuntu-12.04 + box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box + run_list: + - recipe[apt] + +- name: ubuntu-10.04 + driver_config: + box: opscode-ubuntu-10.04 + box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_provisionerless.box + run_list: + - recipe[apt] + +- name: centos-6.4 + driver_config: + box: opscode-centos-6.4 + box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box + run_list: + - recipe[yum::epel] + +- name: centos-5.9 + driver_config: + box: opscode-centos-5.9 + box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-5.9_provisionerless.box + run_list: + - recipe[yum::epel] + +suites: +- name: client + run_list: + - recipe[mysql::client] + attributes: {} +- name: ruby + run_list: + - recipe[mysql::ruby] + attributes: {} +- name: server + run_list: + - recipe[minitest-handler] + - recipe[mysql_test::server] + attributes: {} diff --git a/cookbooks/mysql/Berksfile b/cookbooks/mysql/Berksfile new file mode 100644 index 0000000..bdbe545 --- /dev/null +++ b/cookbooks/mysql/Berksfile @@ -0,0 +1,11 @@ +site :opscode + +metadata + +group :integration do + cookbook "apt" + cookbook "yum" + + cookbook "mysql_test", :path => "./test/cookbooks/mysql_test" + cookbook "minitest-handler" +end diff --git a/cookbooks/mysql/CHANGELOG.md b/cookbooks/mysql/CHANGELOG.md new file mode 100644 index 0000000..449dbd3 --- /dev/null +++ b/cookbooks/mysql/CHANGELOG.md @@ -0,0 +1,167 @@ +## v3.0.2: + +### Bug + +- [COOK-2158]: apt-get update is run twice at compile time +- [COOK-2832]: mysql grants.sql file has errors depending on attrs +- [COOK-2995]: server.rb is missing a platform_family comparison value + +### Sub-task + +- [COOK-2102]: `innodb_flush_log_at_trx_commit` value is incorrectly + set based on CPU count + +## v3.0.0: + +**Note** This is a backwards incompatible version with previous + versions of the cookbook. Tickets that introduce incompatibility are + COOK-2615 and COOK-2617. + +* [COOK-2478] - Duplicate 'read_only' server attribute in base and tunable +* [COOK-2471] - Add tunable to set slave_compressed_protocol for reduced network traffic +* [COOK-1059] - Update attributes in mysql cookbook to support missing options for my.cnf usable by Percona +* [COOK-2590] - Typo in server recipe to do with conf_dir and confd_dir +* [COOK-2602] - Add `lower_case_table_names` tunable +* [COOK-2430] - Add a tunable to create a network ACL when allowing `remote_root_access` +* [COOK-2619] - mysql: isamchk deprecated +* [COOK-2515] - Better support for SUSE distribution for mysql cookbook +* [COOK-2557] - mysql::percona_repo attributes missing and key server typo +* [COOK-2614] - Duplicate `innodb_file_per_table` +* [COOK-2145] - MySQL cookbook should remove anonymous and password less accounts +* [COOK-2553] - Enable include directory in my.cnf template for any platform +* [COOK-2615] - Rename `key_buffer` to `key_buffer_size` +* [COOK-2626] - Percona repo URL is being constructed incorrectly +* [COOK-2616] - Unneeded attribute thread_cache +* [COOK-2618] - myisam-recover not using attribute value +* [COOK-2617] - open-files is a duplicate of open-files-limit + +## v2.1.2: + +* [COOK-2172] - Mysql cookbook duplicates `binlog_format` + configuration + +## v2.1.0: + +* [COOK-1669] - Using platform("ubuntu") in default attributes always + returns true +* [COOK-1694] - Added additional my.cnf fields and reorganized + cookbook to avoid race conditions with mysql startup and sql script + execution +* [COOK-1851] - Support server-id and binlog_format settings +* [COOK-1929] - Update msyql server attributes file because setting + attributes without specifying a precedence is deprecated +* [COOK-1999] - Add read_only tunable useful for replication slave + servers + +## v2.0.2: + +* [COOK-1967] - mysql: trailing comma in server.rb platform family + +## v2.0.0: + +**Important note for this release** + +Under Chef Solo, you must set the node attributes for the root, debian +and repl passwords or the run will completely fail. See COOK-1737 for +background on this. + +* [COOK-1390] - MySQL service cannot start after reboot +* [COOK-1610] - Set root password outside preseed (blocker for drop-in mysql + replacements) +* [COOK-1624] - Mysql cookbook fails to even compile on windows +* [COOK-1669] - Using platform("ubuntu") in default attributes always returns true +* [COOK-1686] - Add mysql service start +* [COOK-1687] - duplicate `innodb_buffer_pool_size` attribute +* [COOK-1704] - mysql cookbook fails spec tests when minitest-handler cookbook enabled +* [COOK-1737] - Fail a chef-solo run when `server_root_password`, + `server_debian_password`, and/or `server_repl_password` is not set +* [COOK-1769] - link to database recipe in mysql README goes to old opscode/cookbooks + repo instead of opscode-cookbook organization +* [COOK-1963] - use `platform_family` + +## v1.3.0: + +**Important note for this release** + +This version no longer installs Ruby bindings in the client recipe by +default. Use the ruby recipe if you'd like the RubyGem. If you'd like +packages from your distribution, use them in your application's +specific cookbook/recipe, or modify the client packages attribute. +This resolves the following tickets: + +* COOK-932 +* COOK-1009 +* COOK-1384 + +Additionally, this cookbook now has tests (COOK-1439) for use under +test-kitchen. + +The following issues are also addressed in this release. + +* [COOK-1443] - MySQL (>= 5.1.24) does not support `innodb_flush_method` + = fdatasync +* [COOK-1175] - Add Mac OS X support +* [COOK-1289] - handle additional tunable attributes +* [COOK-1305] - add auto-increment-increment and auto-increment-offset + attributes +* [COOK-1397] - make the port an attribute +* [COOK-1439] - Add MySQL cookbook tests for test-kitchen support +* [COOK-1236] - Move package names into attributes to allow percona to + free-ride +* [COOK-934] - remove deprecated mysql/libraries/database.rb, use the + database cookbook instead. +* [COOK-1475] - fix restart on config change + +## v1.2.6: + +* [COOK-1113] - Use an attribute to determine if upstart is used +* [COOK-1121] - Add support for Windows +* [COOK-1140] - Fix conf.d on Debian +* [COOK-1151] - Fix server_ec2 handling /var/lib/mysql bind mount +* [COOK-1321] - Document setting password attributes for solo + +## v1.2.4 + +* [COOK-992] - fix FATAL nameerror +* [COOK-827] - `mysql:server_ec2` recipe can't mount `data_dir` +* [COOK-945] - FreeBSD support + +## v1.2.2 + +* [COOK-826] mysql::server recipe doesn't quote password string +* [COOK-834] Add 'scientific' and 'amazon' platforms to mysql cookbook + +## v1.2.1 + +* [COOK-644] Mysql client cookbook 'package missing' error message is confusing +* [COOK-645] RHEL6/CentOS6 - mysql cookbook contains 'skip-federated' directive which is unsupported on MySQL 5.1 + +## v1.2.0 + +* [COOK-684] remove mysql_database LWRP + +## 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 diff --git a/cookbooks/mysql/CONTRIBUTING b/cookbooks/mysql/CONTRIBUTING new file mode 100644 index 0000000..89ac873 --- /dev/null +++ b/cookbooks/mysql/CONTRIBUTING @@ -0,0 +1,29 @@ +If you would like to contribute, please open a ticket in JIRA: + +* http://tickets.opscode.com + +Create the ticket in the COOK project and use the cookbook name as the +component. + +For all code contributions, we ask that contributors sign a +contributor license agreement (CLA). Instructions may be found here: + +* http://wiki.opscode.com/display/chef/How+to+Contribute + +When contributing changes to individual cookbooks, please do not +modify the version number in the metadata.rb. Also please do not +update the CHANGELOG.md for a new version. Not all changes to a +cookbook may be merged and released in the same versions. Opscode will +handle the version updates during the release process. You are welcome +to correct typos or otherwise make updates to documentation in the +README. + +If a contribution adds new platforms or platform versions, indicate +such in the body of the commit message(s), and update the relevant +COOK ticket. When writing commit messages, it is helpful for others if +you indicate the COOK ticket. For example: + + git commit -m '[COOK-1041] Updated pool resource to correctly delete.' + +In the ticket itself, it is also helpful if you include log output of +a successful Chef run, but this is not absolutely required. diff --git a/cookbooks/mysql/LICENSE b/cookbooks/mysql/LICENSE new file mode 100644 index 0000000..11069ed --- /dev/null +++ b/cookbooks/mysql/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +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. diff --git a/cookbooks/mysql/README.md b/cookbooks/mysql/README.md new file mode 100644 index 0000000..1a0856a --- /dev/null +++ b/cookbooks/mysql/README.md @@ -0,0 +1,250 @@ +Description +=========== + +Installs and configures MySQL client or server. + +Requirements +============ + +Chef 0.10.10+. + +Platform +-------- + +* Debian, Ubuntu +* CentOS, Red Hat, Fedora +* Mac OS X (Using homebrew) + +Tested on: + +* Debian 5.0, 6.0 +* Ubuntu 10.04-12.04 +* CentOS 5.5-5.8, 6.2-6.3 +* Mac OS X 10.7.2 + +See TESTING.md for information about running tests in Opscode's Test +Kitchen. + +Cookbooks +--------- + +Requires Opscode's openssl cookbook for secure password generation. +See _Attributes_ and _Usage_ for more information. + +The RubyGem installation in the `mysql::ruby` recipe requires a C +compiler and Ruby development headers to be installed in order to +build the mysql gem. + +Requires `homebrew` +[cookbook](http://community.opscode.com/cookbooks/homebrew) on Mac OS +X. + +Resources and Providers +======================= + +The LWRP that used to ship as part of this cookbook has been +refactored into the +[database](http://community.opscode.com/cookbooks/database) +cookbook. Please see the README for details on updated usage. + +Attributes +========== + +See the `attributes/server.rb` or `attributes/client.rb` for default +values. Several attributes have values that vary based on the node's +platform and version. + +* `node['mysql']['client']['packages']` - An array of package names + that should be installed on "client" systems. This can be modified, + e.g., to specify packages for Percona. +* `node['mysql']['server']['packages']` - An array of package names + that should be installed on "server" systems. This can be modified, + e.g., to specify packages for Percona. + +* `node['mysql']['auto-increment-increment']` - + auto-increment-increment value in my.cnf +* `node['mysql']['auto-increment-offset]` - auto-increment-offset + value in my.cnf +* `node['mysql']['basedir']` - Base directory where MySQL is installed +* `node['mysql']['bind_address']` - Listen address for MySQLd +* `node['mysql']['conf_dir']` - Location for mysql conf directory +* `node['mysql']['confd_dir']` - Location for mysql conf.d style + include directory +* `node['mysql']['data_dir']` - Location for mysql data directory +* `node['mysql']['ec2_path']` - location of mysql data_dir on EC2 + nodes +* `node['mysql']['grants_path']` - Path where the grants.sql should be + written +* `node['mysql']['mysqladmin_bin']` - Path to the mysqladmin binary +* `node['mysql']['old_passwords']` - Sets the `old_passwords` value in + my.cnf. +* `node['mysql']['pid_file']` - Path to the mysqld.pid file +* `node['mysql']['port']` - Liten port for MySQLd +* `node['mysql']['reload_action']` - Action to take when mysql conf + files are modified. Also allows "reload" and "none". +* `node['mysql']['root_group']` - The default group of the "root" user +* `node['mysql']['service_name']` - The name of the mysqld service +* `node['mysql']['socket']` - Path to the mysqld.sock file +* `node['mysql']['use_upstart']` - Whether to use upstart for the + service provider +* `mysql['root_network_acl']` - Set define the network the root user will be able to login from, default is nil + +Performance and other "tunable" attributes are under the +`node['mysql']['tunable']` attribute, corresponding to the same-named +parameter in my.cnf, and the default values are used. See +`attributes/server.rb`. + +By default, a MySQL installation has an anonymous user, allowing anyone +to log into MySQL without having to have a user account created for +them. This is intended only for testing, and to make the installation +go a bit smoother. You should remove them before moving into a +production environment. + +* `node['mysql']['remove_anonymous_users']` - Remove anonymous users + +Normally, root should only be allowed to connect from 'localhost'. This +ensures that someone cannot guess at the root password from the network. + +* `node['mysql']['allow_remote_root']` - If true Sets root access from '%'. If false deletes any non-localhost root users. + +By default, MySQL comes with a database named 'test' that anyone can +access. This is also intended only for testing, and should be removed +before moving into a production environment. This will also drop any user privileges to the test databae and any DB named test_% . + +* `node['mysql']['remove_test_database']` - Delete the test database and access to it. + +The following attributes are randomly generated passwords handled in +the `mysql::server` recipe, using the OpenSSL cookbook's +`secure_password` helper method. These are set using the `set_unless` +node attribute method, which allows them to be easily overridden e.g. +in a role. + +* `node['mysql']['server_root_password']` - Set the server's root + password +* `node['mysql']['server_repl_password']` - Set the replication user + 'repl' password +* `node['mysql']['server_debian_password']` - Set the debian-sys-maint + user password + +## Windows Specific + +The following attributes are specific to Windows platforms. + +* `node['mysql']['client']['version']` - The version of MySQL + connector to install. +* `node['mysql']['client']['arch']` - Force 32 bit to work with the + mysql gem +* `node['mysql']['client']['package_file']` - The MSI file for the + mysql connector. +* `node['mysql']['client']['url']` - URL to download the mysql + connector. +* `node['mysql']['client']['packages']` - Similar to other platforms, + this is the name of the client package. +* `node['mysql']['client']['basedir']` - Base installation location +* `node['mysql']['client']['lib_dir']` - Libraries under the base location +* `node['mysql']['client']['bin_dir']` - binary directory under base location +* `node['mysql']['client']['ruby_dir']` - location where the Ruby + binaries will be + +Usage +===== + +On client nodes, use the client (or default) recipe: + + { "run_list": ["recipe[mysql::client]"] } + +This will install the MySQL client libraries and development headers +on the system. + +On nodes which may use the `database` cookbook's mysql resources, also +use the ruby recipe. This installs the mysql RubyGem in the Ruby +environment Chef is using via `chef_gem`. + + { "run_list": ["recipe[mysql::client]", "recipe[mysql::ruby]"] } + +If you need to install the mysql Ruby library as a package for your +system, override the client packages attribute in your node or role. +For example, on an Ubuntu system: + + { + "mysql": { + "client": { + "packages": ["mysql-client", "libmysqlclient-dev","ruby-mysql"] + } + } + } + +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 :-). + +On server nodes, use the server recipe: + + { "run_list": ["recipe[mysql::server]"] } + +On Debian and Ubuntu, this will preseed the mysql-server package with +the randomly generated root password in the recipe 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. + +The recipe will perform a `node.save` unless it is run under +`chef-solo` after the password attributes are used to ensure that in +the event of a failed run, the saved attributes would be used. + +On EC2 nodes, use the `server_ec2` recipe and the mysql data dir will +be set up in the ephmeral storage. + + { "run_list": ["recipe[mysql::server_ec2]"] } + +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. + +For more infromation on the compile vs execution phase of a Chef run: + +* http://wiki.opscode.com/display/chef/Anatomy+of+a+Chef+Run + +Chef Solo Note +============== + +These node attributes are stored on the Chef +server when using `chef-client`. Because `chef-solo` does not +connect to a server or save the node object at all, to have the same +passwords persist across `chef-solo` runs, you must specify them in +the `json_attribs` file used. For example: + + { + "mysql": { + "server_root_password": "iloverandompasswordsbutthiswilldo", + "server_repl_password": "iloverandompasswordsbutthiswilldo", + "server_debian_password": "iloverandompasswordsbutthiswilldo" + }, + "run_list":["recipe[mysql::server]"] + } + +License and Author +================== + +- Author:: Joshua Timberman () +- Author:: AJ Christensen () +- Author:: Seth Chisamore () +- Author:: Brian Bianco () +- Author:: Jesse Howarth () +- Author:: Andrew Crump () + +Copyright:: 2009-2013 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. diff --git a/cookbooks/mysql/TESTING.md b/cookbooks/mysql/TESTING.md new file mode 100644 index 0000000..e29ff7c --- /dev/null +++ b/cookbooks/mysql/TESTING.md @@ -0,0 +1,25 @@ +This cookbook includes support for running tests via Test Kitchen (1.0). This has some requirements. + +1. You must be using the Git repository, rather than the downloaded cookbook from the Chef Community Site. +2. You must have Vagrant 1.1 installed. +3. You must have a "sane" Ruby 1.9.3 environment. + +Once the above requirements are met, install the additional requirements: + +Install the berkshelf plugin for vagrant, and berkshelf to your local Ruby environment. + + vagrant plugin install vagrant-berkshelf + gem install berkshelf + +Install Test Kitchen 1.0 (unreleased yet, use the alpha / prerelease version). + + gem install test-kitchen --pre + +Install the Vagrant driver for Test Kitchen. + + gem install kitchen-vagrant + +Once the above are installed, you should be able to run Test Kitchen: + + kitchen list + kitchen test diff --git a/cookbooks/mysql/attributes/client.rb b/cookbooks/mysql/attributes/client.rb new file mode 100644 index 0000000..fcaa1da --- /dev/null +++ b/cookbooks/mysql/attributes/client.rb @@ -0,0 +1,52 @@ +# +# Cookbook Name:: mysql +# Attributes:: client +# +# Copyright 2008-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. +# +# Include Opscode helper in Node class to get access +# to debian_before_squeeze? and ubuntu_before_lucid? +::Chef::Node.send(:include, Opscode::Mysql::Helpers) + +case node['platform_family'] +when "rhel", "fedora" + default['mysql']['client']['packages'] = %w{mysql mysql-devel} +when "suse" + default['mysql']['client']['packages'] = %w{mysql-community-server-client libmysqlclient-devel} +when "debian" + if debian_before_squeeze? || ubuntu_before_lucid? + default['mysql']['client']['packages'] = %w{mysql-client libmysqlclient15-dev} + else + default['mysql']['client']['packages'] = %w{mysql-client libmysqlclient-dev} + end +when "freebsd" + default['mysql']['client']['packages'] = %w{mysql55-client} +when "windows" + default['mysql']['client']['version'] = "6.0.2" + default['mysql']['client']['arch'] = "win32" # force 32 bit to work with mysql gem + default['mysql']['client']['package_file'] = "mysql-connector-c-#{mysql['client']['version']}-#{mysql['client']['arch']}.msi" + default['mysql']['client']['url'] = "http://www.mysql.com/get/Downloads/Connector-C/#{mysql['client']['package_file']}/from/http://mysql.mirrors.pair.com/" + default['mysql']['client']['packages'] = ["MySQL Connector C #{mysql['client']['version']}"] + + default['mysql']['client']['basedir'] = "#{ENV['SYSTEMDRIVE']}\\Program Files (x86)\\MySQL\\#{mysql['client']['packages'].first}" + default['mysql']['client']['lib_dir'] = "#{mysql['client']['basedir']}\\lib/opt" + default['mysql']['client']['bin_dir'] = "#{mysql['client']['basedir']}\\bin" + default['mysql']['client']['ruby_dir'] = RbConfig::CONFIG['bindir'] +when "mac_os_x" + default['mysql']['client']['packages'] = %w{mysql-connector-c} +else + default['mysql']['client']['packages'] = %w{mysql-client libmysqlclient-dev} +end + diff --git a/cookbooks/mysql/attributes/percona_repo.rb b/cookbooks/mysql/attributes/percona_repo.rb new file mode 100644 index 0000000..80650a6 --- /dev/null +++ b/cookbooks/mysql/attributes/percona_repo.rb @@ -0,0 +1,3 @@ +default['mysql']['percona']['apt_key_id'] = 'CD2EFD2A' +default['mysql']['percona']['apt_uri'] = "http://repo.percona.com/apt" +default['mysql']['percona']['apt_keyserver'] = "keys.gnupg.net" diff --git a/cookbooks/mysql/attributes/server.rb b/cookbooks/mysql/attributes/server.rb new file mode 100644 index 0000000..006e85b --- /dev/null +++ b/cookbooks/mysql/attributes/server.rb @@ -0,0 +1,254 @@ +# +# Cookbook Name:: mysql +# Attributes:: server +# +# Copyright 2008-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. +# + +default['mysql']['bind_address'] = attribute?('cloud') ? cloud['local_ipv4'] : ipaddress +default['mysql']['port'] = 3306 +default['mysql']['nice'] = 0 + +case node["platform_family"] +when "debian" + default['mysql']['server']['packages'] = %w{mysql-server} + default['mysql']['service_name'] = "mysql" + default['mysql']['basedir'] = "/usr" + default['mysql']['data_dir'] = "/var/lib/mysql" + default['mysql']['root_group'] = "root" + default['mysql']['mysqladmin_bin'] = "/usr/bin/mysqladmin" + default['mysql']['mysql_bin'] = "/usr/bin/mysql" + + default['mysql']['conf_dir'] = '/etc/mysql' + default['mysql']['confd_dir'] = '/etc/mysql/conf.d' + default['mysql']['socket'] = "/var/run/mysqld/mysqld.sock" + default['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid" + default['mysql']['old_passwords'] = 0 + default['mysql']['grants_path'] = "/etc/mysql/grants.sql" +when "rhel", "fedora" + if node["mysql"]["version"].to_f >= 5.5 + default['mysql']['service_name'] = "mysql" + default['mysql']['pid_file'] = "/var/run/mysql/mysql.pid" + else + default['mysql']['service_name'] = "mysqld" + default['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid" + end + default['mysql']['server']['packages'] = %w{mysql-server} + default['mysql']['basedir'] = "/usr" + default['mysql']['data_dir'] = "/var/lib/mysql" + default['mysql']['root_group'] = "root" + default['mysql']['mysqladmin_bin'] = "/usr/bin/mysqladmin" + default['mysql']['mysql_bin'] = "/usr/bin/mysql" + + default['mysql']['conf_dir'] = '/etc' + default['mysql']['confd_dir'] = '/etc/mysql/conf.d' + default['mysql']['socket'] = "/var/lib/mysql/mysql.sock" + default['mysql']['old_passwords'] = 1 + default['mysql']['grants_path'] = "/etc/mysql_grants.sql" + # RHEL/CentOS mysql package does not support this option. + default['mysql']['tunable']['innodb_adaptive_flushing'] = false +when "suse" + default['mysql']['service_name'] = "mysql" + default['mysql']['server']['packages'] = %w{mysql-community-server} + default['mysql']['basedir'] = "/usr" + default['mysql']['data_dir'] = "/var/lib/mysql" + default['mysql']['root_group'] = "root" + default['mysql']['mysqladmin_bin'] = "/usr/bin/mysqladmin" + default['mysql']['mysql_bin'] = "/usr/bin/mysql" + default['mysql']['conf_dir'] = '/etc' + default['mysql']['confd_dir'] = '/etc/mysql/conf.d' + default['mysql']['socket'] = "/var/run/mysql/mysql.sock" + default['mysql']['pid_file'] = "/var/run/mysql/mysqld.pid" + default['mysql']['old_passwords'] = 1 + default['mysql']['grants_path'] = "/etc/mysql_grants.sql" +when "freebsd" + default['mysql']['server']['packages'] = %w{mysql55-server} + default['mysql']['service_name'] = "mysql-server" + default['mysql']['basedir'] = "/usr/local" + default['mysql']['data_dir'] = "/var/db/mysql" + default['mysql']['root_group'] = "wheel" + default['mysql']['mysqladmin_bin'] = "/usr/local/bin/mysqladmin" + default['mysql']['mysql_bin'] = "/usr/local/bin/mysql" + + default['mysql']['conf_dir'] = '/usr/local/etc' + default['mysql']['confd_dir'] = '/usr/local/etc/mysql/conf.d' + default['mysql']['socket'] = "/tmp/mysqld.sock" + default['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid" + default['mysql']['old_passwords'] = 0 + default['mysql']['grants_path'] = "/var/db/mysql/grants.sql" +when "windows" + default['mysql']['server']['packages'] = ["MySQL Server 5.5"] + default['mysql']['version'] = '5.5.21' + default['mysql']['arch'] = 'win32' + default['mysql']['package_file'] = "mysql-#{mysql['version']}-#{mysql['arch']}.msi" + default['mysql']['url'] = "http://www.mysql.com/get/Downloads/MySQL-5.5/#{mysql['package_file']}/from/http://mysql.mirrors.pair.com/" + + default['mysql']['service_name'] = "mysql" + default['mysql']['basedir'] = "#{ENV['SYSTEMDRIVE']}\\Program Files (x86)\\MySQL\\#{mysql['server']['packages'].first}" + default['mysql']['data_dir'] = "#{node['mysql']['basedir']}\\Data" + default['mysql']['bin_dir'] = "#{node['mysql']['basedir']}\\bin" + default['mysql']['mysqladmin_bin'] = "#{node['mysql']['bin_dir']}\\mysqladmin" + default['mysql']['mysql_bin'] = "#{node['mysql']['bin_dir']}\\mysql" + + default['mysql']['conf_dir'] = node['mysql']['basedir'] + default['mysql']['old_passwords'] = 0 + default['mysql']['grants_path'] = "#{node['mysql']['conf_dir']}\\grants.sql" +when "mac_os_x" + default['mysql']['server']['packages'] = %w{mysql} + default['mysql']['basedir'] = "/usr/local/Cellar" + default['mysql']['data_dir'] = "/usr/local/var/mysql" + default['mysql']['root_group'] = "admin" + default['mysql']['mysqladmin_bin'] = "/usr/local/bin/mysqladmin" + default['mysql']['mysql_bin'] = "/usr/local/bin/mysql" +else + default['mysql']['server']['packages'] = %w{mysql-server} + default['mysql']['service_name'] = "mysql" + default['mysql']['basedir'] = "/usr" + default['mysql']['data_dir'] = "/var/lib/mysql" + default['mysql']['root_group'] = "root" + default['mysql']['mysqladmin_bin'] = "/usr/bin/mysqladmin" + default['mysql']['mysql_bin'] = "/usr/bin/mysql" + + default['mysql']['conf_dir'] = '/etc/mysql' + default['mysql']['confd_dir'] = '/etc/mysql/conf.d' + default['mysql']['socket'] = "/var/run/mysqld/mysqld.sock" + default['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid" + default['mysql']['old_passwords'] = 0 + default['mysql']['grants_path'] = "/etc/mysql/grants.sql" +end + +if attribute?('ec2') + default['mysql']['ec2_path'] = "/mnt/mysql" + default['mysql']['ebs_vol_dev'] = "/dev/sdi" + default['mysql']['ebs_vol_size'] = 50 +end + +default['mysql']['reload_action'] = "restart" # or "reload" or "none" + +default['mysql']['use_upstart'] = node['platform'] == "ubuntu" && node['platform_version'].to_f >= 10.04 + +default['mysql']['auto-increment-increment'] = 1 +default['mysql']['auto-increment-offset'] = 1 + +default['mysql']['allow_remote_root'] = false +default['mysql']['remove_anonymous_users'] = false +default['mysql']['remove_test_database'] = false +default['mysql']['root_network_acl'] = nil +default['mysql']['tunable']['character-set-server'] = "utf8" +default['mysql']['tunable']['collation-server'] = "utf8_general_ci" +default['mysql']['tunable']['lower_case_table_names'] = nil +default['mysql']['tunable']['back_log'] = "128" +default['mysql']['tunable']['key_buffer_size'] = "256M" +default['mysql']['tunable']['myisam_sort_buffer_size'] = "8M" +default['mysql']['tunable']['myisam_max_sort_file_size'] = "2147483648" +default['mysql']['tunable']['myisam_repair_threads'] = "1" +default['mysql']['tunable']['myisam-recover'] = "BACKUP" +default['mysql']['tunable']['max_allowed_packet'] = "16M" +default['mysql']['tunable']['max_connections'] = "800" +default['mysql']['tunable']['max_connect_errors'] = "10" +default['mysql']['tunable']['concurrent_insert'] = "2" +default['mysql']['tunable']['connect_timeout'] = "10" +default['mysql']['tunable']['tmp_table_size'] = "32M" +default['mysql']['tunable']['max_heap_table_size'] = node['mysql']['tunable']['tmp_table_size'] +default['mysql']['tunable']['bulk_insert_buffer_size'] = node['mysql']['tunable']['tmp_table_size'] +default['mysql']['tunable']['net_read_timeout'] = "30" +default['mysql']['tunable']['net_write_timeout'] = "30" +default['mysql']['tunable']['table_cache'] = "128" + +default['mysql']['tunable']['thread_cache_size'] = 8 +default['mysql']['tunable']['thread_concurrency'] = 10 +default['mysql']['tunable']['thread_stack'] = "256K" +default['mysql']['tunable']['sort_buffer_size'] = "2M" +default['mysql']['tunable']['read_buffer_size'] = "128k" +default['mysql']['tunable']['read_rnd_buffer_size'] = "256k" +default['mysql']['tunable']['join_buffer_size'] = "128k" +default['mysql']['tunable']['wait_timeout'] = "180" +default['mysql']['tunable']['open-files-limit'] = "1024" + +default['mysql']['tunable']['sql_mode'] = nil + +default['mysql']['tunable']['skip-character-set-client-handshake'] = false +default['mysql']['tunable']['skip-name-resolve'] = false + +default['mysql']['tunable']['slave_compressed_protocol'] = 0 + +default['mysql']['tunable']['server_id'] = nil +default['mysql']['tunable']['log_bin'] = nil +default['mysql']['tunable']['log_bin_trust_function_creators'] = false + +default['mysql']['tunable']['relay_log'] = nil +default['mysql']['tunable']['relay_log_index'] = nil +default['mysql']['tunable']['log_slave_updates'] = false + +default['mysql']['tunable']['sync_binlog'] = 0 +default['mysql']['tunable']['skip_slave_start'] = false +default['mysql']['tunable']['read_only'] = false + +default['mysql']['tunable']['log_error'] = nil +default['mysql']['tunable']['log_warnings'] = false +default['mysql']['tunable']['log_queries_not_using_index'] = true +default['mysql']['tunable']['log_bin_trust_function_creators'] = false + +default['mysql']['tunable']['innodb_log_file_size'] = "5M" +default['mysql']['tunable']['innodb_buffer_pool_size'] = "128M" +default['mysql']['tunable']['innodb_buffer_pool_instances'] = "4" +default['mysql']['tunable']['innodb_additional_mem_pool_size'] = "8M" +default['mysql']['tunable']['innodb_data_file_path'] = "ibdata1:10M:autoextend" +default['mysql']['tunable']['innodb_flush_method'] = false +default['mysql']['tunable']['innodb_log_buffer_size'] = "8M" +default['mysql']['tunable']['innodb_write_io_threads'] = "4" +default['mysql']['tunable']['innodb_io_capacity'] = "200" +default['mysql']['tunable']['innodb_file_per_table'] = true +default['mysql']['tunable']['innodb_lock_wait_timeout'] = "60" +if node['cpu'].nil? or node['cpu']['total'].nil? + default['mysql']['tunable']['innodb_thread_concurrency'] = "8" + default['mysql']['tunable']['innodb_commit_concurrency'] = "8" + default['mysql']['tunable']['innodb_read_io_threads'] = "8" +else + default['mysql']['tunable']['innodb_thread_concurrency'] = "#{(Integer(node['cpu']['total'])) * 2}" + default['mysql']['tunable']['innodb_commit_concurrency'] = "#{(Integer(node['cpu']['total'])) * 2}" + default['mysql']['tunable']['innodb_read_io_threads'] = "#{(Integer(node['cpu']['total'])) * 2}" +end +default['mysql']['tunable']['innodb_flush_log_at_trx_commit'] = "1" +default['mysql']['tunable']['innodb_support_xa'] = true +default['mysql']['tunable']['innodb_table_locks'] = true +default['mysql']['tunable']['skip-innodb-doublewrite'] = false + +default['mysql']['tunable']['transaction-isolation'] = nil + +default['mysql']['tunable']['query_cache_limit'] = "1M" +default['mysql']['tunable']['query_cache_size'] = "16M" + +default['mysql']['tunable']['log_slow_queries'] = "/var/log/mysql/slow.log" +default['mysql']['tunable']['slow_query_log'] = node['mysql']['tunable']['log_slow_queries'] # log_slow_queries is deprecated + # in favor of slow_query_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']['binlog_cache_size'] = "32K" + +default['mysql']['tmpdir'] = ["/tmp"] + +default['mysql']['log_dir'] = node['mysql']['data_dir'] +default['mysql']['log_files_in_group'] = false +default['mysql']['innodb_status_file'] = false + +unless node['platform_family'] == "rhel" && node['platform_version'].to_i < 6 + # older RHEL platforms don't support these options + default['mysql']['tunable']['event_scheduler'] = 0 + default['mysql']['tunable']['table_open_cache'] = "128" + default['mysql']['tunable']['binlog_format'] = "statement" if node['mysql']['tunable']['log_bin'] +end diff --git a/cookbooks/mysql/libraries/helpers.rb b/cookbooks/mysql/libraries/helpers.rb new file mode 100644 index 0000000..40adcfc --- /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? + (node['platform'] == "debian") && (node['platform_version'].to_f < 6.0) + end + + def ubuntu_before_lucid? + (node['platform'] == "ubuntu") && (node['platform_version'].to_f < 10.0) + end + + end + end +end diff --git a/cookbooks/mysql/metadata.json b/cookbooks/mysql/metadata.json new file mode 100644 index 0000000..03687b3 --- /dev/null +++ b/cookbooks/mysql/metadata.json @@ -0,0 +1 @@ +{"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\nChef 0.10.10+.\n\nPlatform\n--------\n\n* Debian, Ubuntu\n* CentOS, Red Hat, Fedora\n* Mac OS X (Using homebrew)\n\nTested on:\n\n* Debian 5.0, 6.0\n* Ubuntu 10.04-12.04\n* CentOS 5.5-5.8, 6.2-6.3\n* Mac OS X 10.7.2\n\nSee TESTING.md for information about running tests in Opscode's Test\nKitchen.\n\nCookbooks\n---------\n\nRequires Opscode's openssl cookbook for secure password generation.\nSee _Attributes_ and _Usage_ for more information.\n\nThe RubyGem installation in the `mysql::ruby` recipe requires a C\ncompiler and Ruby development headers to be installed in order to\nbuild the mysql gem.\n\nRequires `homebrew`\n[cookbook](http://community.opscode.com/cookbooks/homebrew) on Mac OS\nX.\n\nResources and Providers\n=======================\n\nThe LWRP that used to ship as part of this cookbook has been\nrefactored into the\n[database](http://community.opscode.com/cookbooks/database)\ncookbook. Please see the README for details on updated usage.\n\nAttributes\n==========\n\nSee the `attributes/server.rb` or `attributes/client.rb` for default\nvalues. Several attributes have values that vary based on the node's\nplatform and version.\n\n* `node['mysql']['client']['packages']` - An array of package names\n that should be installed on \"client\" systems. This can be modified,\n e.g., to specify packages for Percona.\n* `node['mysql']['server']['packages']` - An array of package names\n that should be installed on \"server\" systems. This can be modified,\n e.g., to specify packages for Percona.\n\n* `node['mysql']['auto-increment-increment']` -\n auto-increment-increment value in my.cnf\n* `node['mysql']['auto-increment-offset]` - auto-increment-offset\n value in my.cnf\n* `node['mysql']['basedir']` - Base directory where MySQL is installed\n* `node['mysql']['bind_address']` - Listen address for MySQLd\n* `node['mysql']['conf_dir']` - Location for mysql conf directory\n* `node['mysql']['confd_dir']` - Location for mysql conf.d style\n include directory\n* `node['mysql']['data_dir']` - Location for mysql data directory\n* `node['mysql']['ec2_path']` - location of mysql data_dir on EC2\n nodes\n* `node['mysql']['grants_path']` - Path where the grants.sql should be\n written\n* `node['mysql']['mysqladmin_bin']` - Path to the mysqladmin binary\n* `node['mysql']['old_passwords']` - Sets the `old_passwords` value in\n my.cnf.\n* `node['mysql']['pid_file']` - Path to the mysqld.pid file\n* `node['mysql']['port']` - Liten port for MySQLd\n* `node['mysql']['reload_action']` - Action to take when mysql conf\n files are modified. Also allows \"reload\" and \"none\".\n* `node['mysql']['root_group']` - The default group of the \"root\" user\n* `node['mysql']['service_name']` - The name of the mysqld service\n* `node['mysql']['socket']` - Path to the mysqld.sock file\n* `node['mysql']['use_upstart']` - Whether to use upstart for the\n service provider\n* `mysql['root_network_acl']` - Set define the network the root user will be able to login from, default is nil\n\nPerformance and other \"tunable\" attributes are under the\n`node['mysql']['tunable']` attribute, corresponding to the same-named\nparameter in my.cnf, and the default values are used. See\n`attributes/server.rb`.\n\nBy default, a MySQL installation has an anonymous user, allowing anyone\nto log into MySQL without having to have a user account created for\nthem. This is intended only for testing, and to make the installation\ngo a bit smoother. You should remove them before moving into a\nproduction environment.\n\n* `node['mysql']['remove_anonymous_users']` - Remove anonymous users\n\nNormally, root should only be allowed to connect from 'localhost'. This\nensures that someone cannot guess at the root password from the network.\n\n* `node['mysql']['allow_remote_root']` - If true Sets root access from '%'. If false deletes any non-localhost root users.\n\nBy default, MySQL comes with a database named 'test' that anyone can\naccess. This is also intended only for testing, and should be removed\nbefore moving into a production environment. This will also drop any user privileges to the test databae and any DB named test_% .\n\n* `node['mysql']['remove_test_database']` - Delete the test database and access to it.\n\nThe following attributes are randomly generated passwords handled in\nthe `mysql::server` recipe, using the OpenSSL cookbook's\n`secure_password` helper method. These are set using the `set_unless`\nnode attribute method, which allows them to be easily overridden e.g.\nin a role.\n\n* `node['mysql']['server_root_password']` - Set the server's root\n password\n* `node['mysql']['server_repl_password']` - Set the replication user\n 'repl' password\n* `node['mysql']['server_debian_password']` - Set the debian-sys-maint\n user password\n\n## Windows Specific\n\nThe following attributes are specific to Windows platforms.\n\n* `node['mysql']['client']['version']` - The version of MySQL\n connector to install.\n* `node['mysql']['client']['arch']` - Force 32 bit to work with the\n mysql gem\n* `node['mysql']['client']['package_file']` - The MSI file for the\n mysql connector.\n* `node['mysql']['client']['url']` - URL to download the mysql\n connector.\n* `node['mysql']['client']['packages']` - Similar to other platforms,\n this is the name of the client package.\n* `node['mysql']['client']['basedir']` - Base installation location\n* `node['mysql']['client']['lib_dir']` - Libraries under the base location\n* `node['mysql']['client']['bin_dir']` - binary directory under base location\n* `node['mysql']['client']['ruby_dir']` - location where the Ruby\n binaries will be\n\nUsage\n=====\n\nOn client nodes, use the client (or default) recipe:\n\n { \"run_list\": [\"recipe[mysql::client]\"] }\n\nThis will install the MySQL client libraries and development headers\non the system.\n\nOn nodes which may use the `database` cookbook's mysql resources, also\nuse the ruby recipe. This installs the mysql RubyGem in the Ruby\nenvironment Chef is using via `chef_gem`.\n\n { \"run_list\": [\"recipe[mysql::client]\", \"recipe[mysql::ruby]\"] }\n\nIf you need to install the mysql Ruby library as a package for your\nsystem, override the client packages attribute in your node or role.\nFor example, on an Ubuntu system:\n\n {\n \"mysql\": {\n \"client\": {\n \"packages\": [\"mysql-client\", \"libmysqlclient-dev\",\"ruby-mysql\"]\n }\n }\n }\n\nThis creates a resource object for the package and does the\ninstallation before other recipes are parsed. You'll need to have the\nC compiler and such (ie, build-essential on Ubuntu) before running the\nrecipes, but we already do that when installing Chef :-).\n\nOn server nodes, use the server recipe:\n\n { \"run_list\": [\"recipe[mysql::server]\"] }\n\nOn Debian and Ubuntu, this will preseed the mysql-server package with\nthe randomly generated root password in the recipe file. On other\nplatforms, it simply installs the required packages. It will also\ncreate an SQL file, `/etc/mysql/grants.sql`, that will be used to set up\ngrants for the root, repl and debian-sys-maint users.\n\nThe recipe will perform a `node.save` unless it is run under\n`chef-solo` after the password attributes are used to ensure that in\nthe event of a failed run, the saved attributes would be used.\n\nOn EC2 nodes, use the `server_ec2` recipe and the mysql data dir will\nbe set up in the ephmeral storage.\n\n { \"run_list\": [\"recipe[mysql::server_ec2]\"] }\n\nWhen the `ec2_path` doesn't exist we look for a mounted filesystem\n(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\nChef Solo Note\n==============\n\nThese node attributes are stored on the Chef\nserver when using `chef-client`. Because `chef-solo` does not\nconnect to a server or save the node object at all, to have the same\npasswords persist across `chef-solo` runs, you must specify them in\nthe `json_attribs` file used. For example:\n\n {\n \"mysql\": {\n \"server_root_password\": \"iloverandompasswordsbutthiswilldo\",\n \"server_repl_password\": \"iloverandompasswordsbutthiswilldo\",\n \"server_debian_password\": \"iloverandompasswordsbutthiswilldo\"\n },\n \"run_list\":[\"recipe[mysql::server]\"]\n }\n\nLicense and Author\n==================\n\n- Author:: Joshua Timberman ()\n- Author:: AJ Christensen ()\n- Author:: Seth Chisamore ()\n- Author:: Brian Bianco ()\n- Author:: Jesse Howarth ()\n- Author:: Andrew Crump ()\n\nCopyright:: 2009-2013 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","platforms":{"debian":">= 0.0.0","ubuntu":">= 0.0.0","centos":">= 0.0.0","suse":">= 0.0.0","fedora":">= 0.0.0","redhat":">= 0.0.0","scientific":">= 0.0.0","amazon":">= 0.0.0","freebsd":">= 0.0.0","windows":">= 0.0.0","mac_os_x":">= 0.0.0"},"dependencies":{"openssl":">= 0.0.0","build-essential":"> 1.1.0"},"recommendations":{},"suggestions":{"homebrew":">= 0.0.0","windows":">= 0.0.0"},"conflicting":{},"providing":{},"replacing":{},"attributes":{"mysql/server_root_password":{"display_name":"MySQL Server Root Password","description":"Randomly generated password for the mysqld root user","default":"randomly generated","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/bind_address":{"display_name":"MySQL Bind Address","description":"Address that mysqld should listen on","default":"ipaddress","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/data_dir":{"display_name":"MySQL Data Directory","description":"Location of mysql databases","default":"/var/lib/mysql","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"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","default":"/mnt/mysql","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/reload_action":{"display_name":"MySQL conf file reload action","description":"Action to take when mysql conf files are modified","default":"reload","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/tunable":{"display_name":"MySQL Tunables","description":"Hash of MySQL tunable attributes","type":"hash","choice":[],"calculated":false,"required":"optional","recipes":[]},"mysql/tunable/key_buffer":{"display_name":"MySQL Tuntable Key Buffer","default":"250M","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/tunable/max_connections":{"display_name":"MySQL Tunable Max Connections","default":"800","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/tunable/wait_timeout":{"display_name":"MySQL Tunable Wait Timeout","default":"180","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/tunable/net_read_timeout":{"display_name":"MySQL Tunable Net Read Timeout","default":"30","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/tunable/net_write_timeout":{"display_name":"MySQL Tunable Net Write Timeout","default":"30","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/tunable/back_log":{"display_name":"MySQL Tunable Back Log","default":"128","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/tunable/table_cache":{"display_name":"MySQL Tunable Table Cache for MySQL < 5.1.3","default":"128","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/tunable/table_open_cache":{"display_name":"MySQL Tunable Table Cache for MySQL >= 5.1.3","default":"128","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/tunable/max_heap_table_size":{"display_name":"MySQL Tunable Max Heap Table Size","default":"32M","choice":[],"calculated":false,"type":"string","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":[]},"mysql/client":{"display_name":"MySQL Connector/C Client","description":"Hash of MySQL client attributes","type":"hash","choice":[],"calculated":false,"required":"optional","recipes":[]},"mysql/client/version":{"display_name":"MySQL Connector/C Version","default":"6.0.2","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/client/arch":{"display_name":"MySQL Connector/C Architecture","default":"win32","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/client/package_file":{"display_name":"MySQL Connector/C Package File Name","default":"mysql-connector-c-6.0.2-win32.msi","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/client/url":{"display_name":"MySQL Connector/C Download URL","default":"http://www.mysql.com/get/Downloads/Connector-C/mysql-connector-c-6.0.2-win32.msi/from/http://mysql.mirrors.pair.com/","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/client/package_name":{"display_name":"MySQL Connector/C Registry DisplayName","default":"MySQL Connector C 6.0.2","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/client/basedir":{"display_name":"MySQL Connector/C Base Install Directory","default":"C:\\Program Files (x86)\\MySQL\\Connector C 6.0.2","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/client/lib_dir":{"display_name":"MySQL Connector/C Library Directory (containing libmysql.dll)","default":"C:\\Program Files (x86)\\MySQL\\Connector C 6.0.2\\lib\\opt","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/client/bin_dir":{"display_name":"MySQL Connector/C Executable Directory","default":"C:\\Program Files (x86)\\MySQL\\Connector C 6.0.2\\bin","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]},"mysql/client/ruby_dir":{"display_name":"Ruby Executable Directory which should gain MySQL support","default":"system ruby","choice":[],"calculated":false,"type":"string","required":"optional","recipes":[]}},"groupings":{},"recipes":{"mysql":"Includes the client recipe to configure a client","mysql::client":"Installs packages required for mysql clients using run_action magic","mysql::server":"Installs packages required for mysql servers w/o manual intervention","mysql::server_ec2":"Performs EC2-specific mountpoint manipulation"},"version":"3.0.2"} \ No newline at end of file diff --git a/cookbooks/mysql/metadata.rb b/cookbooks/mysql/metadata.rb new file mode 100644 index 0000000..d14cea8 --- /dev/null +++ b/cookbooks/mysql/metadata.rb @@ -0,0 +1,140 @@ +name "mysql" +maintainer "Opscode, Inc." +maintainer_email "cookbooks@opscode.com" +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 "3.0.2" +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" +recipe "mysql::server_ec2", "Performs EC2-specific mountpoint manipulation" + +%w{ debian ubuntu centos suse fedora redhat scientific amazon freebsd windows mac_os_x }.each do |os| + supports os +end + +depends "openssl" +depends "build-essential", "> 1.1.0" +suggests "homebrew" +suggests "windows" + +attribute "mysql/server_root_password", + :display_name => "MySQL Server Root Password", + :description => "Randomly generated password for the mysqld root user", + :default => "randomly generated" + +attribute "mysql/bind_address", + :display_name => "MySQL Bind Address", + :description => "Address that mysqld should listen on", + :default => "ipaddress" + +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", + :default => "/mnt/mysql" + +attribute "mysql/reload_action", + :display_name => "MySQL conf file reload action", + :description => "Action to take when mysql conf files are modified", + :default => "reload" + +attribute "mysql/tunable", + :display_name => "MySQL Tunables", + :description => "Hash of MySQL tunable attributes", + :type => "hash" + +attribute "mysql/tunable/key_buffer", + :display_name => "MySQL Tuntable Key Buffer", + :default => "250M" + +attribute "mysql/tunable/max_connections", + :display_name => "MySQL Tunable Max Connections", + :default => "800" + +attribute "mysql/tunable/wait_timeout", + :display_name => "MySQL Tunable Wait Timeout", + :default => "180" + +attribute "mysql/tunable/net_read_timeout", + :display_name => "MySQL Tunable Net Read Timeout", + :default => "30" + +attribute "mysql/tunable/net_write_timeout", + :display_name => "MySQL Tunable Net Write Timeout", + :default => "30" + +attribute "mysql/tunable/back_log", + :display_name => "MySQL Tunable Back Log", + :default => "128" + +attribute "mysql/tunable/table_cache", + :display_name => "MySQL Tunable Table Cache for MySQL < 5.1.3", + :default => "128" + +attribute "mysql/tunable/table_open_cache", + :display_name => "MySQL Tunable Table Cache for MySQL >= 5.1.3", + :default => "128" + +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" + +attribute "mysql/client", + :display_name => "MySQL Connector/C Client", + :description => "Hash of MySQL client attributes", + :type => "hash" + +attribute "mysql/client/version", + :display_name => "MySQL Connector/C Version", + :default => "6.0.2" + +attribute "mysql/client/arch", + :display_name => "MySQL Connector/C Architecture", + :default => "win32" + +attribute "mysql/client/package_file", + :display_name => "MySQL Connector/C Package File Name", + :default => "mysql-connector-c-6.0.2-win32.msi" + +attribute "mysql/client/url", + :display_name => "MySQL Connector/C Download URL", + :default => "http://www.mysql.com/get/Downloads/Connector-C/mysql-connector-c-6.0.2-win32.msi/from/http://mysql.mirrors.pair.com/" + +attribute "mysql/client/package_name", + :display_name => "MySQL Connector/C Registry DisplayName", + :default => "MySQL Connector C 6.0.2" + +attribute "mysql/client/basedir", + :display_name => "MySQL Connector/C Base Install Directory", + :default => "C:\\Program Files (x86)\\MySQL\\Connector C 6.0.2" + +attribute "mysql/client/lib_dir", + :display_name => "MySQL Connector/C Library Directory (containing libmysql.dll)", + :default => "C:\\Program Files (x86)\\MySQL\\Connector C 6.0.2\\lib\\opt" + +attribute "mysql/client/bin_dir", + :display_name => "MySQL Connector/C Executable Directory", + :default => "C:\\Program Files (x86)\\MySQL\\Connector C 6.0.2\\bin" + +attribute "mysql/client/ruby_dir", + :display_name => "Ruby Executable Directory which should gain MySQL support", + :default => "system ruby" diff --git a/cookbooks/mysql/recipes/client.rb b/cookbooks/mysql/recipes/client.rb new file mode 100644 index 0000000..91787e7 --- /dev/null +++ b/cookbooks/mysql/recipes/client.rb @@ -0,0 +1,59 @@ +# +# Cookbook Name:: mysql +# Recipe:: client +# +# Copyright 2008-2011, 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. +# + +# Include Opscode helper in Recipe class to get access +# to debian_before_squeeze? and ubuntu_before_lucid? +::Chef::Recipe.send(:include, Opscode::Mysql::Helpers) + +case node['platform'] +when "windows" + package_file = node['mysql']['client']['package_file'] + remote_file "#{Chef::Config[:file_cache_path]}/#{package_file}" do + source node['mysql']['client']['url'] + not_if { File.exists? "#{Chef::Config[:file_cache_path]}/#{package_file}" } + end + + windows_package node['mysql']['client']['packages'].first do + source "#{Chef::Config[:file_cache_path]}/#{package_file}" + end + windows_path node['mysql']['client']['bin_dir'] do + action :add + end + def package(*args, &blk) + windows_package(*args, &blk) + end +when "mac_os_x" + include_recipe 'homebrew' +end + +node['mysql']['client']['packages'].each do |mysql_pack| + package mysql_pack do + action :install + end +end + +if platform? 'windows' + ruby_block "copy libmysql.dll into ruby path" do + block do + require 'fileutils' + FileUtils.cp "#{node['mysql']['client']['lib_dir']}\\libmysql.dll", node['mysql']['client']['ruby_dir'] + end + not_if { File.exist?("#{node['mysql']['client']['ruby_dir']}\\libmysql.dll") } + end +end diff --git a/cookbooks/mysql/recipes/default.rb b/cookbooks/mysql/recipes/default.rb new file mode 100644 index 0000000..9ff90d6 --- /dev/null +++ b/cookbooks/mysql/recipes/default.rb @@ -0,0 +1,20 @@ +# +# Cookbook Name:: mysql +# Recipe:: default +# +# Copyright 2008-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. +# + +include_recipe "mysql::client" diff --git a/cookbooks/mysql/recipes/percona_repo.rb b/cookbooks/mysql/recipes/percona_repo.rb new file mode 100644 index 0000000..f629e79 --- /dev/null +++ b/cookbooks/mysql/recipes/percona_repo.rb @@ -0,0 +1,48 @@ +# +# Cookbook Name:: mysql +# Recipe:: percona_repo +# +# Copyright 2008-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. +# + + +case node['platform'] +when "ubuntu", "debian" + include_recipe "apt" + apt_repository "percona" do + uri node['mysql']['percona']['apt_uri'] + distribution node['lsb']['codename'] + components [ "main" ] + keyserver node['mysql']['percona']['apt_keyserver'] + key node['mysql']['percona']['apt_key_id'] + action :add + end +when "centos", "amazon", "redhat" + include_recipe "yum" + yum_key "RPM-GPG-KEY-percona" do + url "http://www.percona.com/downloads/RPM-GPG-KEY-percona" + action :add + end + arch = node['kernel']['machine'] + arch = "i386" unless arch == "x86_64" + pversion = node['platform_version'].split('.').first + yum_repository "percona" do + repo_name "Percona" + description "Percona Repo" + url "http://repo.percona.com/centos/#{pversion}/os/#{arch}/" + key "RPM-GPG-KEY-percona" + action :add + end +end diff --git a/cookbooks/mysql/recipes/ruby.rb b/cookbooks/mysql/recipes/ruby.rb new file mode 100644 index 0000000..8c8470d --- /dev/null +++ b/cookbooks/mysql/recipes/ruby.rb @@ -0,0 +1,31 @@ +# +# Cookbook Name:: mysql +# Recipe:: ruby +# +# Author:: Jesse Howarth () +# Author:: Jamie Winsor () +# +# Copyright 2008-2012, 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. +# + +node.set['build_essential']['compiletime'] = true +include_recipe "build-essential" +include_recipe "mysql::client" + +node['mysql']['client']['packages'].each do |mysql_pack| + resources("package[#{mysql_pack}]").run_action(:install) +end + +chef_gem "mysql" diff --git a/cookbooks/mysql/recipes/server.rb b/cookbooks/mysql/recipes/server.rb new file mode 100644 index 0000000..5a4b3fc --- /dev/null +++ b/cookbooks/mysql/recipes/server.rb @@ -0,0 +1,221 @@ +# +# Cookbook Name:: mysql +# Recipe:: default +# +# Copyright 2008-2011, 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. +# + +::Chef::Recipe.send(:include, Opscode::OpenSSL::Password) + +include_recipe "mysql::client" + +if Chef::Config[:solo] + missing_attrs = %w{ + server_debian_password server_root_password server_repl_password + }.select do |attr| + node["mysql"][attr].nil? + end.map { |attr| "node['mysql']['#{attr}']" } + + if !missing_attrs.empty? + Chef::Application.fatal!([ + "You must set #{missing_attrs.join(', ')} in chef-solo mode.", + "For more information, see https://github.com/opscode-cookbooks/mysql#chef-solo-note" + ].join(' ')) + end +else + # generate all passwords + node.set_unless['mysql']['server_debian_password'] = secure_password + node.set_unless['mysql']['server_root_password'] = secure_password + node.set_unless['mysql']['server_repl_password'] = secure_password + node.save +end + +if platform_family?(%w{debian}) + + directory "/var/cache/local/preseeding" do + owner "root" + group node['mysql']['root_group'] + mode 0755 + recursive true + end + + execute "preseed mysql-server" do + command "debconf-set-selections /var/cache/local/preseeding/mysql-server.seed" + action :nothing + end + + template "/var/cache/local/preseeding/mysql-server.seed" do + source "mysql-server.seed.erb" + owner "root" + group node['mysql']['root_group'] + mode "0600" + notifies :run, "execute[preseed mysql-server]", :immediately + end + + template "#{node['mysql']['conf_dir']}/debian.cnf" do + source "debian.cnf.erb" + owner "root" + group node['mysql']['root_group'] + mode "0600" + end + +end + +if platform_family?('windows') + package_file = node['mysql']['package_file'] + + remote_file "#{Chef::Config[:file_cache_path]}/#{package_file}" do + source node['mysql']['url'] + not_if { File.exists? "#{Chef::Config[:file_cache_path]}/#{package_file}" } + end + + windows_package node['mysql']['server']['packages'].first do + source "#{Chef::Config[:file_cache_path]}/#{package_file}" + end + + def package(*args, &blk) + windows_package(*args, &blk) + end +end + +node['mysql']['server']['packages'].each do |package_name| + package package_name do + action :install + notifies :start, "service[mysql]", :immediately + end +end + +unless platform_family?(%w{mac_os_x}) + + [File.dirname(node['mysql']['pid_file']), + File.dirname(node['mysql']['tunable']['slow_query_log']), + node['mysql']['conf_dir'], + node['mysql']['confd_dir'], + node['mysql']['log_dir'], + node['mysql']['data_dir']].each do |directory_path| + directory directory_path do + owner "mysql" unless platform? 'windows' + group "mysql" unless platform? 'windows' + action :create + recursive true + end + end + + if platform_family? 'windows' + require 'win32/service' + + windows_path node['mysql']['bin_dir'] do + action :add + end + + windows_batch "install mysql service" do + command "\"#{node['mysql']['bin_dir']}\\mysqld.exe\" --install #{node['mysql']['service_name']}" + not_if { Win32::Service.exists?(node['mysql']['service_name']) } + end + end + + skip_federated = case node['platform'] + when 'fedora', 'ubuntu', 'amazon' + true + when 'centos', 'redhat', 'scientific' + node['platform_version'].to_f < 6.0 + else + false + end +end + +# Homebrew has its own way to do databases +if platform_family?(%w{mac_os_x}) + execute "mysql-install-db" do + command "mysql_install_db --verbose --user=`whoami` --basedir=\"$(brew --prefix mysql)\" --datadir=#{node['mysql']['data_dir']} --tmpdir=/tmp" + environment('TMPDIR' => nil) + action :run + creates "#{node['mysql']['data_dir']}/mysql" + end +else + execute 'mysql-install-db' do + command "mysql_install_db" + action :run + not_if { File.exists?(node['mysql']['data_dir'] + '/mysql/user.frm') } + end + + service "mysql" do + service_name node['mysql']['service_name'] + if node['mysql']['use_upstart'] + provider Chef::Provider::Service::Upstart + end + supports :status => true, :restart => true, :reload => true + action :enable + end +end + +# set the root password for situations that don't support pre-seeding. +# (eg. platforms other than debian/ubuntu & drop-in mysql replacements) +execute "assign-root-password" do + command "\"#{node['mysql']['mysqladmin_bin']}\" -u root password \"#{node['mysql']['server_root_password']}\"" + action :run + only_if "\"#{node['mysql']['mysql_bin']}\" -u root -e 'show databases;'" +end + +unless platform_family?(%w{mac_os_x}) + grants_path = node['mysql']['grants_path'] + + begin + t = resources("template[#{grants_path}]") + rescue + Chef::Log.info("Could not find previously defined grants.sql resource") + t = template grants_path do + source "grants.sql.erb" + owner "root" unless platform_family? 'windows' + group node['mysql']['root_group'] unless platform_family? 'windows' + mode "0600" + action :create + end + end + + if platform_family? 'windows' + windows_batch "mysql-install-privileges" do + command "\"#{node['mysql']['mysql_bin']}\" -u root #{node['mysql']['server_root_password'].empty? ? '' : '-p' }\"#{node['mysql']['server_root_password']}\" < \"#{grants_path}\"" + action :nothing + subscribes :run, resources("template[#{grants_path}]"), :immediately + end + else + execute "mysql-install-privileges" do + command %Q["#{node['mysql']['mysql_bin']}" -u root #{node['mysql']['server_root_password'].empty? ? '' : '-p' }"#{node['mysql']['server_root_password']}" < "#{grants_path}"] + action :nothing + subscribes :run, resources("template[#{grants_path}]"), :immediately + end + end + + template "#{node['mysql']['conf_dir']}/my.cnf" do + source "my.cnf.erb" + owner "root" unless platform? 'windows' + group node['mysql']['root_group'] unless platform? 'windows' + mode "0644" + case node['mysql']['reload_action'] + when 'restart' + notifies :restart, "service[mysql]", :immediately + when 'reload' + notifies :reload, "service[mysql]", :immediately + else + Chef::Log.info "my.cnf updated but mysql.reload_action is #{node['mysql']['reload_action']}. No action taken." + end + variables :skip_federated => skip_federated + end + + service "mysql" do + action :start + end +end diff --git a/cookbooks/mysql/recipes/server_ec2.rb b/cookbooks/mysql/recipes/server_ec2.rb new file mode 100644 index 0000000..6033ef4 --- /dev/null +++ b/cookbooks/mysql/recipes/server_ec2.rb @@ -0,0 +1,51 @@ +# +# Cookbook Name:: mysql +# Recipe:: default +# +# Copyright 2008-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. +# + + +if (node.attribute?('ec2') && ! FileTest.directory?(node['mysql']['ec2_path'])) + + service "mysql" do + action :stop + end + + execute "install-mysql" do + command "mv #{node['mysql']['data_dir']} #{node['mysql']['ec2_path']}" + not_if do FileTest.directory?(node['mysql']['ec2_path']) end + end + + [node['mysql']['ec2_path'], node['mysql']['data_dir']].each do |dir| + directory dir do + owner "mysql" + group "mysql" + end + end + + mount node['mysql']['data_dir'] do + device node['mysql']['ec2_path'] + fstype "none" + options "bind,rw" + action [:mount, :enable] + end + + service "mysql" do + action :start + end + +end + diff --git a/cookbooks/mysql/templates/default/debian.cnf.erb b/cookbooks/mysql/templates/default/debian.cnf.erb new file mode 100644 index 0000000..989b125 --- /dev/null +++ b/cookbooks/mysql/templates/default/debian.cnf.erb @@ -0,0 +1,12 @@ +[client] +host = localhost +user = debian-sys-maint +password = <%= node['mysql']['server_debian_password'] %> +socket = <%= node['mysql']['socket'] %> + +[mysql_upgrade] +host = localhost +user = debian-sys-maint +password = <%= node['mysql']['server_debian_password'] %> +socket = <%= node['mysql']['socket'] %> +basedir = /usr diff --git a/cookbooks/mysql/templates/default/grants.sql.erb b/cookbooks/mysql/templates/default/grants.sql.erb new file mode 100644 index 0000000..79924af --- /dev/null +++ b/cookbooks/mysql/templates/default/grants.sql.erb @@ -0,0 +1,40 @@ +# Generated by Chef for <%= node['hostname'] %>. +# Local modifications will be overwritten. +<% case node['platform_family'] -%> +<% when "debian" -%> + +# Grant privileges for debian-sys-main user +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '<%= node['mysql']['server_debian_password'] %>' WITH GRANT OPTION; +<% end %> + +# Grant replication for a slave user. +GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' identified by '<%= node['mysql']['server_repl_password'] %>'; +<% if node['mysql']['allow_remote_root'] -%> + +# Set the server root password. This should be preseeded by the package installation. +GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '<%= node['mysql']['server_root_password'] %>' WITH GRANT OPTION; +<% else %> + +# remove remote access for root user and set password for local root user +DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1'); +UPDATE mysql.user SET Password=PASSWORD('<%= node['mysql']['server_root_password'] %>') WHERE User='root'; +<% end %> +<% if node['mysql']['remove_anonymous_users'] -%> + +# Remove anonymous users +DELETE FROM mysql.user WHERE User=''; +<% end %> +<% if node['mysql']['remove_test_database'] -%> + +# Remove test database and access to it +DROP DATABASE IF EXISTS test; +DELETE FROM mysql.db WHERE Db='test' OR Db='test\_%'; +<% end %> + +# Set the password for root@localhost +SET PASSWORD FOR 'root'@'localhost' = PASSWORD('<%= node['mysql']['server_root_password'] %>'); +<% if node['mysql']['root_network_acl'] -%> + +# allow root to connect from a remote network if root_network_acl is not nil +SET PASSWORD FOR 'root'@'<%= node['mysql']['root_network_acl'] %>' = PASSWORD('<%= node['mysql']['server_root_password'] %>'); +<% end -%> diff --git a/cookbooks/mysql/templates/default/my.cnf.erb b/cookbooks/mysql/templates/default/my.cnf.erb new file mode 100644 index 0000000..1022976 --- /dev/null +++ b/cookbooks/mysql/templates/default/my.cnf.erb @@ -0,0 +1,317 @@ +# +# Generated by Chef for <%= node['hostname'] %> +# +# Local modifications will be overwritten. +# +# The MySQL database server configuration file. +# +# You can copy this to one of: +# - "/etc/mysql/my.cnf" to set global options, +# - "~/.my.cnf" to set user-specific options. +# +# One can use all long options that the program supports. +# Run program with --help to get a list of available options and with +# --print-defaults to see which it would actually understand and use. +# +# For explanations see +# http://dev.mysql.com/doc/mysql/en/server-system-variables.html + +# This will be passed to all mysql clients +# It has been reported that passwords should be enclosed with ticks/quotes +# escpecially if they contain "#" chars... +# Remember to edit /etc/mysql/debian.cnf when changing the socket location. +[client] +port = <%= node['mysql']['port'] %> +socket = <%= node['mysql']['socket'] %> + +# Here is entries for some specific programs +# The following values assume you have at least 32M ram + +# This was formally known as [safe_mysqld]. Both versions are currently parsed. +[mysqld_safe] +socket = <%= node['mysql']['socket'] %> +nice = <%= node['mysql']['nice'] %> + +[mysqld] +# +# * Basic Settings +# + +# +# * IMPORTANT +# If you make changes to these settings and your system uses apparmor, you may +# also need to also adjust /etc/apparmor.d/usr.sbin.mysqld. +# + +user = mysql +pid-file = <%= node['mysql']['pid_file'] %> +socket = <%= node['mysql']['socket'] %> +port = <%= node['mysql']['port'] %> +basedir = <%= node['mysql']['basedir'] %> +datadir = <%= node['mysql']['data_dir'] %> +tmpdir = <%= node['mysql']['tmpdir'].join(':') %> +skip-external-locking +<%- if node['mysql']['tunable']['skip-name-resolve'] %> +skip-name-resolve +<%- end %> + +# Charset and Collation +character-set-server = <%= node['mysql']['tunable']['character-set-server'] %> +collation-server = <%= node['mysql']['tunable']['collation-server'] %> +<%- if node['mysql']['tunable']['lower_case_table_names'] %> +lower_case_table_names = <%= node['mysql']['tunable']['lower_case_table_names'] %> +<%- end %> +<%- if node['mysql']['tunable']['event_scheduler'] %> +event_scheduler = <%= node['mysql']['tunable']['event_scheduler'] %> +<%- end %> +<%- if node['mysql']['tunable']['skip-character-set-client-handshake'] %> +skip-character-set-client-handshake +<%- end %> +<%- if (node['mysql']['tunable']['lc_messages_dir'] && node['mysql']['tunable']['lc_messages']) %> +lc_messages_dir = <%= node['mysql']['lc_messages_dir'] %> +lc_messages = <%= node['mysql']['lc_messages'] %> +<%- elsif (node['mysql']['tunable']['languages']) %> +languages = <%= node['mysql']['tunable']['languages'] %> +<%- end %> + +# +# Instead of skip-networking the default is now to listen only on +# localhost which is more compatible and is not less secure. +bind-address = <%= node['mysql']['bind_address'] %> +# +# * Fine Tuning +# +key_buffer_size = <%= node['mysql']['tunable']['key_buffer_size'] %> +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'] %> +sort_buffer_size = <%= node['mysql']['tunable']['sort_buffer_size'] %> +read_buffer_size = <%= node['mysql']['tunable']['read_buffer_size'] %> +read_rnd_buffer_size = <%= node['mysql']['tunable']['read_rnd_buffer_size'] %> +join_buffer_size = <%= node['mysql']['tunable']['join_buffer_size'] %> + +auto-increment-increment = <%= node['mysql']['auto-increment-increment'] %> +auto-increment-offset = <%= node['mysql']['auto-increment-offset'] %> + +# This replaces the startup script and checks MyISAM tables if needed +# the first time they are touched +myisam-recover = <%= node['mysql']['tunable']['myisam-recover'] %> +max_connections = <%= node['mysql']['tunable']['max_connections'] %> +max_connect_errors = <%= node['mysql']['tunable']['max_connect_errors'] %> +concurrent_insert = <%= node['mysql']['tunable']['concurrent_insert'] %> +connect_timeout = <%= node['mysql']['tunable']['connect_timeout'] %> +wait_timeout = <%= node['mysql']['tunable']['wait_timeout'] %> +net_read_timeout = <%= node['mysql']['tunable']['net_read_timeout'] %> +net_write_timeout = <%= node['mysql']['tunable']['net_write_timeout'] %> +back_log = <%= node['mysql']['tunable']['back_log'] %> +table_cache = <%= node['mysql']['tunable']['table_cache'] %> +<%- if node['mysql']['tunable']['table_open_cache'] %> +table_open_cache = <%= node['mysql']['tunable']['table_open_cache'] %> +<%- end %> +tmp_table_size = <%= node['mysql']['tunable']['tmp_table_size'] %> +max_heap_table_size = <%= node['mysql']['tunable']['max_heap_table_size'] %> +bulk_insert_buffer_size = <%= node['mysql']['tunable']['bulk_insert_buffer_size'] %> +open-files-limit = <%= node['mysql']['tunable']['open-files-limit'] %> + +# Default Table Settings +<%- if node['mysql']['tunable']['sql_mode'] %> +sql_mode = "<%= node['mysql']['tunable']['sql_mode'] %>" +<%- end %> + +# +# * Query Cache Configuration +# +query_cache_limit = <%= node['mysql']['tunable']['query_cache_limit'] %> +query_cache_size = <%= node['mysql']['tunable']['query_cache_size'] %> +# +# * Logging +# +# Both location gets rotated by the cronjob. +# Be aware that this log type is a performance killer. +#log = /var/log/mysql/mysql.log +# +# Error logging goes to syslog. This is a Debian improvement :) +<%- if node['mysql']['tunable']['log_error'] %> +log_error = <%= node['mysql']['tunable']['log_error'] %> +<%- end %> +<%- if node['mysql']['tunable']['log_warnings'] %> +log_warnings +<%- end %> +# +# * Replication +# + + +# +# Here you can see queries with especially long duration +<%- if node['mysql']['version'].to_f >= 5.5 %> +slow_query_log = <%= node['mysql']['tunable']['slow_query_log'] %> +<% else %> +log_slow_queries = <%= node['mysql']['tunable']['slow_query_log'] %> +<% end %> + +long_query_time = <%= node['mysql']['tunable']['long_query_time'] %> +<%- if node['mysql']['tunable']['log_queries_not_using_index'] and node['mysql']['slow_query_log'] %> +log-queries-not-using-indexes +<%- end %> +# +# The following can be used as easy to replay backup logs or for replication. +# note: if you are setting up a replication slave, see README.Debian about +# other settings you may need to change. +<%- if node['mysql']['tunable']['server_id'] %> +server-id = <%= node['mysql']['tunable']['server_id'] %> +<% end %> +<%- if node['mysql']['tunable']['log_bin'] %> +log_bin = <%= node['mysql']['tunable']['log_bin'] %> +<%- if node['mysql']['tunable']['log_bin'] %> +binlog_format = <%= node['mysql']['tunable']['binlog_format'] %> +<%- end %> +log_slave_updates = <%= node['mysql']['tunable']['log_slave_updates'] %> +<%- end %> +<%- if node['mysql']['tunable']['log_bin_trust_function_creators'] %> +log_bin_trust_function_creators +<%- end %> +expire_logs_days = <%= node['mysql']['tunable']['expire_logs_days'] %> +max_binlog_size = <%= node['mysql']['tunable']['max_binlog_size'] %> +binlog_cache_size = <%= node['mysql']['tunable']['binlog_cache_size'] %> +#binlog_do_db = include_database_name +#binlog_ignore_db = include_database_name +<%- if node['mysql']['tunable']['relay_log'] %> +relay_log = <%= node['mysql']['tunable']['relay_log'] %> +<%- end %> +<%- if node['mysql']['tunable']['relay_log_index'] %> +relay_log_index = <%= node['mysql']['tunable']['relay_log_index'] %> +<%- end %> + +sync_binlog = <%= node['mysql']['tunable']['sync_binlog'] %> +<%- if node['mysql']['tunable']['skip_slave_start'] %> +skip_slave_start +<%- end %> +<%- if node['mysql']['tunable']['read_only'] %> +read_only = 1 +<%- end %> + +<%- if node['mysql']['tunable']['transaction-isolation'] %> +transaction-isolation = <%= node['mysql']['tunable']['transaction-isolation'] %> +<%- end %> + +<%- if node['mysql']['tunable']['slave_compressed_protocol'] %> +slave_compressed_protocol = <%= node['mysql']['tunable']['slave_compressed_protocol'] %> +<%- end %> +# +# * InnoDB +# +# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. +# Read the manual for more InnoDB related options. There are many! +# You might want to disable InnoDB to shrink the mysqld process by circa 100MB. +#skip-innodb + +<%- if node["mysql"]["version"].to_f >= 5.5 %> +innodb_write_io_threads = <%= node['mysql']['tunable']['innodb_write_io_threads'] %> +innodb_io_capacity = <%= node['mysql']['tunable']['innodb_io_capacity'] %> +innodb_read_io_threads = <%= node['mysql']['tunable']['innodb_read_io_threads'] %> +innodb_buffer_pool_instances = <%= node['mysql']['tunable']['innodb_buffer_pool_instances'] %> +<%- end %> + +## InnoDB Plugin Independent Settings +innodb_data_home_dir = <%= node['mysql']['data_dir'] %> +innodb_log_group_home_dir = <%= node['mysql']['log_dir'] %> +<%- if node['mysql']['log_files_in_group'] %> +innodb_log_files_in_group = <%= node['mysql']['log_files_in_group'] %> +<%- end %> + +<%- if node['mysql']['innodb_status_file'] %> +innodb_status_file +<%- end %> +<%- if node['mysql']['tunable']['innodb_file_per_table'] %> +innodb_file_per_table +<%- end %> +innodb_table_locks = <%= node['mysql']['tunable']['innodb_table_locks'] %> +innodb_lock_wait_timeout = <%= node['mysql']['tunable']['innodb_lock_wait_timeout'] %> +innodb_thread_concurrency = <%= node['mysql']['tunable']['innodb_thread_concurrency'] %> +innodb_commit_concurrency = <%= node['mysql']['tunable']['innodb_commit_concurrency'] %> +innodb_support_xa = <%= node['mysql']['tunable']['innodb_support_xa'] %> +<%- if node['mysql']['tunable']['skip-innodb-doublewrite'] %> +skip-innodb-doublewrite +<%- end %> + +innodb_buffer_pool_size = <%= node['mysql']['tunable']['innodb_buffer_pool_size'] %> +innodb_log_file_size = <%= node['mysql']['tunable']['innodb_log_file_size'] %> +innodb_additional_mem_pool_size = <%= node['mysql']['tunable']['innodb_additional_mem_pool_size'] %> +innodb_data_file_path = <%= node['mysql']['tunable']['innodb_data_file_path'] %> +innodb_flush_log_at_trx_commit = <%= node['mysql']['tunable']['innodb_flush_log_at_trx_commit'] %> +<%- if node['mysql']['tunable']['innodb_flush_method'] %> +innodb_flush_method = <%= node['mysql']['tunable']['innodb_flush_method'] %> +<%- end %> +innodb_log_buffer_size = <%= node['mysql']['tunable']['innodb_log_buffer_size'] %> +<%- if node['mysql']['tunable']['innodb_adaptive_flushing'] %> +innodb_adaptive_flushing = <%= node['mysql']['tunable']['innodb_adaptive_flushing'] %> +<%- end %> + +<% if @skip_federated %> +# +# * Federated +# +# The FEDERATED storage engine is disabled since 5.0.67 by default in the .cnf files +# shipped with MySQL distributions (my-huge.cnf, my-medium.cnf, and so forth). +# +skip-federated +<% end %> +# +# * Security Features +# +# Read the manual, too, if you want chroot! +# chroot = /var/lib/mysql/ +# +# For generating SSL certificates I recommend the OpenSSL GUI "tinyca". +# +# ssl-ca=/etc/mysql/cacert.pem +# ssl-cert=/etc/mysql/server-cert.pem +# ssl-key=/etc/mysql/server-key.pem + +[mysqldump] +quick +quote-names +max_allowed_packet = <%= node['mysql']['tunable']['max_allowed_packet'] %> + +[mysql] +#no-auto-rehash # faster start of mysql but no tab completition + +[myisamchk] +key_buffer = <%= node['mysql']['tunable']['max_allowed_packet'] %> + +myisam_sort_buffer_size = <%= node['mysql']['tunable']['myisam_sort_buffer_size'] %> +myisam_max_sort_file_size = <%= node['mysql']['tunable']['myisam_max_sort_file_size'] %> +myisam_repair_threads = <%= node['mysql']['tunable']['myisam_repair_threads'] %> +myisam-recover = <%= node['mysql']['tunable']['myisam-recover'] %> + +# +# * NDB Cluster +# +# See /usr/share/doc/mysql-server-*/README.Debian for more information. +# +# The following configuration is read by the NDB Data Nodes (ndbd processes) +# not from the NDB Management Nodes (ndb_mgmd processes). +# +# [MYSQL_CLUSTER] +# ndb-connectstring=127.0.0.1 + +<% case node['platform_family'] -%> +<% when "rhel", "fedora", "suse" -%> +# +# * BerkeleyDB +# +# Using BerkeleyDB is now discouraged as its support will cease in 5.1.12. +skip-bdb +# Default to using old password format for compatibility with mysql 3.x +# clients (those using the mysqlclient10 compatibility package). +old_passwords = <%= node['mysql']['old_passwords'] %> +<% end -%> + +<% if node['mysql']['confd_dir'] -%> +# +# * IMPORTANT: Additional settings that can override those from this file! +# The files must end with '.cnf', otherwise they'll be ignored. +# +!includedir <%= node['mysql']['confd_dir'] %>/ +<% end -%> diff --git a/cookbooks/mysql/templates/default/mysql-server.seed.erb b/cookbooks/mysql/templates/default/mysql-server.seed.erb new file mode 100644 index 0000000..a5a74f0 --- /dev/null +++ b/cookbooks/mysql/templates/default/mysql-server.seed.erb @@ -0,0 +1,10 @@ +mysql-server-5.0 mysql-server/root_password_again select <%= node['mysql']['server_root_password'] %> +mysql-server-5.0 mysql-server/root_password select <%= node['mysql']['server_root_password'] %> +mysql-server-5.0 mysql-server-5.0/really_downgrade boolean false +mysql-server-5.0 mysql-server-5.0/need_sarge_compat boolean false +mysql-server-5.0 mysql-server-5.0/start_on_boot boolean true +mysql-server-5.0 mysql-server/error_setting_password boolean false +mysql-server-5.0 mysql-server-5.0/nis_warning note +mysql-server-5.0 mysql-server-5.0/postrm_remove_databases boolean false +mysql-server-5.0 mysql-server/password_mismatch boolean false +mysql-server-5.0 mysql-server-5.0/need_sarge_compat_done boolean true diff --git a/cookbooks/mysql/templates/default/port_mysql.erb b/cookbooks/mysql/templates/default/port_mysql.erb new file mode 100644 index 0000000..55a2ffc --- /dev/null +++ b/cookbooks/mysql/templates/default/port_mysql.erb @@ -0,0 +1,3 @@ +# MySQL +-A FWR -p tcp -m tcp --dport 3306 -j ACCEPT +-A FWR -p udp -m udp --dport 3306 -j ACCEPT \ No newline at end of file diff --git a/cookbooks/mysql/templates/windows/my.cnf.erb b/cookbooks/mysql/templates/windows/my.cnf.erb new file mode 100644 index 0000000..f0550c1 --- /dev/null +++ b/cookbooks/mysql/templates/windows/my.cnf.erb @@ -0,0 +1,61 @@ +# +# Generated by Chef for <%= node['hostname'] %> +# +# Local modifications will be overwritten. +# +# The MySQL database server configuration file. +# +# One can use all long options that the program supports. +# Run program with --help to get a list of available options and with +# --print-defaults to see which it would actually understand and use. +# +# For explanations see +# http://dev.mysql.com/doc/mysql/en/server-system-variables.html + +# This will be passed to all mysql clients +# It has been reported that passwords should be enclosed with ticks/quotes +# escpecially if they contain "#" chars... +[client] +port = 3306 + +[mysql] +default-character-set = latin1 + +[mysqld] +# +# * Basic Settings +# +port = 3306 +basedir = <%= node['mysql']['basedir'] %> +datadir = <%= node['mysql']['data_dir'] %> +character-set-server = latin1 +default-storage-engine = INNODB +sql-mode = "STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" + +# +# * Fine Tuning +# +thread_cache_size = <%= node['mysql']['tunable']['thread_cache_size'] %> +max_connections = <%= node['mysql']['tunable']['max_connections'] %> +table_cache = <%= node['mysql']['tunable']['table_cache'] %> +query_cache_size = <%= node['mysql']['tunable']['query_cache_size'] %> +tmp_table_size = 5M +myisam_max_sort_file_size = 100G +myisam_sort_buffer_size = 8M +key_buffer_size = 8M +read_buffer_size = 64K +read_rnd_buffer_size = 256K +sort_buffer_size = 212K + +# +# * InnoDB +# +# Read the manual for more InnoDB related options. There are many! +# You might want to disable InnoDB to shrink the mysqld process by circa 100MB. +# +innodb_additional_mem_pool_size = 2M +innodb_flush_log_at_trx_commit = 1 +innodb_log_buffer_size = 1M +innodb_buffer_pool_size = <%= node['mysql']['tunable']['innodb_buffer_pool_size'] %> +innodb_log_file_size = 10M +innodb_thread_concurrency = 8