-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- New version of Oracle's mysql-utilities (1.3.3) is supported
- Python 2.6 is supported as it's the default version for RHEL/CentOS (code was working only with 2.7) - Add Puppet type and provider - Add Puppet example - Add RPM spec file Signed-off-by: Frederic -lefred- Descamps <lefred@percona.com>
- Loading branch information
Frederic -lefred- Descamps
committed
Aug 2, 2013
1 parent
ae31855
commit 92a7d0b
Showing
23 changed files
with
475 additions
and
11,297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
node percona1 { | ||
include percona::repository | ||
include percona::toolkit | ||
include online-migration | ||
|
||
Class['percona::repository'] -> Class['percona::server'] | ||
|
||
class { | ||
'percona::server': | ||
mysql_version => "5.5", | ||
perconaserverid => "1", | ||
enable => "true", | ||
ensure => "running" | ||
} | ||
|
||
mysql_schema { "world": | ||
ensure => present, | ||
require => [ Package["online-migration"], Service['mysql'] ], | ||
version => 1, | ||
cwd => "/root/om", | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
examples/puppet/modules/online-migration/files/world/0000-up.meta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
0 | ||
d41d8cd98f00b204e9800998ecf8427e | ||
Initial file |
2 changes: 2 additions & 0 deletions
2
examples/puppet/modules/online-migration/files/world/0000-up.mig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CREATE DATABASE world; | ||
USE world; |
3 changes: 3 additions & 0 deletions
3
examples/puppet/modules/online-migration/files/world/0001-down.mig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DROP TABLE City; | ||
DROP TABLE Country; | ||
DROP TABLE CountryLanguage; |
3 changes: 3 additions & 0 deletions
3
examples/puppet/modules/online-migration/files/world/0001-up.meta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
1 | ||
3239e7245d98d27681020e36d0085676 | ||
first step |
4 changes: 4 additions & 0 deletions
4
examples/puppet/modules/online-migration/files/world/0001-up.mig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
OM_IGNORE_TABLE::SET foreign_key_checks = 0; | ||
OM_IGNORE_TABLE::CREATE TABLE `City` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Name` char(35) NOT NULL DEFAULT '', `CountryCode` char(3) NOT NULL DEFAULT '', `District` char(20) NOT NULL DEFAULT '', `Population` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), KEY `CountryCode` (`CountryCode`), CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `Country` (`Code`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||
OM_IGNORE_TABLE::CREATE TABLE `Country` ( `Code` char(3) NOT NULL DEFAULT '', `Name` char(52) NOT NULL DEFAULT '', `Continent` enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL DEFAULT 'Asia', `Region` char(26) NOT NULL DEFAULT '', `SurfaceArea` float(10,2) NOT NULL DEFAULT '0.00', `IndepYear` smallint(6) DEFAULT NULL, `Population` int(11) NOT NULL DEFAULT '0', `LifeExpectancy` float(3,1) DEFAULT NULL, `GNP` float(10,2) DEFAULT NULL, `GNPOld` float(10,2) DEFAULT NULL, `LocalName` char(45) NOT NULL DEFAULT '', `GovernmentForm` char(45) NOT NULL DEFAULT '', `HeadOfState` char(60) DEFAULT NULL, `Capital` int(11) DEFAULT NULL, `Code2` char(2) NOT NULL DEFAULT '', PRIMARY KEY (`Code`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||
OM_IGNORE_TABLE::CREATE TABLE `CountryLanguage` ( `CountryCode` char(3) NOT NULL DEFAULT '', `Language` char(30) NOT NULL DEFAULT '', `IsOfficial` enum('T','F') NOT NULL DEFAULT 'F', `Percentage` float(4,1) NOT NULL DEFAULT '0.0', PRIMARY KEY (`CountryCode`,`Language`), KEY `CountryCode` (`CountryCode`), CONSTRAINT `countryLanguage_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `Country` (`Code`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; |
47 changes: 47 additions & 0 deletions
47
examples/puppet/modules/online-migration/lib/puppet/provider/mysql_schema/mysql_schema.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Puppet::Type.type(:mysql_schema).provide(:mysql_schema) do | ||
desc "Provides access to online-migration" | ||
|
||
optional_commands :omcmd => "/usr/local/bin/online-migration.py" | ||
|
||
def create | ||
info("performing the migration") | ||
dir = self.resource[:cwd] || Dir.pwd | ||
Dir.chdir(dir) | ||
|
||
last_version = omcmd "last_version", resource[:schema] | ||
last_version.chomp! | ||
if last_version == "None" | ||
omcmd "up", resource[:schema] | ||
last_version = omcmd "last_version", resource[:schema] | ||
last_version.chomp! | ||
end | ||
if last_version > resource[:version] | ||
omcmd "down", resource[:schema], "to", resource[:version] | ||
elsif last_version < resource[:version] | ||
omcmd "up", resource[:schema], "to", resource[:version] | ||
end | ||
return true | ||
end | ||
|
||
def destroy | ||
omcmd "last_version", resource[:schema] | ||
info("performing the destruction") | ||
end | ||
|
||
def exists? | ||
last_version = omcmd "last_version", resource[:schema] | ||
last_version.chomp! | ||
info("performing the check, last_version is #{last_version}") | ||
if last_version == "-1" | ||
info("we need to initialize online-migration") | ||
omcmd "init_sysdb" | ||
return false | ||
elsif !( last_version == resource[:version] ) | ||
info("we need to migrate to another version (#{resource[:version]})") | ||
return false | ||
else | ||
return true | ||
end | ||
end | ||
|
||
end |
23 changes: 23 additions & 0 deletions
23
examples/puppet/modules/online-migration/lib/puppet/type/mysql_schema.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Puppet::Type.newtype(:mysql_schema) do | ||
@doc = "Manage MySQL Schemas" | ||
ensurable do | ||
defaultvalues | ||
defaultto :present | ||
end | ||
|
||
|
||
newparam(:schema) do | ||
desc "the schema to manage" | ||
isnamevar | ||
end | ||
|
||
newparam(:version) do | ||
desc "the schema version to insall" | ||
end | ||
|
||
newparam(:cwd, :parent => Puppet::Parameter::Path) do | ||
desc "The directory from which to run the command. If | ||
this directory does not exist, the command will fail." | ||
end | ||
|
||
end |
29 changes: 29 additions & 0 deletions
29
examples/puppet/modules/online-migration/manifests/init.pp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class online-migration { | ||
|
||
package { | ||
"mysql-utilities": | ||
ensure => present, | ||
} | ||
|
||
package { | ||
"online-migration": | ||
ensure => installed, | ||
require => [ Package['mysql-utilities'], Package['percona-toolkit'] ], | ||
provider => rpm, | ||
source => '/vagrant/online-migration-0.2-1.noarch.rpm'; | ||
} | ||
|
||
file { | ||
"/root/om/": | ||
owner => root, | ||
ensure => directory; | ||
"/root/om/world/": | ||
owner => root, | ||
require => File["/root/om/"], | ||
source => "puppet:///modules/online-migration/world/", | ||
ensure => directory, | ||
recurse => true; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class percona::repository { | ||
|
||
|
||
$releasever = "6" | ||
$basearch = $hardwaremodel | ||
yumrepo { | ||
"percona": | ||
descr => "Percona", | ||
enabled => 1, | ||
baseurl => "http://repo.percona.com/centos/$releasever/os/$basearch/", | ||
gpgcheck => 0; | ||
"percona-testing": | ||
descr => "Percona Testing", | ||
enabled => 1, | ||
baseurl => "http://repo.percona.com/testing/centos/$releasever/os/$basearch/", | ||
gpgcheck => 0; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class percona::server ($perconaserverid=undef,$mysql_version="5.5", $enable="false",$ensure="running") { | ||
include percona::server::packages | ||
include percona::server::config | ||
include percona::server::service | ||
|
||
Class['percona::server::packages'] -> Class['percona::server::config'] -> Class['percona::server::service'] | ||
} |
20 changes: 20 additions & 0 deletions
20
examples/puppet/modules/percona/manifests/server/config.pp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class percona::server::config { | ||
|
||
$perconaserverid = $percona::server::perconaserverid | ||
$mysql_version = $percona::server::mysql_version | ||
|
||
file { | ||
"/etc/my.cnf": | ||
ensure => present, | ||
content => template("percona/server/my.cnf.erb"), | ||
notify => Service['mysql'], | ||
} | ||
|
||
exec { | ||
"disable-selinux": | ||
path => ["/usr/bin","/bin"], | ||
command => "echo 0 >/selinux/enforce", | ||
unless => "grep 0 /selinux/enforce", | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
examples/puppet/modules/percona/manifests/server/packages.pp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class percona::server::packages { | ||
|
||
if $percona::server::mysql_version == "5.5" { | ||
$ps_ver="55" | ||
$repo="percona" | ||
} elsif $percona::server::mysql_version == "5.6" { | ||
info("Congrats ! Using 5.6 !!") | ||
$ps_ver="56" | ||
$repo="percona-testing" | ||
} | ||
|
||
package { | ||
"Percona-Server-server-$ps_ver.$hardwaremodel": | ||
alias => "MySQL-server", | ||
require => Yumrepo[$repo], | ||
ensure => "installed"; | ||
"Percona-Server-client-$ps_ver.$hardwaremodel": | ||
alias => "MySQL-client", | ||
require => Yumrepo[$repo], | ||
ensure => "installed"; | ||
"mysql-libs": | ||
ensure => "absent"; | ||
"Percona-Server-shared-compat": | ||
require => [ Yumrepo[$repo], Package['mysql-libs'], Package['MySQL-client'] ], | ||
ensure => "installed"; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/puppet/modules/percona/manifests/server/service.pp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class percona::server::service { | ||
|
||
|
||
service { | ||
"mysql": | ||
enable => $percona::server::enable, | ||
ensure => $percona::server::ensure, | ||
require => Package['MySQL-server'], | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class percona::toolkit { | ||
|
||
package { | ||
"perl-Time-HiRes": | ||
ensure => installed; | ||
"perl-TermReadKey": | ||
ensure => installed; | ||
"perl-DBD-MySQL": | ||
ensure => installed, | ||
require => Package['Percona-Server-shared-compat']; | ||
"percona-toolkit": | ||
ensure => installed, | ||
require => [ Package['perl-Time-HiRes'], Package['perl-TermReadKey'], Package['perl-DBD-MySQL'] ], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class percona::xtrabackup { | ||
|
||
package { | ||
"xtrabackup.$hardwaremodel": | ||
alias => "xtrabackup", | ||
require => [ Yumrepo['percona'], Package['Percona-Server-shared-compat'] ], | ||
ensure => installed; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
examples/puppet/modules/percona/templates/cluster/my.cnf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[mysqld] | ||
datadir=/var/lib/mysql | ||
user=mysql | ||
log_error=error.log | ||
binlog_format=ROW | ||
wsrep_provider=/usr/lib64/libgalera_smm.so | ||
wsrep_cluster_address=gcomm://<%= joinip %> | ||
wsrep_sst_receive_address=<%= ipaddress_eth1 %> | ||
wsrep_node_incoming_address=<%= ipaddress_eth1 %> | ||
wsrep_slave_threads=2 | ||
wsrep_cluster_name=trimethylxanthine | ||
wsrep_sst_method=rsync | ||
wsrep_node_name=<%= hostname %> | ||
innodb_locks_unsafe_for_binlog=1 | ||
innodb_autoinc_lock_mode=2 | ||
innodb_log_file_size=64M | ||
bind-address=<%= ipaddress_eth1 %> | ||
|
||
[mysql] | ||
prompt="<%=hostname %> mysql> " |
21 changes: 21 additions & 0 deletions
21
examples/puppet/modules/percona/templates/server/my.cnf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[mysqld] | ||
datadir=/var/lib/mysql | ||
user=mysql | ||
log_error=<%= hostname %>-error.log | ||
binlog_format=MIXED | ||
<% if has_variable?("perconaserverid") and perconaserverid.to_s != "undef" then %>server-id=<%= perconaserverid %> <% end %> | ||
innodb_log_file_size=64M | ||
innodb_file_per_table | ||
log_slave_updates=1 | ||
log-bin=mysql-bin | ||
max_allowed_packet = 64M | ||
pid-file=/var/lib/mysql/mysqld.pid | ||
|
||
<% if has_variable?("mysql_version") and mysql_version.to_s == "5.6" then %> | ||
#support GTID | ||
enforce_gtid_consistency=1 | ||
gtid_mode=on | ||
<% end %> | ||
|
||
[mysql] | ||
prompt="<%= hostname %> mysql> " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
Automate schema version in puppet | ||
================================= | ||
|
||
It's possible to automate the installation of MySQL (or Percona Server or MariaDB ;-) ) but | ||
I wanted to also automate the schema installation or migration with Puppet. | ||
|
||
This is how it works: | ||
|
||
On your node you make sure you have all the needed packages installed (seen manifests/site.pp) and | ||
for the schema, this is what it's needed:: | ||
|
||
include online-migration | ||
|
||
mysql_schema { "world": | ||
ensure => present, | ||
require => [ Package["online-migration"], Service['mysql'] ], | ||
version => 1, | ||
cwd => "/root/om", | ||
} | ||
|
||
|
||
The name of the resource ("world") is the name of the schema (database) and the migration files | ||
are located in */root/om* | ||
|
||
*/root/om* contains the *world* folder with all definitions for each available version, this is how it's defined in puppet:: | ||
|
||
file { | ||
"/root/om/": | ||
owner => root, | ||
ensure => directory; | ||
"/root/om/world/": | ||
owner => root, | ||
require => File["/root/om/"], | ||
source => "puppet:///modules/online-migration/world/", | ||
ensure => directory, | ||
recurse => true; | ||
} | ||
|
||
There are some message when the type **mysql_schema** is used, this is an example of puppet execution:: | ||
|
||
info: Mysql_schema[world](provider=mysql_schema): performing the check, last_version is None | ||
info: Mysql_schema[world](provider=mysql_schema): we need to migrate to another version (1) | ||
info: Mysql_schema[world](provider=mysql_schema): performing the migration | ||
notice: /Stage[main]//Node[percona1]/Mysql_schema[world]/ensure: created | ||
|
||
|
Oops, something went wrong.