Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

max_connections = 1025

innodb_buffer_pool_size = 2G
innodb_log_file_size = 512M
innodb_buffer_pool_instances = 8
innodb_page_cleaners = 8
innodb_flush_method = O_DIRECT

Quy Tr�nh tao lai replicate

1.Chinh sua file master.my

At Slave Server:

mysql> STOP SLAVE;

At Master
mysql> show master status \G
*************************** 1. row ***************************
File: mysql-bin.000009
Position: 612028668
Binlog_Do_DB:
Binlog_Ignore_DB:
sys,information_schema,mysql,performance_schema,sys,information_schema,mysql,perfor
mance_schema,sys,information_schema,mysql,performance_schema,sys,information_schema
,mysql,performance_schema,sys,information_schema,mysql,performance_schema,sys,infor
mation_schema,mysql,performance_schema,sys,information_schema,mysql,performance_sch
ema,sys,information_schema,mysql,performance_schema,sys,information_schema,mysql,pe
rformance_schema,sys,information_schema,mysql,performance_schema
Executed_Gtid_Set: 89c3737f-b410-11e9-a18c-0a58c0aa04c8:1-24371
1 row in set (0.00 sec)

mysql> RESET MASTER;


Query OK, 0 rows affected (0.34 sec)

mysql> show master status \G


*************************** 1. row ***************************
File: mysql-bin.000001
Position: 154
Binlog_Do_DB:
Binlog_Ignore_DB:
sys,information_schema,mysql,performance_schema,sys,information_schema,mysql,perfor
mance_schema,sys,information_schema,mysql,performance_schema,sys,information_schema
,mysql,performance_schema,sys,information_schema,mysql,performance_schema,sys,infor
mation_schema,mysql,performance_schema,sys,information_schema,mysql,performance_sch
ema,sys,information_schema,mysql,performance_schema,sys,information_schema,mysql,pe
rformance_schema,sys,information_schema,mysql,performance_schema
Executed_Gtid_Set:
1 row in set (0.00 sec)

mysql>

2.Scale einvoice to 0

3.Backup Database master from worker-node06

oc rsh mysql-master-4-8spjq /opt/rh/rh-mysql57/root/usr/bin/mysqldump --skip-


lock-tables -h 127.0.0.1 -P 3306 -u root --password=fpsadmin --all-databases >
/backup/einvoicebk.sql.now.20191213.00

After backup can scale to 0 and up to 1 with master db;

4. Copy file from worker-node to pod

# oc rsync /backup/now mysql-slave-4-hkw4z:/tmp/now


# oc rsync /backup/20191213 mysql-slave-4-525zs:/tmp/20191213

5. Restore on slave

# mysql -uroot -p
mysql> source /tmp/now/now/einvoicebk.sql.now.20190920.00

6. Setup Slave
mysql> RESET SLAVE;
mysql> CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=1;
mysql> START SLAVE;
mysql> SHOW SLAVE STATUS \G

### for formart STATEMENT


CHANGE MASTER TO MASTER_HOST='mysql-master', MASTER_USER='master',
MASTER_PASSWORD='fpsadmin', MASTER_AUTO_POSITION = 1;

### for format ROW


CHANGE MASTER TO MASTER_HOST='mysql-master', MASTER_USER='master',
MASTER_PASSWORD='fpsadmin', MASTER_AUTO_POSITION = 0;

Master uuid
89c3737f-b410-11e9-a18c-0a58c0aa04c8
Master_UUID: 89c3737f-b410-11e9-a18c-0a58c0aa04c8

Slave uuid
Executed_Gtid_Set: 803fdfb3-b410-11e9-95e0-0a58c0a804e8:1-9479,
89c3737f-b410-11e9-a18c-0a58c0aa04c8:1-7890

EG
MASTER UUID: 4c2ad77f-697e-11e3-b2c3-c80aa9f17dc4
SLAVE UUID: 5b37def1-6189-11e3-bee0-e89a8f22a444

slave>show slave status;

copy the 'Executed_Gtid_Set' value. '4c2ad77f-697e-11e3-b2c3-c80aa9f17dc4:1-


659731804,5b37def1-6189-11e3-bee0-e89a8f22a444:1-70734947-80436012:80436021-
80437839'

SET GTID_NEXT="5b37def1-6189-11e3-bee0-e89a8f22a444:80437840";
(last_executed_slave_gtid_on_master + 1)

/var/lib/mysql/data/master.info

Executed_Gtid_Set: 89c3737f-b410-11e9-a18c-0a58c0aa04c8:1-349
mysqlbinlog --base64-output=DECODE-ROWS --verbose mysql-relay-bin.000017 > mysql-
relay-bin.000017.decode.sql

grep --color=always -A 30 472372965 mysql-relay-bin.000017.decode.sql

SHOW GRANTS FOR 'appuser'@'%';

GRANT TRIGGER ON i0100100079068.* TO 'appuser'@'%';

GRANT INSERT ON i0100100079068.* TO 'appuser'@'%';


GRANT UPDATE ON i0100100079068.* TO 'appuser'@'%';
GRANT SELECT ON i0100100079068.* TO 'appuser'@'%';
GRANT CREATE ON i0100100079068.* TO 'appuser'@'%';
GRANT DROP ON i0100100079068.* TO 'appuser'@'%';
FLUSH PRIVILEGES;

GRANT INSERT ON fyi.* TO dev;


GRANT UPDATE ON fyi.* TO dev;
GRANT DELETE ON fyi.* TO dev;
GRANT SELECT ON fyi.* TO dev;
GRANT CREATE ON fyi.* TO dev;
GRANT DROP ON fyi.* TO dev;

### SLAVE
bash-4.2$ cat mysqld-slave
#!/bin/bash
#
# This is an entrypoint that runs the MySQL server in the 'slave' mode.
#

export_vars=$(cgroup-limits); export $export_vars


source ${CONTAINER_SCRIPTS_PATH}/common.sh
set -eu
if [[ -v DEBUG_IGNORE_SCRIPT_FAILURES ]]; then
set +e
fi

export_setting_variables

log_volume_info $MYSQL_DATADIR

export MYSQL_RUNNING_AS_SLAVE=1

# Generate the unique 'server-id' for this master


export MYSQL_SERVER_ID=$(server_id)
log_info "The 'slave' server-id is ${MYSQL_SERVER_ID}"

# pre-init files
process_extending_files ${APP_DATA}/mysql-pre-init/ ${CONTAINER_SCRIPTS_PATH}/pre-
init/

if [ ! -e "${MYSQL_DATADIR}/mysql" ]; then
# Initialize MySQL database and wait for the MySQL master to accept
# connections.
initialize_database "$@"
wait_for_mysql_master

mysql $mysql_flags <<EOSQL


CHANGE MASTER TO MASTER_HOST='${MYSQL_MASTER_SERVICE_NAME}',MASTER_USER='$
{MYSQL_MASTER_USER}', MASTER_PASSWORD='${MYSQL_MASTER_PASSWORD}',
MASTER_AUTO_POSITION = 1;
EOSQL

# init files
process_extending_files ${APP_DATA}/mysql-init/ ${CONTAINER_SCRIPTS_PATH}/init/

# Restart the MySQL server with public IP bindings


shutdown_local_mysql
fi

unset_env_vars
log_volume_info $MYSQL_DATADIR
log_info 'Running final exec -- Only MySQL server logs after this point'
exec ${MYSQL_PREFIX}/libexec/mysqld --defaults-file=$MYSQL_DEFAULTS_FILE \
--report-host=$(hostname -I) "$@" 2>&1
bash-4.2$

### MASTER
bash-4.2$ cat /usr/bin/run-mysqld-master
#!/bin/bash
#
# This is an entrypoint that runs the MySQL server in the 'master' mode.
#

export_vars=$(cgroup-limits); export $export_vars


source ${CONTAINER_SCRIPTS_PATH}/common.sh
set -eu
if [[ -v DEBUG_IGNORE_SCRIPT_FAILURES ]]; then
set +e
fi

export_setting_variables

log_volume_info $MYSQL_DATADIR

export MYSQL_RUNNING_AS_MASTER=1

# The 'server-id' for master needs to be constant


export MYSQL_SERVER_ID=1
log_info "The 'master' server-id is ${MYSQL_SERVER_ID}"

# pre-init files
process_extending_files ${APP_DATA}/mysql-pre-init/ ${CONTAINER_SCRIPTS_PATH}/pre-
init/

if [ ! -d "$MYSQL_DATADIR/mysql" ]; then
initialize_database "$@"
else
start_local_mysql "$@"
fi

log_info 'Setting passwords ...'


[ -f ${CONTAINER_SCRIPTS_PATH}/passwd-change.sh ] && source $
{CONTAINER_SCRIPTS_PATH}/passwd-change.sh

# Setup the 'master' replication on the MySQL server


mysql $mysql_flags <<EOSQL
CREATE USER IF NOT EXISTS '${MYSQL_MASTER_USER}'@'%' IDENTIFIED BY '$
{MYSQL_MASTER_PASSWORD}';
GRANT REPLICATION SLAVE ON *.* TO '${MYSQL_MASTER_USER}'@'%';
FLUSH PRIVILEGES;
EOSQL

# init files
process_extending_files ${APP_DATA}/mysql-init/ ${CONTAINER_SCRIPTS_PATH}/init/

# Restart the MySQL server with public IP bindings


shutdown_local_mysql
unset_env_vars
log_volume_info $MYSQL_DATADIR
log_info 'Running final exec -- Only MySQL server logs after this point'
exec ${MYSQL_PREFIX}/libexec/mysqld --defaults-file=$MYSQL_DEFAULTS_FILE "$@" 2>&1
bash-4.2$

You might also like