Configure MySQL DB replication
This guide describes configuring of the replication between MySQL databases using the Percona toolkit. It is assumed that 2 SPA environments are already installed.
Prerequisites
/opt/workfusion:<INSTALL_DIR>is the default Workfusion installation directory.- 10.0.0.1 is the IP address of the Master role.
- 10.0.0.2 is the IP address of the Slave role.
- Export MASTER_NAME=10.0.0.1
- Export SLAVE_NAME=10.0.0.2
- Export BACKUP_DIR=
$INSTALL_DIR/backup - Export INSTALL_DIR=
/opt/workfusion - Export REPL_USER=
repl - Export REPL_PASS=
repl
Configure replication on Master
To configure replication:
In
/opt/workfusion/mysql/usr/my.cnf, turn on log-bin:Comment the following line:
init_connect='CALL wfdb.change_isolation_level('wfdb_read@%')'Add the following lines to the file:
server-id = 10 log-bin = /opt/workfusion/mysql/var/log/mysql-replication.log
Log in to the MySQL DB to grant permissions to
$REPL_USER:GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'repl'@'%' IDENTIFIED BY 'repl';Create a backup file:
$ mkdir -p $BACKUP_DIR $ innobackupex --user=mysql -p $BACKUP_DIR --no-timestamp $ innobackupex --apply-log $BACKUP_DIRRestart the MySQL service:
$ wfmanager restart mysql
Configure replication on Slave
To configure replication:
Create a directory for backups:
$ mkdir -p $BACKUP_DIR $ cd $BACKUP_DIRCopy a backup file from Master to Slave:
$ rsync -avu $MASTER_NAME:$BACKUP_DIR/* $SLAVE_NAME:$BACKUP_DIRStop the MySQL service:
$ wfmanager stop mysqlBack up old data:
$ mv $INSTALL_DIR/mysql/var/lib/mysql $INSTALL_DIR/mysql_OLDRestore files from the backup to the data location:
$ cd $BACKUP_DIR $ mkdir -p $INSTALL_DIR/mysql/data $ xtrabackup --move-back --target-dir=$BACKUP_DIRCheck connection from Slave to Master:
$ mysql --host=$MASTER_NAME --user=mysql -pIn the
/opt/workfusion/mysql/usr/my.cnfMySQL configuration file, specifyserver-id:server-id = 20Start the MySQL service:
$ wfmanager stop mysqlLog in to MySQL DB to change the
MASTER_LOG_FILEandMASTER_LOG_POSparameters:CHANGE MASTER TO MASTER_HOST='10.0.0.1', MASTER_USER='repl', MASTER_PASSWORD='repl', MASTER_LOG_FILE='mysql-replication.000001', MASTER_LOG_POS=10; START SLAVE; SHOW SLAVE STATUS \G;
note
This information can be found in $BACKUP_DIR/xtrabackup_binlog_info.
Change role from Slave to Master
To change a role:
Log in to the MySQL DB to grant the permission to
$REPL_USER:STOP SLAVE; RESET MASTER; RESET SLAVE ALL;Check the status. The command must return the empty set:
SHOW SLAVE STATUS \G;Restart all services:
$ wfmanager restart all