SAP SQL Anywhere High Availability Tutorial for Business Objects
Percona Cluster with Master_Slave for Disaster Recovery
1. Prepared By: Ram Gautam email to :ramgau@gmail.com
Contents
1. Introduction ....................................................................................................................................2
2. Scope...............................................................................................................................................2
3. Intendant audience..........................................................................................................................2
4. Point to be considered/Further research .........................................................................................2
5. High Level diagram ..........................................................................................................................3
6. Used tools .......................................................................................................................................4
7. Configuration and setup ..................................................................................................................4
7.1 Asynchronous Communication between Master/Slave ..................................................................4
7.2 Percona XtraDB Cluster Configurations: .........................................................................................4
7.3 Master/Slave configuration for Asynchronous DB replication.........................................................5
STEP 1: Make a backup on TheMaster and prepare it.......................................................................5
STEP 2: Copy backed up data to TheSlave ........................................................................................7
STEP 3: Configure The Master’s MySQL server .................................................................................7
STEP 4: Start the replication.............................................................................................................8
STEP 5: Check the Master/Slave status.............................................................................................8
8. References.......................................................................................................................................8
2. Prepared By: Ram Gautam email to :ramgau@gmail.com
1. Introduction
This document is giving high level configuration about Percona 5.7, 3 node cluster with Master/Slave
database Replication for Disaster Recovery (DR) between Production Data Center (DC) and Disaster
Recovery Data Center.
2. Scope
This document covers about to configure Master/Save Database (DB) replication in centos using Percona
technologies.
3. Intendant audience
All configuration and setup are being done on Centos 6, Linux platform. So Database Administrator or
System Administrator or Developer should have basic knowledge of Linux command, MySQL database,
and Master /slave information to follow this document.
4. Point to be considered/Further research
Before start doing DB replication configuration, there may be following points to be considered.
Network stability between Production Datacenter and DR Datacenter
MySQL version at both Production DB and DR DB
DB replication strategy for MySQL storage ENGINE. Like InnoDB, MyISAM
Running query by Application.
3. Prepared By: Ram Gautam email to :ramgau@gmail.com
5. High Level diagram
This high level digram is showing two Application sets. i.e Production Set at Production Dataceter and
DR Set at Disaster Recovery Datacenter. Based on DR platform configuration we need to create identical
sets of components between Production and DR platform. For this, web server/Application server, Load
Balancer for both App & DB, and DB Cluster are the identified components for platform setup. Running
application does not often change compare to DB. So we are focusing on DB synchronization between
Production and DR platform. We cannot put synchronous communication medium to synch DB due to
network latency, each transaction cycle in DB. Due to this, we need to use Asynchronous mechanism for
DB synch.
In above figure, Red highlighted rectangle is detonated as the Virtual Private Network (VPN) between
Production DC and DR DC. Perconca tools to make Asynchronous DB replication/Hot Backup between
Production DB cluster and DR DB cluster. There is used Master/Slave concept for db replication as
source and destination DB server. One of the node from Production 3 node cluster as Master and One of
the node from DR Node Cluster.
4. Prepared By: Ram Gautam email to :ramgau@gmail.com
6. Used tools
Percona 5.7 cluster
Innobackupex/ xtrabackup
Yum
7. Configuration and setup
7.1 Asynchronous Communication between Master/Slave
Asynchronous Replication uses the approach of lazy replication. The master database asynchronously
propagates replica updates to other slave nodes. Percona comes with a tool that allows you to perform
Asynchronous DB replication/Hot Backup s of a running MySQL database, with no blocking. It’s able to
do this because of Innodb & multi-version concurrency control (MVCC). Luckily we don’t need to dig into
the guts to enjoy the benefits of this great technology.
7.2 Percona XtraDB Cluster Configurations:
Percona is an open source software company specializing in MySQL, MongoDB, and other open source
database support, consulting, managed services, and training.
Percona XtraDB Cluster is an active/active high availability and high scalability open source solution for
MySQL clustering. It integrates Percona Server and Percona XtraBackup with the Codership Galera
library of MySQL high availability solutions in a single package that enables you to create a cost-effective
MySQL high availability cluster.
We can found more information
https://www.percona.com/software/mysql-database/percona-xtradb-cluster
Installation Documentation: https://www.percona.com/downloads/Percona-XtraDB-Cluster-57/LATEST/
In other document already described about how to configure Percona cluster 5.7 cluster with High
Availability. This document consists about configuration about DB replication between two sets of db
cluster. Each Cluster consists 3 nodes because 3 nodes clusters is best practice for clustering. DB
replication configuration step starts once all Cluster successfully configuration at both Production DC and
DR DC. Then we will pick one node as Master form Production DC and one node as from DR DC
5. Prepared By: Ram Gautam email to :ramgau@gmail.com
7.3 Master/Slave configuration for Asynchronous DB replication
Based on High level diagram, configuration will be as follows:
- TheMaster ,Node at Production Cluster-Node3 (192.168.2.6)
- TheSlave ,Node at DR Cluster – Node 1 (192.168.3.4)
TheMaster, A system with a MySQL-based server installed, configured and running. This system will be
called TheMaster, as it is where your data is stored and the one to be replicated. We will assume the
following about this system:
the MySQL server is able to communicate with others by the standard TCP/IP port;
the SSH server is installed and configured;
you have a user account in the system with the appropriate permissions;
you have a MySQL’s user account with appropriate privileges.
server has binlogs enabled and unique server-id set up.
TheSlave Another system, with a MySQL-based server installed on it. We will refer to this machine as
TheSlave and we will assume the same things we did about TheMaster, except that the server-id on
TheSlave .
Percona XtraBackup, The backup tool we will use. It should be installed in both computers for
convenience.
STEP 1: Make a backup on TheMaster and prepare it
Binary logs on PXC
Binary logs are not strictly needed in PXC for replication, but you may be using them for backups or for
asynchronous slaves of the cluster. To set them up properly, we need the following settings added to
our config . For this, following configuration needs to be added in TheMaster, my.cnf config file.
# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW
#For DB replication
server_id=19216826
#binlog_format=ROW
log_slave_updates=1
log_bin=binlog
6. Prepared By: Ram Gautam email to :ramgau@gmail.com
Sample TheMaster, My.cnf will be ,After adding Replication parameter
[mysqld]
datadir=/var/lib/mysql
user=mysql
#log-error=/var/log/mysqld.log
# Path to Galera library
wsrep_provider=/usr/lib64/libgalera_smm.so
# Cluster connection URL contains the IPs of node#1, node#2 and
node#3wsrep_cluster_address=gcomm://192.168.2.4,192.168.2.5,192.168.2.6
# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW
#For DB replication
server_id=19216826
#binlog_format=ROW
log_slave_updates=1
log_bin=binlog
#gtid_mode=ON
#enforce_gtid_consistency=1
# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB
# This InnoDB autoincrement locking mode is a requirement for Galera
innodb_autoinc_lock_mode=2
# Node 1 address
wsrep_node_address=192.168.2.6
# SST method
wsrep_sst_method=xtrabackup-v2
# Cluster name
wsrep_cluster_name=test_5_7cluster_node
# Authentication for SST method
wsrep_sst_auth="sstuser:s3cret"
7. Prepared By: Ram Gautam email to :ramgau@gmail.com
TO get snapshot from Master DB:
TheMaster # innobackupex --host=127.0.0.1 --user=bkpuser --password=bkppassword --port=3306
/data/backups/new_backup/
After this is finished you should get :
innobackupex: completed OK!
This will make a copy of your MySQL data dir to the /data/backups/new_backup/$TIMESTAMP. You
have told Percona XtraBackup (through the innobackupex script) to connect to the database server
using your database user and password, and do a hot backup of all your data in it (all MyISAM, InnoDB
tables and indexes in them).
In order for snapshot to be consistent you need to prepare the data:
TheMaster # innobackupex --apply-log --host=127.0.0.1 --user=bkpuser --password=bkppassword
/data/backups/new_backup/$TIMESTAMP
STEP 2: Copy backed up data to TheSlave
TheMaster # scp -r /data/backups/new_backup/$TIMESTAMP root@ TheSlave:/data/
Stop mysql at slave after successfully copied file from Master
At minimum you need to set the server_id to a unique value. The IP address with the
periods removed can make a good server_id. Like 19216834
Update mysql data directory with just copied from Master.
TheSlave$ mv /path/to/mysql/datadir /path/to/mysql/datadir_bak
and move the snapshot from TheMaster in its place:
TheSlave$ mv /path/to/mysql/$TIMESTAMP /path/to/mysql/datadir
After you copy data over, make sure MySQL has proper permissions to access them.
TheSlave$ chown mysql:mysql /path/to/mysql/datadir
In case the ibdata and iblog files are located in different directories outside of the datadir,
you will have to put them in their proper place after the logs have been applied
STEP 3: Configure The Master’s MySQL server
Add the appropriate grant in order for slave to be able to connect to master:
TheMaster|mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'$slaveip' IDENTIFIED BY '$slavepass';
Also make sure that firewall rules are correct and that TheSlave can connect to TheMaster. Test that you
can run the mysql client on TheSlave, connect to TheMaster, and authenticate.
TheSlave$ mysql --host=TheMaster --user=repl --password=$slavepass
Verify the privileges.
mysql> SHOW GRANTS;
8. Prepared By: Ram Gautam email to :ramgau@gmail.com
STEP 4: Start the replication
Start/restat MySQL on TheSlave
Look at the content of the file xtrabackup_binlog_info, it will be something like:
TheSlave$ cat /var/lib/mysql/xtrabackup_binlog_info
TheMaster-bin.000001 481
Execute the CHANGE MASTER statement on a MySQL console and use the username and
password you’ve set up in STEP 3:
TheSlave|mysql> CHANGE MASTER TO
MASTER_HOST='$masterip',
MASTER_USER='repl',
MASTER_PASSWORD='$slavepass',
MASTER_LOG_FILE='TheMaster-bin.000001',
MASTER_LOG_POS=481;
and start the slave:
TheSlave|mysql> START SLAVE;
STEP 5: Check the Master/Slave status
You should check that everything went OK with:
TheSlave|mysql> SHOW SLAVE STATUS G
...
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...
Seconds_Behind_Master: 13
...
8. References
https://www.percona.com/blog/2015/07/16/bypassing-sst-pxc-binary-logs/
https://www.percona.com/doc/percona-xtrabackup/2.1/howtos/setting_up_replication.html
https://www.handybackup.net/mysql-replication.shtml
http://www.iheavy.com/2012/04/17/easy-mysql-replication-with-hotbackups-2/