Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 168 lines (119 sloc) 6.447 kB
957cf6d @jtimberman Add database cookbook
jtimberman authored
1 Database Cookbook
2 =================
3
4 Configures mysql database masters and slaves and uses EBS for storage, integrating together with the application cookbook utilizing data bags for application related information.
5
6 This cookbook is written primarily to use MySQL and the Opscode mysql cookbook. Other RDBMS may be supported at a later date.
7
8 This cookbook does not automatically restore database dumps, but does install tools to help with that.
9
10 ---
e0f4403 @jtimberman Database and application README updates.
jtimberman authored
11 Requirements
12 ============
13
14 Chef 0.8 or higher required.
15
16 The following Opscode cookbooks are dependencies:
17
18 * mysql
19 * xfs
20 * aws
21
22 ---
957cf6d @jtimberman Add database cookbook
jtimberman authored
23 Recipes
24 =======
25
26 ebs_volume
27 ----------
28
29 Loads the aws information from the data bag. Searches the applications data bag for the database master or slave role and checks that role is applied to the node. Loads the EBS information and the master information from data bags. Uses the aws cookbook LWRP, `aws_ebs_volume` to manage the volume.
30
31 On a master node:
32 * if we have an ebs volume already as stored in a data bag, attach it.
33 * if we don't have the ebs information then create a new one and attach it.
34 * store the volume information in a data bag via a ruby block.
35
36 On a slave node:
37 * use the master volume information to generate a snapshot.
38 * create the new volume from the snapshot and attach it.
39
40 Also on a master node, generate some configuration for running a snapshot via `chef-solo` from cron.
41
42 On a new filesystem volume, create as XFS, then mount it in /mnt, and also bind-mount it to the mysql data directory (default /var/lib/mysql).
43
44 master
45 ------
46
e0f4403 @jtimberman Database and application README updates.
jtimberman authored
47 This recipe no longer loads AWS specific information, and the database position for replication is no longer stored in a databag because the client might not have permission to write to the databag item. This may be handled in a different way at a future date.
48
49 Searches the apps databag for applications, and for each one it will check that the specified database master role is set in both the databag and applied to the node's run list. Then, retrieves the passwords for `root`, `repl` and `debian` users and saves them to the node attributes. If the passwords are not found in the databag, it prints a message that they'll be generated by the mysql cookbook.
50
51 Then it adds the application databag database settings to a hash, to use later.
52
53 It sets up the template resource for `/etc/mysql/grants.sql`, passing in the database settings so privileges for application specific database users can be created.
54
55 Then it will iterate over the databases and create them with the mysqladmin command, detecting their presence with the mysql rubygem. At a later date the database creation will probably be handed off to a resource/provider that uses the rubygem.
957cf6d @jtimberman Add database cookbook
jtimberman authored
56
57 slave
58 -----
59
e0f4403 @jtimberman Database and application README updates.
jtimberman authored
60 _TODO_: Retrieve the master status from a data bag, then start replication using a ruby block. The replication status needs to be handled in some other way for now since the master recipe above doesn't actually set it in the databag anymore.
957cf6d @jtimberman Add database cookbook
jtimberman authored
61
62 snapshot
63 --------
64
65 Run via chef-solo. Retrieves the db snapshot configuration from the specified JSON file. Uses the `mysql_database` LWRP to lock and unlock tables, and does a filesystem freeze and EBS snapshot.
66
67 ---
68 Deprecated Recipes
69 ==================
70
71 The following recipes are no longer used as they have been deprecated in functionality both the above.
72
73 ebs_backup
74 ----------
75
e0f4403 @jtimberman Database and application README updates.
jtimberman authored
76 Older style of doing mysql snapshot and replication using Adam Jacob's [ec2_mysql][0] script and library.
957cf6d @jtimberman Add database cookbook
jtimberman authored
77
78 [0]: http://github.com/adamhjk/ec2_mysql
79
80 ---
81 Data Bags
82 =========
83
84 This recipe uses the apps data bag item for the specified application; see the `application` cookbook's README.txt. It also creates data bag items in a bag named 'aws' for storing volume information. In order to interact with EC2, it expects aws to have a main item:
85
86 {
87 "id": "main",
88 "ec2_private_key": "private key as a string",
89 "ec2_cert": "certificate as a string",
90 "aws_account_id": "",
91 "aws_secret_access_key": "",
92 "aws_access_key_id": ""
93 }
94
95 Note: with the Open Source Chef Server, the server using the database recipes must be an admin client or it will not be able to create data bag items. You can modify whether the client is admin by editing it with knife.
96
97 knife client edit <client_name>
98 {
99 ...
100 "admin": true
101 ...
102 }
103
104 This is not required if the Chef Server is the Opscode Platform.
105
106 ---
107 Usage
108 =====
109
e0f4403 @jtimberman Database and application README updates.
jtimberman authored
110 Aside from the application data bag (see the README in the application cookbook), create a role for the database master. Use a role.rb in your chef-repo, or create the role directly with knife.
111
112 % knife role show my_app_database_master
113 {
114 "name": "my_app_database_master",
115 "chef_type": "role",
116 "json_class": "Chef::Role",
117 "default_attributes": {
118 },
119 "description": "",
120 "run_list": [
121 "recipe[mysql::server]",
122 "recipe[database::master]"
123 ],
124 "override_attributes": {
125 }
126 }
957cf6d @jtimberman Add database cookbook
jtimberman authored
127
e0f4403 @jtimberman Database and application README updates.
jtimberman authored
128 Also create a `production` role, or other role based on your desired environment. This is also used in the `application` cookbook.
129
130 % knife role show production
131 {
132 "name": "production",
133 "chef_type": "role",
134 "json_class": "Chef::Role",
135 "default_attributes": {
136 "app_environment": "production"
137 },
138 "description": "production environment role",
139 "run_list": [
140
141 ],
142 "override_attributes": {
143 }
144 }
957cf6d @jtimberman Add database cookbook
jtimberman authored
145
e0f4403 @jtimberman Database and application README updates.
jtimberman authored
146 The cookbook `my_app_database` is recommended to set up any application specific database resources such as configuration templates, trending monitors, etc. It is not required, but you would need to create it separately in `site-cookbooks`. Add it to the `my_app_database_master` role.
957cf6d @jtimberman Add database cookbook
jtimberman authored
147
148 License and Author
149 ==================
150
151 Author:: Adam Jacob (<adam@opscode.com>)
152 Author:: Joshua Timberman (<joshua@opscode.com>)
153 Author:: AJ Christensen (<aj@opscode.com>)
154
155 Copyright 2009-2010, Opscode, Inc.
156
157 Licensed under the Apache License, Version 2.0 (the "License");
158 you may not use this file except in compliance with the License.
159 You may obtain a copy of the License at
160
161 http://www.apache.org/licenses/LICENSE-2.0
162
163 Unless required by applicable law or agreed to in writing, software
164 distributed under the License is distributed on an "AS IS" BASIS,
165 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
166 See the License for the specific language governing permissions and
167 limitations under the License.
Something went wrong with that request. Please try again.