mysql master slave deployment

#开启binlog
log_bin=/data/binlog/mysql-bin

 

#主库进行备份
innobackupex --defaults-file=/etc/my.cnf --socket=/data/binlog/mysql.sock --stream=tar /backup/xtrabackup/ 2>/backup/bak_log/$log | gzip 1>/backup/xtrabackup/xtrabackup.tar.gz

 

#从库停服务清理数据目录
service mysqld stop
rm -rf /data/*
mkdir -p /data/{binlog,log,mysqldata,relay_log}

#还原文件
tar -xvf xtrabackup.tar -C /data/mysqldata/
touch /data/log/mysqld.err
chown -R mysql:mysql /data
innobackupex --defaults-file=/etc/my.cnf --use-memory=800M --apply-log /data/mysqldata

#重启跳过执行事务

service mysqld start
gtid=`awk '{print $3}' /data/mysqldata/xtrabackup_binlog_info`
echo $gtid

mysql <<eof
set global super_read_only=off;
reset master;stop slave;reset slave;
set global gtid_purged="$gtid";
show master status;

change master to master_host='192.168.136.123', master_user='replica_user',master_password='Pas5W@rd',master_auto_position=1;
start slave;
show slave status \G;

set global super_read_only=on;
eof

 

 

 

semi-sync    https://dev.mysql.com/doc/mysql-replication-excerpt/5.7/en/replication-semisync-installation.html

 

create user 'replica_user'@'%' identified with mysql_native_password by 'Pas5W@rd';

grant replication slave on *.* to 'replica_user'@'%';

change master to master_host='192.168.136.123', master_user='replica_user',master_password='Pas5W@rd',master_auto_position=1;

 

 

#修改server-id,semi-sync,只读设置,binlog过期1天,

posted @ 2021-01-11 17:49  sam_wang10  阅读(76)  评论(0编辑  收藏  举报