三臺機器:192.168.1.163(MASTER)mysql
192.168.1.162(SLAVE1)sql
192.168.1.161(SLAVE2)socket
三臺機器的配置文件以下:ide
[mysqld]orm
datadir=/var/lib/mysqlip
socket=/var/lib/mysql/mysql.sockit
innodb_data_file_path = ibdata1:10M:autoextendio
symbolic-links=0innodb
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES ast
log_bin=mysql_bin
gtid-mode=on
binlog_format=row
log-slave-updates
sync_binlog=1
enforce-gtid-consistency
report-host =service-ip(for 192.168.1.163)
report-port = 3306
master-info-repository = TABLE
relay-log-info-repository = TABLE
sync-master-info = 1
在master上進行操做:
grant create ,insert ,drop ,select,super,replication slave,reload on *.* to 'slave1'@'192.168.1.161' identifed by ‘slave1’ with grant option;
grant create ,insert ,drop ,select,super,replication slave,reload on *.* to 'slave2'@'192.168.1.162' identified by ‘slave2’ with grant option;
若是僅僅進行復制操做:
mysql> show master status;
+------------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+------------------------------------------+
| mysql_bin.000016 | 191 | | | 5a603647-7b06-11e5-afbf-6c0b846a1d2a:1-7 |
+------------------+----------+--------------+------------------+------------------------------------------+
在兩臺slave上面:
mysql> CHANGE MASTER TO
-> MASTER_HOST='master_host_name',
-> MASTER_USER='replication_user_name',
-> MASTER_PASSWORD='replication_password',
-> MASTER_LOG_FILE='recorded_log_file_name',
-> MASTER_LOG_POS=recorded_log_position;
分別start slave;
而後就進行復制。
下面進行MySQLfailover的故障自動切換
MySQLfailover是基於全局事物ID來進行的,在剛開始配置的時候已經開啓了GTID;
須要在slave上面進行以下操做:
mysql> CHANGE MASTER TO
> MASTER_HOST = host,
> MASTER_PORT = port,
> MASTER_USER = user,
> MASTER_PASSWORD = password,
> MASTER_AUTO_POSITION = 1;
在MySQL官網上面安裝下載mysql-utilities
MySQLfailover操做:
mysqlfailover --master=replm1@192.168.1.163 --discover-slaves-login=replm1 --force --log=log.txt