1、主從復(fù)制及主主復(fù)制的實(shí)現(xiàn)

主節(jié)點(diǎn)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 |+------------------+-----------+備節(jié)點(diǎn)修改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;主主復(fù)制:server-id=128使用同一個(gè)#### 2、xtrabackup實(shí)現(xiàn)全量+增量+binlog恢復(fù)庫

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)預(yù)準(zhǔn)備:確保數(shù)據(jù)一致,提交完成的事務(wù),回滾未完成的事務(wù)
[root@centos7 ~]#xtrabackup --prepare --target-dir=/back
2)復(fù)制到數(shù)據(jù)庫目錄
注意:數(shù)據(jù)庫目錄必須為空,MySQL服務(wù)不能啟動
[root@centos7 ~]#xtrabackup --copy-back --target-dir=/back
3)還原屬性
[root@centos7 ~]#chown -R mysql:mysql /data/mysql
4)啟動服務(wù)
[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次增量備份到完全備份:最后一次還原不需要加選項(xiàng)--apply-log-only
[root@centos7 ~]#xtrabackup --prepare --target-dir=/back --incrementaldir=/back/inc2
4)復(fù)制到數(shù)據(jù)庫目錄,注意數(shù)據(jù)庫目錄必須為空,MySQL服務(wù)不能啟動
[root@centos7 ~]#xtrabackup --copy-back --target-dir=/back
5)還原屬性:

chown -R mysql.mysql /data/mysql

6)啟動服務(wù):
[root@centos7 ~]#systemctl start mysqld

#### 3、MyCAT實(shí)現(xiàn)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模塊
檢查指定節(jié)點(diǎn)機(jī)器是否還能連通,用法很簡單,不涉及參數(shù),主機(jī)如果在線,則回復(fù)pong
ansible 192.168.168.1 -m ping

command 模塊
在遠(yuǎn)程的主機(jī)上執(zhí)行特定的命令
ansible 192.168.168.1 -m command -a rm -rf /data

copy 模塊
功能:實(shí)現(xiàn)主控端向目標(biāo)主機(jī)copy文件。
ansible 192.168.168.1 -m copy -a src=/etc/hosts dest=/root/

shell 模塊
shell模塊和command模塊類似,支持變量,管道等復(fù)雜的命令
ansible 192.168.168.1 -m shell -a echo 123456 | passwd root --stdin