l 架構准備
Node1
192.168.15.3
Node2
192.168.15.4
VIP
192.168.15.254
l 軟件
MySQL 5.6 Keepalive
yum install gcc python-devel
easy_install mysql-python
l MySQL配置
node1:
server-id = 033306
log-bin = mysql-bin
binlog-format = row
log-slave-updates = true
gtid-mode = on
enforce-gtid-consistency = true
auto-increment-increment = 2
auto-increment-offset = 1
relay-log = /var/lib/mysql/relay-log-3306
node2:
server-id = 043306
log-bin = mysql-bin
binlog-format = row
log-slave-updates = true
gtid-mode = on
enforce-gtid-consistency = true
auto-increment-increment = 2
auto-increment-offset = 2
relay-log = /var/lib/mysql/relay-log-3306
查看兩個UUID
Node1
e05b8b73-fa94-11e4-aa31-000c29b0dac1
show global variables like '%uuid%';
Node2
2e619521-9eb4-11e5-9868-000c295b6358
賦權(node1和node2)
mysql> grant replication slave,replication client on *.* to repluser@'192.168.15.%' identified by 'replpass';
mysql> flush privileges;
備份:
mysqldump -uroot --opt --default-character-set=utf8 --triggers -R --master-data=2 --hex-blob --single-transaction --no-autocommit --all-databases > all.sql
注(會有一個警告):
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.
將導出的數據放到node2中(用免秘鑰傳輸過去):
[root@node1 ~]# yum -y install openssh-clients
[root@node2 mysql]# yum -y install openssh-clients
在node1上
[root@node1 ~]# ssh-keygen
[root@node1 ~]# ssh-copy-id 192.168.15.4
傳送文件
[root@node1 ~]# scp -rv all.sql 192.168.15.4:/tmp
=================================================
在node2上
[root@node2 mysql]# mysql </tmp/all.sql
在node2上配置連接