- A+
所属分类:技术教程
使用Percona XtraBackup搭建slave数据库
下载安装XtraBackup
1.在http://www.percona.com/downloads/XtraBackup/LATEST/
2.解压安装,并配置path路径 export PATH=$JAVA_HOME/bin:/usr/local/xxx:$PATH
3.我的mysql的配置文件是/xx/my.cnf,如果不指定,XtraBackup默认使用此文件识别mysql安装目录,数据文件目录等信息
配置ssh 信任通道
全量备份并传输到slave机器:
备份数据库,直接传输到对应的机器 ,节省空间
innobackupex --user=root --password=xxxx --stream=tar /data/tmp/ --slave-info | ssh slaveip "tar xfi - -C /data/tmp"
备份完成之后会提示日志:
日志
innobackupex: Backup created in directory '/data/tmp'
innobackupex: MySQL binlog position: filename 'binlog.000755', position 95778375
innobackupex: MySQL slave binlog position: master host '10.209.140.22', filename 'binlog.001217', position 352370216
innobackupex: You must use -i (--ignore-zeros) option for extraction of the tar stream.
140313 12:56:53 innobackupex: completed OK!
登录机器恢复
innobackupex --apply-log --ibbackup=xtrabackup /data/tmp/
日志
140313 13:53:30 InnoDB: Completed initialization of buffer pool
140313 13:53:30 InnoDB: highest supported file format is Barracuda.
140313 13:53:34 InnoDB: Waiting for the background threads to start
140313 13:53:35 Percona XtraDB (http://www.percona.com) 1.1.8-20.1 started; log sequence number 6528792620044
140313 13:53:35 [Note] Event Scheduler: Loaded 0 events
140313 13:53:35 [Note] /home/oracle/mysql/bin/mysqld: ready for connections.
Version: '5.5.18-log' socket: '/data/mysql3306/run/mysql.sock' port: 3306 Source distribution
注 :innobackupex –copy-back /data/tmp/ 目录下面的
可以把 /data/tmp/ 目录下面的 ib* copy 到 日志中的iblog目录下。 /data/tmp/下面的其他文件全部导入到 对于的datadir 目录下面。
修改conf文件, 配置service_id=xxx
只读启动mysql数据库
mysqld_safe --read-only=1 &
登录mysql 设置复制结构
在 master 上,需要创建一个复制的帐号:
grant replication slave, replication client on *.* to repl@'219.32.22.%' identified by 'password';
FLUSH PRIVILEGES;
根据备份的日志
innobackupex: MySQL binlog position: filename ‘binlog.000755’, position 95778375
--- reality like this bellow :
change master to master_host='xxx',master_user='repl',
master_password='xxxx', master_port=3306,
master_connect_retry=60,
master_log_file='binlog.000755',
master_log_pos=95778375;
启动恢复
start slave ;
show slave status \G
到此完成备库搭建