实验环境:

192.168.132.121   master1

192.168.132.122   master2

192.168.132.123   slave

使用gtid的方式

两个主分别是192.168.132.121和192.168.132.122,一个从端192.168.132.123分别从两个主端同步数据

192.168.132.121 master1配置

[root@master ~]# cat /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=
datadir=/data/mysql
socket=/data/mysql/mysql.sock
user=mysql
skip-name-resolve
slow_query_log=on
long_query_time=
slow_query_log_file=/data/mysql/mysql-slow.log
innodb-file-per-table=
innodb_flush_log_at_trx_commit =
log_warnings =
connect_timeout =
net_read_timeout =
performance_schema_max_table_instances =
server-id =
gtid_mode=on
enforce_gtid_consistency=on
log-slave-updates=
log-bin=master-bin
log-bin-index = master-bin.index
relay-log = relay-log
relay-log-index = relay-log.index
binlog_format=row
auto_increment_offset=
auto_increment_increment= [mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid

[root@master ~]# mysql -uroot -p123456
mysql> grant replication slave on *.* to 'replication'@'192.168.132.122' identified by '';
mysql> grant replication slave on *.* to 'replication'@'192.168.132.123' identified by '';

192.168.132.122 master2配置

[root@master2 ~]# cat /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=
datadir=/data/mysql
socket=/data/mysql/mysql.sock
user=mysql
skip-name-resolve
slow_query_log=on
long_query_time=
slow_query_log_file=/data/mysql/mysql-slow.log
innodb-file-per-table=
innodb_flush_log_at_trx_commit =
log_warnings =
connect_timeout =
net_read_timeout =
performance_schema_max_table_instances =
server-id =
gtid_mode=on
enforce_gtid_consistency=on
log-slave-updates=
log-bin=master-bin
log-bin-index = master-bin.index
relay-log = relay-log
relay-log-index = relay-log.index
binlog_format=row
auto_increment_offset=
auto_increment_increment= [mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid [root@master2 ~]# mysql -uroot -p123456
mysql> grant replication slave on *.* to 'replication'@'192.168.132.121' identified by '';
mysql> grant replication slave on *.* to 'replication'@'192.168.132.123' identified by '';

192.168.132.123 slave配置

[root@slave ~]# cat /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=
datadir=/data/mysql
socket=/data/mysql/mysql.sock
user=mysql
skip-name-resolve
slow_query_log=on
long_query_time=
slow_query_log_file=/data/mysql/mysql-slow.log
innodb-file-per-table=
innodb_flush_log_at_trx_commit =
log_warnings =
connect_timeout =
net_read_timeout =
performance_schema_max_table_instances =
server-id =
gtid_mode=on
enforce_gtid_consistency=on
log-slave-updates=
log-bin=master-bin
log-bin-index = master-bin.index
relay-log = relay-log
relay-log-index = relay-log.index
binlog_format=row
auto_increment_offset=
auto_increment_increment= [mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid
[root@slave ~]# mysql -uroot -p123456

配置从库

mysql> change master to master_host='192.168.132.121',master_user='replication',master_port=,master_password='',master_auto_position= for channel 'master-1';
ERROR (HY000): To have multiple channels, repository cannot be of type FILE; Please check the repository configuration and convert them to TABLE.
mysql> show variables like '%repository%';
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| master_info_repository | FILE |
| relay_log_info_repository | FILE |
+---------------------------+-------+

需要设置convert表

/etc/my.cnf
[mysqld] #添加
master_info_repository=TABLE
relay_log_info_repository=TABLE

[root@slave ~]# systemctl restart mysqld

[root@slave ~]# mysql -uroot -p123456

mysql> show variables like '%repository%';
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| master_info_repository | TABLE |
| relay_log_info_repository | TABLE |
+---------------------------+-------+
mysql> change master to master_host='192.168.132.121',master_user='replication',master_port=,master_password='',master_auto_position= for channel 'master-1';
mysql> change master to master_host='192.168.132.122',master_user='replication',master_port=,master_password='',master_auto_position= for channel 'master-2';

查看从端状态

mysql> start slave;
Query OK, rows affected (0.01 sec) mysql> show slave status\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.132.121
Master_User: replication
Master_Port:
Connect_Retry:
Master_Log_File: master-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-log-master@002d1.
Relay_Log_Pos:
Relay_Master_Log_File: master-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 63a7f26f-a196-11e9-a2b2-000c2991dd19
Master_Info_File: mysql.slave_master_info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 63a7f26f-a196-11e9-a2b2-000c2991dd19:-
Executed_Gtid_Set: 5ad46c94-a197-11e9--000c29f004c9:,
63a7f26f-a196-11e9-a2b2-000c2991dd19:-,
662134df-a196-11e9-b432-000c2963fd11:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name: master-1 #通道1,连接master1
Master_TLS_Version:
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.132.122
Master_User: replication
Master_Port:
Connect_Retry:
Master_Log_File: master-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-log-master@002d2.
Relay_Log_Pos:
Relay_Master_Log_File: master-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 662134df-a196-11e9-b432-000c2963fd11
Master_Info_File: mysql.slave_master_info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 662134df-a196-11e9-b432-000c2963fd11:-
Executed_Gtid_Set: 5ad46c94-a197-11e9--000c29f004c9:,
63a7f26f-a196-11e9-a2b2-000c2991dd19:-,
662134df-a196-11e9-b432-000c2963fd11:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name: master-2 #通道2,连接master2
Master_TLS_Version:

查看进程

mysql> show processlist;
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
| | root | localhost | NULL | Query | | starting | show processlist |
| | system user | | NULL | Connect | | Waiting for master to send event | NULL |
| | system user | | NULL | Connect | | Slave has read all relay log; waiting for more updates | NULL |
| | system user | | NULL | Connect | | Waiting for master to send event | NULL |
| | system user | | NULL | Connect | | Slave has read all relay log; waiting for more updates | NULL |
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+

验证

master1
mysql> create database master1;
Query OK, row affected (0.00 sec) mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| master1 |
| mysql |
| performance_schema |
| sys |
+--------------------+
master2
mysql> create database master2;
Query OK, row affected (0.00 sec) mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| master2 |
| mysql |
| performance_schema |
| sys |
+--------------------+
slave查看 #已经同步
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| master1 |
| master2 |
| mysql |
| performance_schema |
| sys |
+--------------------+

多源复制,配置完成

mysql主从之多元复制的更多相关文章

  1. 高性能Mysql主从架构的复制原理及配置详解

    温习<高性能MySQL>的复制篇. 1 复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台 ...

  2. Mysql主从同步(复制)

    目录: mysql主从同步定义      主从同步机制 配置主从同步      配置主服务器      配置从服务器 使用主从同步来备份      使用mysqldump来备份      备份原始文件 ...

  3. 转:高性能Mysql主从架构的复制原理及配置详解

    温习<高性能MySQL>的复制篇. 1 复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台 ...

  4. 高性能Mysql主从架构的复制原理及配置详解(转)

    温习<高性能MySQL>的复制篇. 1 复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台 ...

  5. Mysql主从同步(复制)(转)

    文章转自:https://www.cnblogs.com/kylinlin/p/5258719.html 目录: mysql主从同步定义 主从同步机制 配置主从同步 配置主服务器 配置从服务器 使用主 ...

  6. 高性能Mysql主从架构的复制原理及配置

    1. 复制概述 1.1 mysql支持的复制类型 1.2 复制解决的问题 1.3 复制如何工作 2. 2 复制配置 2.1创建复制帐号 2.2拷贝数据 2.3配置master 2.4配置slave 2 ...

  7. MySQL主从双向同步复制

    本文介绍了mysql主从,实现mysql的双向同步复制. MySQL支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.主服务器将更新写入二进制日志文件,并维护日 ...

  8. Mysql学习总结(18)——Mysql主从架构的复制原理及配置详解

    一.复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机的数据复制到其它主机(slaves)上,并重 ...

  9. Mysql主从架构的复制

    复制类型 (1)基于语句的复制:  在主服务器上执行的SQL语句,在从服务器上执行同样的语句.MySQL默认采用基于语句的复制,效率比较高.  一旦发现没法精确复制时,会自动选着基于行的复制. (2) ...

随机推荐

  1. 25-3 requests模块的cookie和代理操作

    一.基于requests模块的cookie操作 引言:有些时候,我们在使用爬虫程序去爬取一些用户相关信息的数据(爬取张三“人人网”个人主页数据)时,如果使用之前requests模块常规操作时,往往达不 ...

  2. iOS 11 适配UIWebView,页面下移20的问题

    方案1: AppDelegate文件 didFinishLaunchingWithOptions()中添加如下代码 if (@available(iOS 11.0, *)) { [[UIScrollV ...

  3. 第四次C++

    继承与派生 一.什么是继承和派生 所谓继承就是从先辈处得到属性和行为特征.类的继承,是新的类从已有类那里得到已有的特性.从另一个角度来看这个问题,从已有类产生新类的过程就是类的派生.类的继承与派生机制 ...

  4. C语言中内存的管理

    一.动态内存分配与释放 1.为什么要使用动态内存分配,以下看一个实例,关于超市中购买记录的一段程序 #include <stdio.h> #include <string.h> ...

  5. @loj - 6353@「CodePlus 2018 4 月赛」组合数问题 2

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 请你找到 k 个不同的组合数,使得对于其中任何一个组合数 \(C ...

  6. js日期拓展方法

    最近项目中使用了大量关于日期的操作遂将其整理如下: /** * 格式化日期 * @param {String} fmt [日期类型 默认为年月日(yyyy-MM-dd)] */ Date.protot ...

  7. sublime text 3创建新文件插件-AdvanceNewFile

    这里要记录sublime text 3 在创建新文件时安装的插件–AdvanceNewFile ST本来自带的创建新文件的快捷键是ctrl+n.但是用户需要保存时才可修改名称以及文件路径.但是安装完A ...

  8. 在 Linux 安装 IIS?

    在 Linuxe 安装 IIS? 在群里有人说他的老大让他在 Linux 中安装 IIS. 一群人回复不同的解决方案. 在 Linux 安装虚拟机,再安装 Windows. (哈哈哈) 这个问题虽然有 ...

  9. fakeroot与sudo的区别

    fakeroot 可以用来模拟 root 权限,以便建立特定权限与档案拥有者的压缩文件案(tar, ar, .deb 等).透过 LD_PRELOAD 的 dynamic loader 功能,用户不必 ...

  10. Element-ui学习笔记2

    1.Button按钮 <el-button> type属性可以修改按钮主题 type='text'时为文字按钮 plain,round,circle可以修改按钮样式,plain为朴素按钮, ...