Galera replication

30
Galera Galera Master-Master Master-Master Replication Replication Marian HackMan Marinov <[email protected]>

Transcript of Galera replication

Page 1: Galera replication

GaleraGaleraMaster-MasterMaster-Master

ReplicationReplication

Marian HackMan Marinov <[email protected]>

Page 2: Galera replication

What is the BinaryLog?

UPDATE t1 SET count=100 WHERE id=100UPDATE t1 SET count=100 WHERE id=100

CLIENTCLIENT

Page 3: Galera replication

What is the BinaryLog?

UPDATE t1 SET count=100 WHERE id=100UPDATE t1 SET count=100 WHERE id=100

CLIENTCLIENT

Page 4: Galera replication

What is the BinaryLog?

UPDATE t1 SET count=100 WHERE id=100UPDATE t1 SET count=100 WHERE id=100

CLIENTCLIENT

SUCCESS

Page 5: Galera replication

What is the BinaryLog?

UPDATE t1 SET count=100 WHERE id=100UPDATE t1 SET count=100 WHERE id=100

CLIENTCLIENT

SUCCESS

Page 6: Galera replication

Types of Replication

● STATEMENT● ROW● MIXED

● Master-Slave● Master-Master

Page 7: Galera replication

Types of Replication

● STATEMENT

UPDATE t1 SET count=100 WHERE id=100;UPDATE t1 SET count=100 WHERE id=100;

INSERT INTO t1 VALUES (102, 1);INSERT INTO t1 VALUES (102, 1);

Page 8: Galera replication

Types of Replication

● ROW

table t1 change:table t1 change:

ROW id=100 count=100ROW id=100 count=100

table t1 change:table t1 change:

add row with id=102, count=1add row with id=102, count=1

Page 9: Galera replication

Types of Replication

● MIXED

UPDATE t1 SET count=100 WHERE id=100;UPDATE t1 SET count=100 WHERE id=100;

table t1 change:table t1 change:

ROW id=100 count=100ROW id=100 count=100

INSERT INTO t1 VALUES (102, 1);INSERT INTO t1 VALUES (102, 1);

table t1 change:table t1 change:

add row with id=102, count=1add row with id=102, count=1

Page 10: Galera replication

What is Galera

● Write set replication - WSREPWrite set replication - WSREP● Global Transaction ID - GTIDGlobal Transaction ID - GTID

Page 11: Galera replication

What is Galera

● Write set replication - WSREPWrite set replication - WSREP

UPDATE t1 SET count=100 WHERE id=100;UPDATE t1 SET count=100 WHERE id=100;

INSERT INTO t1 VALUES (102, 1);INSERT INTO t1 VALUES (102, 1);

Write setWrite set

Page 12: Galera replication

What is Galera

● Write set replication - WSREPWrite set replication - WSREP

UPDATE t1 SET count=100 WHERE id=100;UPDATE t1 SET count=100 WHERE id=100;

INSERT INTO t1 VALUES (102, 1);INSERT INTO t1 VALUES (102, 1);

Write setWrite set

GTID: 318e70bb-4ba2-4707-aa5f-20cf44c3d367GTID: 318e70bb-4ba2-4707-aa5f-20cf44c3d367

Page 13: Galera replication

What is Galera

● Write set replication - WSREPWrite set replication - WSREP

UPDATE t1 SET count=100 WHERE id=100;UPDATE t1 SET count=100 WHERE id=100;

INSERT INTO t1 VALUES (102, 1);INSERT INTO t1 VALUES (102, 1);

Write setWrite set

GTID: 318e70bb-4ba2-4707-aa5f-20cf44c3d367GTID: 318e70bb-4ba2-4707-aa5f-20cf44c3d367

Certification based replication???Certification based replication???

Page 14: Galera replication

● WSREP XXX-XXX– certificate that it can proceed

– check based on table's primary key

Page 15: Galera replication

How is it implemented?

Page 16: Galera replication

How is it implemented?

Page 17: Galera replication

How is it implemented?

● WSREP plugin– backing up data

● logs and files

– conns between nodes

– generating GTIDs

– certification of WSETs

WSREP

Page 18: Galera replication

How is it implemented?

Page 19: Galera replication

Node states

Page 20: Galera replication

● State Snapshot Transfer (SST)– Logical - mysqldump

– Physical● rsync/rsync_wan● xtrabackup

wsrep_sst_method=xtrabackupv2● Incremental State Transfer (IST)

5a76ef62-30ec-11e1-0800-dba504cf2aab:197222

5a76ef62-30ec-11e1-0800-dba504cf2aab:201913

– Write-set cache (GCache)

Page 21: Galera replication

Requirements

● binlog_format=ROW● Storage engine InnoDB/XtraDB● All tables should have a primary key

Page 22: Galera replication

Setup

/etc/yum.repos.d/galera.repo

[galera]

name = Galera

baseurl = http://releases.galeracluster.com/centos/6/x86_64

gpgkey = http://releases.galeracluster.com/GPG-KEY-galeracluster.com

gpgcheck = 1

Page 23: Galera replication

Setup

yum install \

Percona-XtraDB-Cluster-server \

Percona-XtraDB-Cluster-client \

Percona-XtraDB-Cluster-galera-3.x86_64 \

galera \

socat \

pv \

pigz \

nc

Page 24: Galera replication

Setup

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

binlog_format=ROW

bind-address=0.0.0.0

default_storage_engine=innodb

innodb_autoinc_lock_mode=2

innodb_flush_log_at_trx_commit=0

innodb_buffer_pool_size=122M

Page 25: Galera replication

Setup

wsrep_provider=/usr/lib64/galera3/libgalera_smm.so

wsrep_provider_options="gcache.size=300M;gcache.page_size=300M"

wsrep_cluster_name="example_cluster"

wsrep_cluster_address="gcomm://10.19.1.8,10.19.1.9"

wsrep_sst_method=xtrabackup-v2

wsrep_sst_auth="root:ensurethehighest"

Page 26: Galera replication

Setup

[sst]

progress=/var/log/mysql/sst.log

streamfmt=xbstream

transferfmt=socat

encrypt=2

encrypt-algo=AES256

tkey=/etc/mysql/key.pem

tcert=/etc/mysql/cert.pem

compressor="pigz -6"

decompressor="pigz -d"

Page 27: Galera replication

First start

# mysql_install_db

# service mysql start --wsrep-new-cluster

Page 28: Galera replication

Adding new node

● Add GRANTs for the new machine– GRANT ALL ON *.* TO 'root'@'10.19.1.10' IDENTIFIED BY 'ensurethehighest';

● Copy the my.cnf from another node● Fix the node_name and node_address● Add the IP of the local node to cluster_address● Start MySQL on the new node● After the sync is done and the new node is in the cluster

– update the cluster_address in the configuration of the other nodes– update the cluster_address in the running mysql instances:

mysql> set global wsrep_cluster_address =

'gcomm://10.19.1.8,10.19.1.9,10.19.1.10';

Page 29: Galera replication

Arbitrator

# chkconfig garb on

# cat /etc/sysconfig/garb

GALERA_NODES="10.19.1.8:4567 10.19.1.9:4567 10.19.1.10:4567"

GALERA_GROUP="gp_cluster"

# /etc/init.d/garb restart

Page 30: Galera replication

QUESTIONS???QUESTIONS???

Marian HackMan Marinov <[email protected]>