1.mysql添加从库
node1 主库
node2 新服务器
2.node1已经配置免密码SSH登陆到node2
在node2上执行
ssh-keygen -t rsa
在node1上新建
authorized_keys
将node2中的id_rsa.pub中的内容,添加到node1的authorized_keys
3.两台机器上都安装percona-xtrabackup
sudo yum install https://www.percona.com/downloads/percona-release/redhat/latest/percona-release-0.1-4.noarch.rpm
yum list | grep percona-xtrabackup
yum install percona-xtrabackup-24
4.两台机器上安装lz4
yum install lz4 -y
5.在node2上创建/tmp/mysql
6.执行同步
innobackupex --user=root --password=root --parallel=4 --socket=/var/lib/mysql/mysql.sock --no-timestamp \
--stream=xbstream . | lz4 -B4 | ssh node2 "cat - | lz4 -d -B7 | xbstream -x -C /tmp/mysql"
7.导入数据后,还要执行下整理操作
innobackupex --apply-log /tmp/mysql/
8. 将整理好的数据库文件导入到原先的mysql datadir里
innobackupex --copy-back /tmp/mysql/
9.mysql就启动
chown mysql.mysql /data/mysql/ -R
确保serverid不相同
/etc/init.d/mysql start
10.查看位子
cat /data/backup/full/xtrabackup_binlog_info
mysql-bin.0000022 1231231
11.登录到slave库执行下列语句开启同步
change master to master_host='xxxx',master_user='repl',master_password='repl',master_port=3306,master_log_file='mysql-bin.0000022',master_log_pos=1231231;
start slave;
show slave status\G;