CentOS 使用XtraBackup在线热部署mysql replication

CentOS 7 的服务器环境
1.安装XtraBackup (主库执行)
yum -y install perl perl-devel libaio libaio-devel perl-Time-HiRes perl-DBD-MySQL libev

rpm -ivh https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.3.4/binary/redhat/7/x86_64/percona-xtrabackup-2.3.4-1.el7.x86_64.rpm

2.备份数据(主库执行)
innobackupex --socket=/tmp/mysql.sock --user=root --password=密码 /backup/

innobackupex --socket=/tmp/mysql.sock --user=root --password=密码 --apply-log /backup/时间目录

3.传送数据库到从服务器数据库并启动mysql mysql数据目录为/usr/local/mysql/data (从库执行)
rsync -avp /backup/时间目录 root@从库服务器IP:/目录
mv 时间目录 /usr/local/mysql/data
chown -R mysql: /usr/local/mysql/data
/etc/init.d/mysql start

4.主库创建复制权限
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY '密码';

5.从库启用slave 复制进程
用cat获取binlog日志名及POS 值 cat /usr/local/mysql/data/xtrabackupbinloginfo
再在从库的mysql执行如下sql语句

CHANGE MASTER TO MASTER_HOST='主库IP', MASTER_USER='repl', MASTER_PASSWORD='密码', MASTER_LOG_FILE='binlog日志名', MASTER_LOG_POS=POS 值; start slave:

至此全文完