Galera Cluster
Galera Cluster
Group Communication
A client executes a write transaction, it is executed
optimistically on the local server right until before
being actually committed.
Transaction is bundled into a write-set and sent to the
Group Communication toolkit
Message is ordered by the Group Communication
Toolkit, and sent to all nodes in the same order.
Every server keeps for each row update an associated
version, and each transaction has a version number to
guarantee consistency.
If the transaction has no conflicts it will be executed
Certification is used to detect conflicts between
version numbers
We have a 3 nodes database group
Each Database has a Database Version Number
Database version number is increased after any
transaction is committed
Transaction TX1
Current Version =1
Transaction TX1
Current Version =1
Transaction TX1
Current Version =1
From DB2:
Transaction T2
Update x=0
Current Version = 1
DBV=1 DBV=1 DBV=1
The group communication will choose the right order for the
two transactions ( assume T1 will be first)
From DB1:
Transaction T1
Update x=500
Client 1 Client 2
Current Version = 1
From DB2:
Transaction T2
Update x=0
Current Version = 1
DBV=1 DBV=1 DBV=1
T1 will be checked for certification.
Since the CV >= DBV , then there is no conflicts and it will be
certified.
Client 1 Client 2
From DB2:
Transaction T2
Update x=0
Current Version = 1
DBV=2 DBV=2 DBV=2
Server 2 will rollback the transaction and return an error to
the client.
Client 1 Client 2
Each select
reads different
data
Old Data Transaction 1 Transaction 2
X=500 Select X, Select X,
Update X = (X + 500) Update X = (X - 500)
Select X,
Update X = 100 Update X = (X - 500)
Galera cluster supports 4 isolation levels:
(3) REPEATABLE–READ: The default isolation level for MySQL InnoDB.
Here snapshots of data are taken before the first SELECT query and all subsequent queries see the same
snapshot
Queries will not see changes committed by other transactions making reads repeatable.
10.12.0.134 gdb01
10.12.0.135 gdb02
10.12.0.136 gdb03
CentOS Repositories include the old version 5.5.
We will install MariaDB version 10.1
Add the repository (Ref: https://mariadb.com/kb/en/library/yum/):
◦ Create the file : /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
Install MariaDB server, client and common tools using the command:
◦ yum install MariaDB-server MariaDB-client MariaDB-common
On The 1st node (any node), start MariaDB and run the
command :
◦ mysql_secure_installation
Configure Galera Section in the file : /etc/my.cnf.d/server.cnf
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://10.12.0.134,10.12.0.135,10.12.0.136"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
wsrep_cluster_name="cluster1"
wsrep_sst_method=rsync
wsrep_node_address= " 10.12.0.134"
wsrep_node_name="gdb01"
On the 1st node, run the command:
galera_new_cluster
Now the Cluster size = 1 (check that)
On the 2nd node run
systemctl start mariadb
Check the cluster size again
On the 3rd node run
systemctl start mariadb
Check the cluster size again
To check the cluster, create new database and new table
(InnoDB) , insert data, and check that everything is
replicated to the other servers.
create database test100;
use test100;
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
insert into t1(a) values(50);
insert into t1(a) values(60);
insert into t1(a) values(70);
Yes No
Do you accept
increasing the DB
size:
What happens if we have three members?
What is the final decision? Yes
Yes No Yes
Do you accept
increasing the DB
Size:
Galera Cluster takes a quorum vote whenever a node does not respond and is
suspected of no longer being a part of the cluster.
The component that has quorum alone continues to operate as the Primary
Component, while those without quorum enter the non-primary state and begin
attempt to connect with the Primary Component.
Expected Votes: 5
Expected Votes: 5
Total votes: 2
Total votes: 3
No Quorum
Valid Quorum
When you design your infrastructure try to avoid split brain conditions (by
using multiple datacenters, switches, servers, Power sources, etc )
You can also make advanced configurations to modify the weights for
member nodes
You can protect your Galera cluster using your firewall, or using iptables or
firewalld in linux, but you need to keep the following ports open:
◦ 3306 For MySQL client connections and State Snapshot Transfer that use the mysqldump
method.
◦ 4567 For Galera Cluster replication traffic, multicast replication uses both UDP transport
and TCP on this port.
◦ 4568 For Incremental State Transfer.
◦ 4444 For all other State Snapshot Transfer.
For securing database server and client connections, you can use the internal
MySQL SSL support.
In the event that you use logical transfer methods for state snapshot transfer, such
as mysqldump, this is the only step you need to take in securing your state
snapshot transfers. ##### /etc/my.cnf File
# MySQL Server
[mysqld]
ssl-ca = /path/to/ca-cert.pem
ssl-key = /path/to/server-key.pem
ssl-cert = /path/to/server-cert.pem
# OR use:
SET GLOBAL wsrep_provider_options="socket.ssl_key=/path/to/server-
key.pem/;socket.ssl_cert=/path/to/server-cert.pem;socket.ssl_ca=/path/to/cacert.pem“
How to balance client requests to your cluster?
Client
Clients connect to HAProxy
HAProxy is used for load balancing
HAProxy used for fault tolerance
Client Client Client
HAProxy
In this Environment we still have Single Point Of Failure.
To avoid Single Point Of Failure , you need to use more than
one HAProxy
Client Client Client
HAProxy
To which IP clients will connect?
Client Client Client
HAProxy HAProxy
Pacemaker creates cluster for HAProxy nodes
It monitors the nodes using heartbeat
Client Client Client
It can be used to create Virtual IP
I Will be glad to share my knowledge with you, and to hear from you
about your experience and advices regarding Galera Cluster and MySQL
High Availability.
I will consider adding any additional topics that you think it’s important for
this course.
http://galeracluster.com/documentation-webpages/
https://mysqlhighavailability.com
https://clusterengine.me