Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cookbooks/eydr/attributes/replication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
:public_hostname => ""
}
},
# The following 2 URLs are required for MySQL replication
:xtrabackup_download_url => "http://www.percona.com/redir/downloads/XtraBackup/XtraBackup-2.2.6/binary/tarball/percona-xtrabackup-2.2.6-5042-Linux-x86_64.tar.gz",
# The following URL is required for compressing/decompressing backups
:qpress_download_url => "http://www.quicklz.com/qpress-11-linux-x64.tar"
}

Expand All @@ -21,3 +20,6 @@

# Set to true to failover to D/R environment during Chef run
default[:failover] = false

# Set to a higher value depending on the available CPUs on master
default[:parallelism] = 1
11 changes: 9 additions & 2 deletions cookbooks/eydr/attributes/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
mysql :latest_version => "5.5.31", :virtual => "5.5", :short_version => '5.5'
datadir '/db/mysql/5.5/data/'
when "mysql5_6"
mysql :latest_version => "5.6.14", :virtual => "5.6", :short_version => '5.6'
datadir '/db/mysql/5.6/data/'
node.default['mysql']['latest_version'] = "5.6.37"
node.default['mysql']['virtual'] = "5.6"
node.default['mysql']['short_version'] = '5.6'
node.default['datadir'] = '/db/mysql/5.6/data/'
when "mysql5_7"
node.default['mysql']['latest_version'] = "5.7.19"
node.default['mysql']['virtual'] = "5.7"
node.default['mysql']['short_version'] = '5.7'
node.default['datadir'] = '/db/mysql/5.7/data/'
when "postgres9"
postgresql :latest_version => "9.0.13", :short_version => "9.0"
datadir '/db/postgresql/9.0/data'
Expand Down
35 changes: 12 additions & 23 deletions cookbooks/eydr/recipes/install_xtrabackup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,31 @@
# Recipe:: install_xtrabackup
#

# Download xtrabackup from URL specificed in attributes
bash "download-xtrabackup" do
user node['owner_name']
code "cd /home/#{node['owner_name']}/ && wget #{node[:dr_replication][:xtrabackup_download_url]}"
not_if { File.exists? "/home/#{node['owner_name']}/#{node[:dr_replication][:xtrabackup_download_url].split("/").last}"}
end

# Untar xtrabackup
bash "untar-xtrabackup" do
user node['owner_name']
code "cd /home/#{node['owner_name']}/ && tar zxvf #{node[:dr_replication][:xtrabackup_download_url].split("/").last}"
# Required for xtrabackup
enable_package "app-arch/lz4" do
version '1.8.3'
end

# Copy xtrabackup into /usr/bin so that it's in the PATH
bash "copy-xtrabackup" do
user "root"
code "yes | cp -ruf /home/#{node['owner_name']}/#{node[:dr_replication][:xtrabackup_download_url].split("/").last.split("-")[0..2].join("-")}*/bin/* /usr/bin/"
package "app-arch/lz4" do
version '1.8.3'
action :install
end

# Ensure proper ownership
bash "chown-xtrabackup" do
user "root"
cwd "/usr/bin/"
code "chown #{node['owner_name']}:#{node['owner_name']} innobackupex xbcrypt xbstream xtrabackup*"
# Install xtrabackup
enable_package "dev-db/percona-xtrabackup" do
version '2.4.13'
end

# Install libaio (required for xtrabackup)
package "dev-libs/libaio" do
package "dev-db/percona-xtrabackup" do
version '2.4.13'
action :install
end

# Download qpress from the URL specified in attributes (used for compression)
bash "download-qpress" do
user node['owner_name']
cwd "/home/#{node['owner_name']}/"
code "wget #{node[:dr_replication][:qpress_download_url]}"
code "wget -U 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)' #{node[:dr_replication][:qpress_download_url]}"
not_if { File.exists? "/home/#{node['owner_name']}/#{node[:dr_replication][:qpress_download_url].split("/").last}"}
end

Expand Down
4 changes: 2 additions & 2 deletions cookbooks/eydr/recipes/mysql_master_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Recipe:: mysql_master_configuration
#

if solo?
if ['solo'].include?(node['dna']['instance_role'])
remote_file "/etc/mysql.d/logbin.cnf" do
source "logbin.cnf"
owner "root"
Expand All @@ -17,6 +17,6 @@
end
end

if db_server?
if ['db_master', 'solo', 'db_slave'].include?(node['dna']['instance_role'])
include_recipe "eydr::install_xtrabackup"
end
3 changes: 2 additions & 1 deletion cookbooks/eydr/recipes/mysql_replication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
template "/etc/mysql.d/replication.cnf" do
source "replication.cnf.erb"
variables({
:server_id => node[:engineyard][:this].split("-")[1].to_i(16),
:server_id => node[:dna][:engineyard][:this].split("-")[1].to_i(16),
:datadir => node[:datadir],
:short_version => node[:mysql][:short_version]
})
Expand All @@ -24,6 +24,7 @@
backup 0
variables({
:master_pass => node[:owner_pass],
:parallelism => node[:parallelism],
:initiate_public_hostname => node[:dr_replication][node[:environment][:framework_env]][:initiate][:public_hostname],
:slave_public_hostname => node[:dr_replication][node[:environment][:framework_env]][:slave][:public_hostname],
:master_public_hostname => node[:dr_replication][node[:environment][:framework_env]][:master][:public_hostname],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

rm -rf <%= @datadir %>*

ssh -i /home/<%= @user %>/.ssh/eydr_key -p 22 -o StrictHostKeyChecking=no -o TCPKeepAlive=yes <%= @db_user %>@<%= @initiate_public_hostname %> 'sudo innobackupex --user root --pass <%= @master_pass %> --slave-info --safe-slave-backup --compress --stream=xbstream /doesntneedtoexist | ssh -i /home/<%= @user %>/.ssh/eydr_key -o StrictHostKeyChecking=no -o TCPKeepAlive=yes <%= @user %>@<%= @slave_public_hostname %> "sudo xbstream -x -C <%= @datadir %>"'
ssh -i /home/<%= @user %>/.ssh/eydr_key -p 22 -o StrictHostKeyChecking=no -o TCPKeepAlive=yes <%= @db_user %>@<%= @initiate_public_hostname %> 'sudo innobackupex --user root --pass <%= @master_pass %> --socket=/var/run/mysqld/mysqld.sock --parallel=<%= @parallelism %> --slave-info --safe-slave-backup --compress --stream=xbstream | ssh -i /home/<%= @user %>/.ssh/eydr_key -o StrictHostKeyChecking=no -o TCPKeepAlive=yes <%= @user %>@<%= @slave_public_hostname %> "sudo xbstream -x -C <%= @datadir %>"'

cd <%= @datadir %> && for bf in `find . -iname "*\.qp"`; do qpress -df $bf $(dirname $bf) && rm $bf; done

Expand Down