[GALERA] Install and configuration: first and other nodes
parent
e512d7d53c
commit
fc5aa46d94
|
@ -135,3 +135,8 @@ mariadb_repository: "http://ftp.igh.cnrs.fr/pub/mariadb/repo/{{ mariadb_version
|
||||||
# -------------------------------------
|
# -------------------------------------
|
||||||
percona_version: '5.6'
|
percona_version: '5.6'
|
||||||
percona_repository: 'http://repo.percona.com/apt'
|
percona_repository: 'http://repo.percona.com/apt'
|
||||||
|
|
||||||
|
|
||||||
|
# Galera
|
||||||
|
mysql_galera_bootstrap: false
|
||||||
|
mariadb_galera_members: []
|
||||||
|
|
|
@ -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 }}"
|
|
@ -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)
|
|
@ -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
|
|
@ -16,20 +16,19 @@
|
||||||
template: src=etc/mysql/conf.d/10-extra.cnf.j2 dest=/etc/mysql/conf.d/10-extra.cnf
|
template: src=etc/mysql/conf.d/10-extra.cnf.j2 dest=/etc/mysql/conf.d/10-extra.cnf
|
||||||
register: extraconfig
|
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)
|
- name: SERVICE | Restart now (prevent bugs)
|
||||||
service: name=mysql state=restarted
|
service: name=mysql state=restarted
|
||||||
when: >
|
when: >
|
||||||
config.changed or
|
config.changed or
|
||||||
extraconfig.changed or
|
extraconfig.changed
|
||||||
(galeraconfig is defined and galeraconfig.changed)
|
|
||||||
|
|
||||||
- name: TEMPLATE Create .my.cnf for root
|
- name: TEMPLATE Create .my.cnf for root
|
||||||
template: src=root/my.cnf dest=/root/.my.cnf owner=root group=root mode=0600 backup=yes
|
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
|
- name: INCLUDE | Replication
|
||||||
include: replication/main.yml
|
include: replication/main.yml
|
||||||
when: mysql_replication_master or mysql_replication_slave
|
when: mysql_replication_master or mysql_replication_slave
|
||||||
|
@ -49,4 +48,3 @@
|
||||||
host="{{ item.host | default('localhost') }}"
|
host="{{ item.host | default('localhost') }}"
|
||||||
state=present
|
state=present
|
||||||
with_items: "{{ mysql_users }}"
|
with_items: "{{ mysql_users }}"
|
||||||
|
|
||||||
|
|
|
@ -4,16 +4,26 @@
|
||||||
|
|
||||||
[mysqld]
|
[mysqld]
|
||||||
|
|
||||||
|
# --------------------
|
||||||
# Galera config
|
# Galera config
|
||||||
|
# --------------------
|
||||||
|
|
||||||
|
# Global
|
||||||
wsrep_on=ON
|
wsrep_on=ON
|
||||||
# TODO: wsrep_cluster_address=gcomm://cluster01,cluster02,cluster03
|
wsrep_provider=/usr/lib/galera/libgalera_smm.so
|
||||||
wsrep_cluster_address=gcomm://127.0.0.1
|
wsrep_cluster_address=gcomm://{{ mariadb_galera_members | join(",") }}
|
||||||
# TODO: https://mariadb.com/kb/en/mariadb/galera-cluster-system-variables/#wsrep_sst_method
|
# TODO: https://mariadb.com/kb/en/mariadb/galera-cluster-system-variables/#wsrep_sst_method
|
||||||
wsrep_sst_method=rsync
|
wsrep_sst_method=rsync
|
||||||
# TODO: wsrep_cluster_name="my_wsrep_cluster"
|
# 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
|
# Deps
|
||||||
|
# --------------------
|
||||||
binlog_format=ROW
|
binlog_format=ROW
|
||||||
default_storage_engine=InnoDB
|
default_storage_engine=InnoDB
|
||||||
innodb_autoinc_lock_mode=2
|
innodb_autoinc_lock_mode=2
|
||||||
|
|
34
tests/gen.pl
34
tests/gen.pl
|
@ -24,7 +24,8 @@ my @a = (
|
||||||
|
|
||||||
my $start_ip = '192.168.200.10';
|
my $start_ip = '192.168.200.10';
|
||||||
my $iip = ip2long($start_ip);
|
my $iip = ip2long($start_ip);
|
||||||
my $tmp_ip = 0;
|
|
||||||
|
my @galera = ();
|
||||||
|
|
||||||
foreach my $n (@a)
|
foreach my $n (@a)
|
||||||
{
|
{
|
||||||
|
@ -40,27 +41,40 @@ foreach my $n (@a)
|
||||||
if($data[-1] eq 'slave')
|
if($data[-1] eq 'slave')
|
||||||
{
|
{
|
||||||
open(FILE, '>', "host_vars/$n");
|
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);
|
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");
|
push(@galera, long2ip($iip));
|
||||||
printf FILE (qq/galera_id: '%s'\n/, $data[-1]);
|
goto SKIP;
|
||||||
close(FILE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open(FILE, '>', "group_vars/" . $data[2]);
|
open(FILE, '>', "group_vars/" . $data[2]);
|
||||||
my $mv = $data[-2];
|
printf FILE (qq/mysql_vendor: '%s'\n/, $data[2]);
|
||||||
$mv = 'mariadb_galera' if($mv eq 'mariadbgalera');
|
|
||||||
printf FILE (qq/mysql_vendor: '%s'\n/, $mv);
|
|
||||||
close(FILE);
|
close(FILE);
|
||||||
|
|
||||||
$tmp_ip = long2ip($iip);
|
SKIP:
|
||||||
$iip++;
|
$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 {
|
sub ip2long {
|
||||||
return unpack("l*", pack("l*", unpack("N*", inet_aton(shift))));
|
return unpack("l*", pack("l*", unpack("N*", inet_aton(shift))));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
mysql_use_percona_repository: true
|
mysql_use_percona_repository: true
|
||||||
mysql_bind_address: '0.0.0.0'
|
mysql_bind_address: '{{ ansible_eth1.ipv4.address }}'
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
mysql_vendor: 'mariadb_galera'
|
mysql_vendor: 'mariadb_galera'
|
||||||
mysql_use_percona_repository: false
|
mariadb_galera_members:
|
||||||
mariadb_version: '10.1'
|
- '192.168.200.18'
|
||||||
|
- '192.168.200.19'
|
||||||
|
- '192.168.200.20'
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
his_master: '192.168.200.16'
|
his_master: '192.168.200.17'
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
his_master: '192.168.200.10'
|
his_master: '192.168.200.11'
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
his_master: '192.168.200.12'
|
his_master: '192.168.200.13'
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
galera_id: '1'
|
|
|
@ -1 +0,0 @@
|
||||||
galera_id: '2'
|
|
|
@ -1 +0,0 @@
|
||||||
galera_id: '3'
|
|
|
@ -1 +1 @@
|
||||||
his_master: '192.168.200.14'
|
his_master: '192.168.200.15'
|
||||||
|
|
|
@ -38,6 +38,11 @@
|
||||||
when: c.changed
|
when: c.changed
|
||||||
|
|
||||||
- hosts: mariadbgalera
|
- 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:
|
roles:
|
||||||
- ../../
|
- ../../
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue