Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the Chef Mailing List.

Select Badges

Select Supported Platforms

Select Status

RSS

mysql-mha (3) Versions 0.1.1

Installs/Configures MHA and MHA Helper

Policyfile
Berkshelf
Knife
cookbook 'mysql-mha', '= 0.1.1', :supermarket
cookbook 'mysql-mha', '= 0.1.1'
knife supermarket install mysql-mha
knife supermarket download mysql-mha
README
Dependencies
Changelog
Quality 100%

mysql-mha Cookbook

Join the chat at https://gitter.im/ovaistariq/cookbook-mysql-mha
Cookbook Version

Deploys MHA and MHA Helper to manage failover of MySQL replication clusters. MHA helper is a Python module that supplements in doing proper failover using MHA.

Requirements

Platforms

  • RHEL / CentOS version 6.x

Chef

  • Chef 11+

Cookbooks

  • packagecloud
  • ssh
  • sudo
  • user
  • yum-epel
  • zap

Usage

On the manager node, which is the node which will manage the MySQL replication clusters, include the following recipe:

include_recipe "mysql-mha::manager"

On all the other MySQL nodes (master and slave), include the following recipe:

include_recipe "mysql-mha::node"

Use knife to create the required data bags.

$ knife data bag create mysql_mha_config
$ knife data bag create mysql_mha_secrets

The mysql_mha_config data bag contains the main configuration minus the sensitive items like user passwords.

Create cluster configuration in the data_bag/mysql_mha_config/ directory.

The latest version of knife supports reading data bags from a file and automatically looks in a directory called +data_bags+ in the current directory. The "bag" should be a directory with JSON files of each item.

{
  "id": "test_pod",
  "comment": "MHA replication pod 'test_pod' configuration",
  "mysql": {
    "user": "mha",
    "repl_user": "repl"
  },
  "remote_user": {
    "id": "mha",
    "comment": "user used by MHA to login to managed nodes",
    "home": "/home/mha",
    "uid": "10011",
    "groups": ["mysql"],
    "ssh_keys": [
      "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAwHjA7iaA0/+TD0roAmyOqYFp3DMpuJ/Xee260gio5igLeV6DHyPBskHhcCOWFcZ+uCAOGIm+Yye9nxuspWFEWCa4L1SxniBEpRGtGyorbgz7Zmh/6VlcZOUBTe1GtaprokGAtzP2gaQbRpJ1c0oX3JZ4lVH6Oro3keCGyncZMFJ2nTu0hOgbJPA3XZkRwO0DhB/8IbPu6NwXVcDjaMfTmpj4kp722RFuEUgGrDBwx/vasakpcBMHF+a6QL0gAODHMttQB1kk1hCV4fQtiTSrbG97jldlcC7VvSqK79twpQNe9y06jnMah8xdvZ69mw/4k3Av+Vv3I4KHxvN9wE59Tw== root@manager-centos-66"
    ]
  },
  "vip_type": "metal",
  "writer_vip_cidr": "192.168.30.100/24",
  "report_email": "ovaistariq@gmail.com",
  "smtp_host": "localhost",
  "requires_sudo": "yes",
  "super_read_only": "no",
  "cluster_interface": "eth1"
}

For the above:

$ mkdir data_bags/mysql_mha_config
$ $EDITOR data_bags/mysql_mha_config/test_pod.json

Paste the user's public SSH key into the ssh_keys value. Also make sure the uid is unique.

Create cluster configuration in the data_bag/mysql_mha_secrets directory.

The mysql_mha_secrets data bag is an encrypted data bag that contains the secondary part of the configuration which includes the sensitive items like user passwords.

{
  "id": "test_pod",
  "comment": "MHA replication pod 'test_pod' secrets",
  "mysql": {
    "password": "mha",
    "repl_password": "repl"
  },
  "remote_user": {
    "ssh_private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBAAKCAQEAwHjA7iaA0/+TD0roAmyOqYFp3DMpuJ/Xee260gio5igLeV6D\nHyPBskHhcCOWFcZ+uCAOGIm+Yye9nxuspWFEWCa4L1SxniBEpRGtGyorbgz7Zmh/\n6VlcZOUBTe1GtaprokGAtzP2gaQbRpJ1c0oX3JZ4lVH6Oro3keCGyncZMFJ2nTu0\nhOgbJPA3XZkRwO0DhB/8IbPu6NwXVcDjaMfTmpj4kp722RFuEUgGrDBwx/vasakp\ncBMHF+a6QL0gAODHMttQB1kk1hCV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InQOeHuvR/ZeiXRMcr/fBtpvp8hab+M9Y\n/Sub5g3iaDF/HaR+AcWuiUhH4HPJWFMMv+g9/wzpuChxRLxoaDrZYEq2Zz/PxWDb\nnz0CgYEA6tj/84IihQ7tUrTpZRI2Ml5Ekzng+zXv27IY/1+7ukO6zlbtkZsdJcG/\n720B150vR1JXmYQlWLYNcgMVb/U/gfPeYI5hpxzl8DyGnSsEYJo7jr8wJ9hebqgf\nyNlZaURrwMLOm9DrnGih9qbWgtMMhHP2GHiQRqTpexhs20dm8U8=\n-----END RSA PRIVATE KEY-----"
  }
}

For the above:

$ mkdir data_bags/mysql_mha_secrets
$ knife data bag create mysql_mha_config test_pod -z --secret-file /path/to/encrypted_data_bag_secret

The data bag name is the name of the cluster and the following attribute must be set on all the nodes that belong to the same MySQL replication cluster:
ruby
node['mysql_mha']['pod_name'] = 'test_pod'

Note how the attribute above matches the name of the data bag in the example above.

Every MySQL node that is the candidate master (including current active MySQL master and all the other nodes that can potentially become masters) must have the following attribute set:
ruby
node['mysql_mha']['node']['candidate_master'] = '1'

You can optionally prevent MHA from checking for replication delay on a node, if you want the node to always act as a master irrespective if its the most latest slave or not:
ruby
node['mysql_mha']['node']['check_repl_delay'] = '0'

If you do not want a MySQL node to every become a master, then you can set the following attribute:
ruby
node['mysql_mha']['node']['no_master'] = '1'

The following attributes must be setup for MHA to function correctly:
ruby
node['mysql_mha']['node']['mysql_port'] = '3306'
node['mysql_mha']['node']['mysql_binlog_dir'] = '/var/lib/mysql'
node['mysql_mha']['node']['ssh_port'] = '22'

Additionally following considerations must be taken into account:

  • The cookbook does not create the MySQL users you specify inside the configuration in the data bags. The must already exist.
  • The writer VIP (specified using the option 'writer_vip_cidr') must already be assigned when the recipe is run for the first time.

License & Authors

Author: Ovais Tariq (me@ovaistariq.net)

Copyright: 2009-2015, Ovais Tariq me@ovaistariq.net.
```
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.
```

Dependent cookbooks

packagecloud >= 0.0.0
ssh >= 0.0.0
sudo >= 2.7.1
user >= 0.0.0
yum-epel <= 0.6.0
zap >= 0.6.0

Contingent cookbooks

There are no cookbooks that are contingent upon this one.

mysql-mha Cookbook CHANGELOG

v0.1.0

  • initial release

Foodcritic Metric
            

0.1.1 passed this metric