首页 / 数据库 / MySQL / MySQL与MariaDB 新型主从集群配置GTID
前面写了《MySQL与MariaDB 传统主从集群配置》,该技术已经非常成熟。从Mysql5.6和MariaDB10.0开始,有了新型的主从方案GTID,不过这两个系统到这个版本出现了分支,具体实现已经不同,配置方法也不同,下文分别讲述。MariaDB:我用的版本还是10.1版,目前该版本还不是稳定版,但不影响测试。先部署好两个数据库实例,参见 http://www.linuxidc.com/Linux/2015-10/124420.htm直到创建好复制用户。我们这里的由于是新创建的数据库,因此先重置下主库的状态,此操作不是必须,如果后面发现同步sql执行失败,可执行这行跳过失败的sql。MariaDB [mysql]> reset master;这时可以发现旧的bin-log都已删除,已经只剩下一个新创建的日志文件。然后执行下面的语句,注意后面 master_use_gtid=current_pos 这行跟传统模式不同。MariaDB [mysql]> change master tomaster_host="localhost",master_port=10001,master_user="rep",master_password="123456",master_use_gtid=current_pos;Query OK, 0 rows affected (0.36 sec) MariaDB [mysql]> start slave;Query OK, 0 rows affected (0.18 sec) MariaDB [mysql]> show slave status G;*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: localhost Master_User: rep Master_Port: 10001 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 313 Relay_Log_File: lyw-hp-relay-bin.000002 Relay_Log_Pos: 601 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes 。。。。。。 Using_Gtid: Current_Pos后面比传统的主从方式多了一行内容 Using_Gtid: Current_Pos,说明使用了新的主从方式。设置好后,同样需要跟测试下,对主库的修改是否影响到从库的内容。Mysql:Mysql5.6版本开始支持GTID复制方式,其配置方式跟MariaDB不同,需要先在配置文件里修改相关配置。新增内容如下[mysqld]gtid-mode = onlog-slave-updates = trueenforce-gtid-consistency= true
然后启动这两个数据库。同样需要配置相应的同步用户。然后在从库执行下面的命令,注意最后这行 master_auto_position=1 跟 MariaDB的不同。mysql> change master to master_host="localhost", master_port=20001, master_user="rep", master_password="123456",master_auto_position=1; mysql> start slave; mysql> show slave status G;*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: localhost Master_User: rep Master_Port: 20001 Connect_Retry: 60 Master_Log_File: mysql-bin.000004 Read_Master_Log_Pos: 850 Relay_Log_File: lyw-hp-relay-bin.000002 Relay_Log_Pos: 1060 Relay_Master_Log_File: mysql-bin.000004 Slave_IO_Running: Yes Slave_SQL_Running: Yes 。。。。。。 Retrieved_Gtid_Set: a34819a9-700f-11e5-a841-34238703623c:1-3 Executed_Gtid_Set: a34819a9-700f-11e5-a841-34238703623c:1-3可见最后增加了两行跟GTID相关的状态,Retrieved_Gtid_Set,Executed_Gtid_Set,说明采用了GTID这种新型同步方式。用同样的方法,一个主数据库后面可以跟多个从数据库,增加数据的可靠性和读的吞吐量。以上主从配置是最基本配置,在线上使用还不够,主挂了后,并不会自动进行切换,请关注。MySQL分片高可用集群之Cobar部署使用 http://www.linuxidc.com/Linux/2015-10/124418.htmMySQL分片高可用集群之Fabric部署使用 http://www.linuxidc.com/Linux/2015-10/124419.htm--------------------------------------分割线 --------------------------------------Linux系统教程:如何检查MariaDB服务端版本 http://www.linuxidc.com/Linux/2015-08/122382.htmMariaDB Proxy读写分离的实现 http://www.linuxidc.com/Linux/2014-05/101306.htmLinux下编译安装配置MariaDB数据库的方法 http://www.linuxidc.com/Linux/2014-11/109049.htmCentOS系统使用yum安装MariaDB数据库 http://www.linuxidc.com/Linux/2014-11/109048.htm安装MariaDB与MySQL并存 http://www.linuxidc.com/Linux/2014-11/109047.htmUbuntu 上如何将 MySQL 5.5 数据库迁移到 MariaDB 10 http://www.linuxidc.com/Linux/2014-11/109471.htm[翻译]Ubuntu 14.04 (Trusty) Server 安装 MariaDB http://www.linuxidc.com/Linux/2014-12/110048htmMariaDB 的详细介绍:请点这里
MariaDB 的下载地址:请点这里本文永久更新链接地址