今天工作中用到了xtrabackup进行数据备份,遇到了一些问题,在这里记录。
数据同步方式有很多种,比如mysqldump,直接复制数据文件,xtrabackup。在数据库存储引擎是innodb时xtrabackup可以不用锁表,所以建议用xtrabackup方式。
本次实验使用的是xtrabackup,其他方式请参考mysql手册。
我是使用tar包进行安装,具体步骤如下:
tar -zxvf percona-xtrabackup-2.4.10-Linux-x86_64.libgcrypt145.tar.gz
mv percona-xtrabackup-2.4.10-Linux-x86_64 /usr/local/xtrabackup
ln -sf /usr/local/xtrabackup/bin/* /usr/bin/ #给命令建个软连接
查看版本
xtrabackup --version
xtrabackup version 2.4.10 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 3198bce)
具体参考博客:https://blog.youkuaiyun.com/jolly10/article/details/80051460
1.配置主库
配置binlog,linux下是在/etc/my.cnf中配置,如果不知道位置可以使用以下语句查找
find / -name my.cnf
(如果已经配置binlog就可以不配置了,server-id要保证主从中唯一)。修改如下配置。
log-bin=mysql-bin
server-id=1
binlog_format=row
查看是否启用了日志
mysql>show variables like 'log_bin';
2.备份主库
xtrabackup --backup --user=root --password=??? --target-dir=/tmp/backupdir
xtrabackup --user=root--password=??? --prepare --target-dir=/tmp/backupdir
配置时遇到以下问题:
Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup' as 'dba' (using password: YES).
innobackupex: Error: Failed to connect to MySQL server: DBI connect(';mysql_read_default_group=xtrabackup','db a',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/bin/innobackupex line 2945.
我通过加上host解决了这个问题
xtrabackup --backup --user=root --password=??? --target-dir=/tmp/backupdir --host=192.168.220.XXX
xtrabackup --user=root--password=??? --prepare --target-dir=/tmp/backupdir --host=192.168.220.XXX
3.传输备份内容到从库
可以用ftp,sftp,rsync等,这里我使用rsync
rsync -avpP -e ssh /tmp/backupdir TheSlave(也就是target ip address):/tmp/backupdir
SSH 连接远程主机时,会检查主机的公钥。如果是第一次该主机,会显示该主机的公钥摘要,提示用户是否信任该主机:
The authenticity of host '192.168.220.XXX (192.168.220.XXX)' can't be established.
ECDSA key fingerprint is SHA256:Oq1uuClFXLFu8aeUlmhu3SsbPI1LYWCqjlbc17skD4s.
ECDSA key fingerprint is MD5:74:60:f1:4d:82:da:71:40:2c:21:11:02:b6:87:26:10.
Are you sure you want to continue connecting (yes/no)? n
当选择接受,就会将该主机的公钥追加到文件 ~/.ssh/known_hosts 中。当再次连接该主机时,就不会再提示该问题了。 如果因为某种原因(服务器系统重装,服务器间IP地址交换,DHCP,虚拟机重建,中间人劫持),该IP地址的公钥改变了,当使用 SSH 连接的时候,会报错:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
e9:0c:36:89:7f:3c:07:71:09:5a:9f:28:8c:44:e9:05.
Please contact your system administrator.
Add correct host key in /home/jiangxin/.ssh/known_hosts to get rid of this message.
Offending key in /home/jiangxin/.ssh/known_hosts:81
RSA host key for 192.168.0.110 has changed and you have requested strict checking.
Host key verification failed.
可以在 ssh 命令行中用 -o 参数进行取消ssh验证
$ ssh -o StrictHostKeyChecking=no 192.168.220.XXX
未完