1、主从复制及主主复制的实现

主节点my.cnfsymbolic-links=0datadir=/data/mysqlsocket=/data/mysql/mysql.socklog-error=/var/log/mysql/mysqld.logpid-file=/data/mysql/mysqld.pidlog-bin=/data/mysql/mysql-binserver-id=128[client]socket=/data/mysql/mysql.sockmysql>GRANT REPLICATION SLAVE ON *.* TO ‘repluser’@’192.168.253.%’ IDENTIFIED BY ‘Huawei12#$’;mysql> show master logs;+------------------+-----------+| Log_name         | File_size |+------------------+-----------+| mysql-bin.000001 |       177 || mysql-bin.000002 |     10491 || mysql-bin.000003 |       177 || mysql-bin.000004 |       448 |+------------------+-----------+备节点修改uuid 主备不一致vi /data/mysql/auto.cnf [auto]server-uuid=922b5420-4a7c-11ec-825d-000c2945d239my.cnfsymbolic-links=0datadir=/data/mysqlsocket=/data/mysql/mysql.socklog-error=/var/log/mysql/mysqld.logpid-file=/data/mysql/mysqld.pidlog-bin=/data/mysql/mysql-binserver-id=129read_only=onrelay_log=relay-logrelay_log_index=relay-log.index systemctl restart mysqldmysql> help change master to;Name: CHANGE MASTER TOCHANGE MASTER TO  MASTER_HOST=source2.example.com,  MASTER_USER=replication,  MASTER_PASSWORD=password,  MASTER_PORT=3306,  MASTER_LOG_FILE=source2-bin.001,  MASTER_LOG_POS=4,  MASTER_CONNECT_RETRY=10;主主复制:server-id=128使用同一个#### 2、xtrabackup实现全量+增量+binlog恢复库

wget https://downloads.percona.com/downloads/Percona-XtraBackup-2.4/Percona-XtraBackup-2.4.23/binary/redhat/7/x86_64/percona-xtrabackup-24-2.4.23-1.el7.x86_64.rpm

yum -y install percona-xtrabackup-24-2.4.23-1.el7.x86_64.rpm

1)预准备:确保数据一致,提交完成的事务,回滚未完成的事务
[root@centos7 ~]#xtrabackup --prepare --target-dir=/back
2)复制到数据库目录
注意:数据库目录必须为空,MySQL服务不能启动
[root@centos7 ~]#xtrabackup --copy-back --target-dir=/back
3)还原属性
[root@centos7 ~]#chown -R mysql:mysql /data/mysql
4)启动服务
[root@centos7 ~]#systemctl start mysqld

增量+binlog还原

xtrabackup -uroot -pHuawei12#$ --backup --target-dir=/back/inc1 --incremental-basedir=/back
xtrabackup -uroot -pHuawei12#$ --backup --target-dir=/back/inc2 --incremental-basedir=/back

[root@centos7 ~]#xtrabackup --prepare --apply-log-only --target-dir=/back
2)合并第1次增量备份到完全备份
[root@centos7 ~]#xtrabackup --prepare --apply-log-only --target-dir=/back --incremental-dir=/back/inc1
3)合并第2次增量备份到完全备份:最后一次还原不需要加选项--apply-log-only
[root@centos7 ~]#xtrabackup --prepare --target-dir=/back --incrementaldir=/back/inc2
4)复制到数据库目录,注意数据库目录必须为空,MySQL服务不能启动
[root@centos7 ~]#xtrabackup --copy-back --target-dir=/back
5)还原属性:

chown -R mysql.mysql /data/mysql

6)启动服务:
[root@centos7 ~]#systemctl start mysqld

#### 3、MyCAT实现MySQL读写分离

./bin/mycat start

[root@128 ~]# cat /root/mycat/conf/schema.xml


http://io.mycat/">;

              

writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
select user()

password="Huawei12#$">

#### 4、ansible常用模块介绍

ping模块
检查指定节点机器是否还能连通,用法很简单,不涉及参数,主机如果在线,则回复pong
ansible 192.168.168.1 -m ping

command 模块
在远程的主机上执行特定的命令
ansible 192.168.168.1 -m command -a rm -rf /data

copy 模块
功能:实现主控端向目标主机copy文件。
ansible 192.168.168.1 -m copy -a src=/etc/hosts dest=/root/

shell 模块
shell模块和command模块类似,支持变量,管道等复杂的命令
ansible 192.168.168.1 -m shell -a echo 123456 | passwd root --stdin