三台机器:192.168.1.163(MASTER)
192.168.1.162(SLAVE1)
192.168.1.161(SLAVE2)
三台机器的配置文件如下:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
innodb_data_file_path = ibdata1:10M:autoextend
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
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 [email protected] --discover-slaves-login=replm1 --force --log=log.txt