? 实验环境
- 系统环境
查看系统版本命令:cat /etc/redhat-release

- 本实验是编译安装的Mysql ,坑太多,以后不建议采用编译安装的方式

- 启动Mysql前首先执行以下命令,创建链接
ln -s /usr/local/mysql/bin/mysql /usr/bin
- Mysql初始的root密码存放在/root/.mysql_secret
找到密码后连接数据库,一定要修改root密码,然后重新启动Mysql
? 搭建Master-Master-slave
MySQL01:192.168.4.63 Master1
MySQL02:192.168.4.64 Master2
MySQL03:192.168.4.65 Slave1
Master1与Master2互为主备,Slave1是Master1,Master2的备机(多源复制)
-
首先实现Master1,Master2互为主备的功能
-
修改/etc/my.cnf,添加如下内容:


多源复制加入了一个叫做Channel的概念,只需要在每个语句最后使用For Channel来进行区分。由于复制的原理没有改变,在没有开启GTID的时候从库需要master-info-repository、relay-log-info-repository设置为table,否则会报错:

- 授权同步帐号


- 查出M1和M2的文件和Pos值


-
执行命令将M1,M2设置为互为主备


- 查看slave状态


- 实现Slave1多源复制功能,即S1为M1,M2的共有备机
- 授权同步帐号


- 执行命令将S1作为M1,M2的备机

- 查看Slave状态


注:至此已实现多主单备的配置,亦称多源复制。Msql5.7以上版本可使用GTID模式实现此功能
数据库的备份是DBA一项非常重要的工作,本案例中我们采用xtrabackup完成数据备份需求
- 在Slave1安装xtrabackup

2.安装完成后,你就能在/etc/yum.repos.d 下看到一个percona-release.repo文件

3.测试Repository,确保Percona XtraBackup相关包已经在Repository中

4.安装Percona XtraBackup包

5.查看安装结果
- 创建备份用户
备份数据库的用户需要具有相应权限,如果要使用一个最小权限的用户进行备份,则可基于如下命令创建此类用户:


- 执行完整备份:
innobackupex --user=root --password=cbichina_123 /extrabackup
执行完成后,会自动创建当前时间的文件夹

利用 --apply-log的作用是通过回滚未提交的事务及同步已经提交的事务至数据文件使数据文件处于一致性状态。
innobackupex --apply-log /extrabackup/2018-03-06_18-15-40/
-
执行增量备份
此命令执行结束后,innobackupex命令会在/backup目录中创建一个新的以时间命名的目录以存放所有的增量备份数据。另外,在执行过增量备份之后再一次进行增量备份时,其--incremental-basedir应该指向上一次的增量备份所在的目录。
innobackupex --incremental /extrabackup/ --user=root--password=cbichina_123
- 还原
请确保信息的最行一行出现“innobackupex: completed OK!”。
innobackupex --copy-back /extrabackup/2018-03-06_18-15-40/
Mysql5.7.12多源复制 xtrabackup
原文:http://blog.51cto.com/12906823/2085967