[GALERA] Install and configuration: first and other nodes

pull/14/head
Emilien Mantel 2016-09-23 17:03:13 +02:00
parent e512d7d53c
commit fc5aa46d94
17 changed files with 131 additions and 29 deletions

View File

@ -135,3 +135,8 @@ mariadb_repository: "http://ftp.igh.cnrs.fr/pub/mariadb/repo/{{ mariadb_version
# -------------------------------------
percona_version: '5.6'
percona_repository: 'http://repo.percona.com/apt'
# Galera
mysql_galera_bootstrap: false
mariadb_galera_members: []

View File

@ -0,0 +1,23 @@
---
- set_fact:
booboo: /var/lib/mysql/.ansible_galera_boostrap
- name: STAT | Bootstrap mark
stat: path={{ booboo }}
register: s
- block:
- name: COMMAND | Stop MariaDB
service: name=mysql state=stopped
- name: COMMAND | Bootstrap first node
command: galera_new_cluster
register: bootstrap_run
when: not s.stat.exists
- name: COMMAND | Create Bootstrap mark
command: "touch {{ booboo }}"
args:
creates: "{{ booboo }}"

View File

@ -0,0 +1,19 @@
---
- name: TEMPLATE | Deploy Galera configuration
template: src=etc/mysql/conf.d/09-galera.cnf.j2 dest=/etc/mysql/conf.d/09-galera.cnf
register: galeraconfig
- name: INCLUDE | Bootstrap first node
include: 'bootstrap.yml'
when: inventory_hostname == mysql_galera_primary_node
- name: INCLUDE | Configure other nodes
include: 'nodes.yml'
when: inventory_hostname != mysql_galera_primary_node
- name: SERVICE | Restart MariaDB if needed
service: name=mysql state=restarted
when: >
(galeraconfig or (p is defined and p.changed)) and
(bootstrap_run is not defined)

View File

@ -0,0 +1,29 @@
---
- name: COMMAND | GET debian.cnf from primary node
command: cat /etc/mysql/debian.cnf
register: debiancnf
delegate_to: '{{ mysql_galera_primary_node }}'
- name: COMMAND | Get current debian.cnf
command: cat /etc/mysql/debian.cnf
register: ondc
- block:
- name: SERVICE | Stop MariaDB
service: name=mysql state=stopped
- name: COPY | Paste primary node's debian.cnf
copy: >
content={{ debiancnf.stdout }}
dest=/etc/mysql/debian.cnf
mode=0600
owner=root
group=root
register: paste
- name: SERVICE | Start MariaDB
service: name=mysql state=started
when: debiancnf.stdout != ondc.stdout

View File

@ -16,20 +16,19 @@
template: src=etc/mysql/conf.d/10-extra.cnf.j2 dest=/etc/mysql/conf.d/10-extra.cnf
register: extraconfig
- name: TEMPLATE | Deploy Galera configuration
template: src=etc/mysql/conf.d/09-galera.cnf.j2 dest=/etc/mysql/conf.d/09-galera.cnf
register: galeraconfig
- name: SERVICE | Restart now (prevent bugs)
service: name=mysql state=restarted
when: >
config.changed or
extraconfig.changed or
(galeraconfig is defined and galeraconfig.changed)
extraconfig.changed
- name: TEMPLATE Create .my.cnf for root
template: src=root/my.cnf dest=/root/.my.cnf owner=root group=root mode=0600 backup=yes
- name: INCLUDE | Galera
include: galera/main.yml
when: mysql_vendor == 'mariadb_galera'
- name: INCLUDE | Replication
include: replication/main.yml
when: mysql_replication_master or mysql_replication_slave
@ -49,4 +48,3 @@
host="{{ item.host | default('localhost') }}"
state=present
with_items: "{{ mysql_users }}"

View File

@ -4,16 +4,26 @@
[mysqld]
# --------------------
# Galera config
# --------------------
# Global
wsrep_on=ON
# TODO: wsrep_cluster_address=gcomm://cluster01,cluster02,cluster03
wsrep_cluster_address=gcomm://127.0.0.1
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://{{ mariadb_galera_members | join(",") }}
# TODO: https://mariadb.com/kb/en/mariadb/galera-cluster-system-variables/#wsrep_sst_method
wsrep_sst_method=rsync
# TODO: wsrep_cluster_name="my_wsrep_cluster"
# Node Configuration
wsrep_node_address="{{ mysql_wsrep_node_address | default(ansible_eth0.ipv4.address) }}"
wsrep_node_name="{{ mysql_wsrep_node_name | default(ansible_fqdn) }}"
# --------------------
# Deps
# --------------------
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2

View File

@ -24,7 +24,8 @@ my @a = (
my $start_ip = '192.168.200.10';
my $iip = ip2long($start_ip);
my $tmp_ip = 0;
my @galera = ();
foreach my $n (@a)
{
@ -40,27 +41,40 @@ foreach my $n (@a)
if($data[-1] eq 'slave')
{
open(FILE, '>', "host_vars/$n");
printf FILE (qq/his_master: '%s'\n/, $tmp_ip);
printf FILE (qq/his_master: '%s'\n/, long2ip($iip));
close(FILE);
}
if($data[-1] =~ /^\d$/ && $data[-2] eq 'mariadbgalera')
# if($data[-1] =~ /^\d$/ && $data[-2] eq 'mariadbgalera')
# {
# open(FILE, '>', "host_vars/$n");
# printf FILE (qq/galera_id: '%s'\n/, $data[-1]);
# close(FILE);
# }
if($data[-2] eq 'mariadbgalera')
{
open(FILE, '>', "host_vars/$n");
printf FILE (qq/galera_id: '%s'\n/, $data[-1]);
close(FILE);
push(@galera, long2ip($iip));
goto SKIP;
}
open(FILE, '>', "group_vars/" . $data[2]);
my $mv = $data[-2];
$mv = 'mariadb_galera' if($mv eq 'mariadbgalera');
printf FILE (qq/mysql_vendor: '%s'\n/, $mv);
printf FILE (qq/mysql_vendor: '%s'\n/, $data[2]);
close(FILE);
$tmp_ip = long2ip($iip);
SKIP:
$iip++;
}
open(FILE, '>', 'group_vars/mariadbgalera');
say FILE qq/mysql_vendor: 'mariadb_galera'/;
say FILE qq/mariadb_galera_members:/;
foreach(@galera)
{
say FILE qq/ - '$_'/;
}
close(FILE);
sub ip2long {
return unpack("l*", pack("l*", unpack("N*", inet_aton(shift))));
}

View File

@ -1,2 +1,2 @@
mysql_use_percona_repository: true
mysql_bind_address: '0.0.0.0'
mysql_bind_address: '{{ ansible_eth1.ipv4.address }}'

View File

@ -1,3 +1,5 @@
mysql_vendor: 'mariadb_galera'
mysql_use_percona_repository: false
mariadb_version: '10.1'
mariadb_galera_members:
- '192.168.200.18'
- '192.168.200.19'
- '192.168.200.20'

View File

@ -1 +1 @@
his_master: '192.168.200.16'
his_master: '192.168.200.17'

View File

@ -1 +1 @@
his_master: '192.168.200.10'
his_master: '192.168.200.11'

View File

@ -1 +1 @@
his_master: '192.168.200.12'
his_master: '192.168.200.13'

View File

@ -1 +0,0 @@
galera_id: '1'

View File

@ -1 +0,0 @@
galera_id: '2'

View File

@ -1 +0,0 @@
galera_id: '3'

View File

@ -1 +1 @@
his_master: '192.168.200.14'
his_master: '192.168.200.15'

View File

@ -38,6 +38,11 @@
when: c.changed
- hosts: mariadbgalera
vars:
mysql_galera_primary_node: 'jessie-upstream-mariadbgalera-1'
mysql_wsrep_node_address: "{{ ansible_eth1.ipv4.address }}"
mysql_use_percona_repository: false
mariadb_version: '10.1'
roles:
- ../../