基于Master-DistributedMaster-Slave架构的replication

实现如下架构Master-DistributedMaster-Slave(单主到从到多从)
------------------------------------------|54.58(innodb)
10.10.54.57(master)---54.56(blackhole)----|54.59(innodb)
环境介绍:
系统版本:CentOS 6.4_x86_64    
MysqlServer version: 5.5.30-log Source distribution   
解析:###54.56 config
==============================
default-storage-engine=blackhole
log-slave-update=1
log-bin=ms-mysql-bin
#当表带engine=innodb,跳过innodb支持,中间层自动使用引擎blackhole
skip-innodb
===============================
导出54.57所有的表结构,修改为blackhole,导入54.56
1.规划网络和主从机器
master:10.10.54.57
blackhole:10.10.54.56
slave1:10.10.54.58
slave2:10.10.54.59
2.修改配置文件
master:
 vim /etc/my.cnf
=====================
[mysqld]
log-bin=master-bin
server-id       = 1
=====================
##重启:/etc/init.d/mysqld restart
blackhole:
 vim /etc/my.cnf
======================
[mysqld]
default_storage_engine=blackhole
log-slave-updates=1
log-bin=blackhole-bin
skip-innodb
server-id       = 10
========================
##重启:/etc/init.d/mysqld restart
slave1:
vim /etc/my.cnf
===================
[mysqld]
log-bin=slave-bin
replicate-wild-do-table=tuge.%
server-id       = 20
====================
##重启:/etc/init.d/mysqld restart
slave2:
vim /etc/my.cnf
======================
[mysqld]
log-bin=slave-bin
replicate-wild-do-table=haha.%
server-id       = 22
=======================
##重启:/etc/init.d/mysqld restart
注意:slave的server-id一定要大于master的server-id.
3.在master上创建数据库和表
mysql>create database tuge;
mysql>create database haha;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| haha               |
| mysql              |
| performance_schema |
| test               |
| tuge               |
+--------------------+
mysql> use tuge;
mysql> create table shiwei(id int not null,name varchar(20));
mysql> insert into shiwei values(1,'dazhima'),(2,'xiaozhima');
mysql> select * from shiwei;
+----+-----------+
| id | name      |
+----+-----------+
|  1 | dazhima   |
|  2 | xiaozhima |
+----+-----------+
mysql> use haha;
mysql> create table hehe(id int not null,name varchar(20));
mysql> insert into hehe select * from tuge.shiwei;
mysql> insert into hehe select * from tuge.shiwei;
mysql> select * from hehe;
+----+-----------+
| id | name      |
+----+-----------+
|  1 | dazhima   |
|  2 | xiaozhima |
|  1 | dazhima   |
|  2 | xiaozhima |
+----+-----------+
4.查看master的状态:
mysql> show master status;
+-------------------+----------+--------------+------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000006 |      107 |              |                  |
+-------------------+----------+--------------+------------------+
4.在master上创建用户并授予权限
mysql>grant replication slave,reload,super on *.* to 'wxq'@'10.10.54.%' identified by '123456';
##刷新权限:
mysql> flush privileges;
5.测试创建用户
##在slave任意一台上都可成功登录
 mysql -uwxq -p123456 -h10.10.54.57
6.备份master上的数据,把备份master数据还原到blackhole上
mysqldump -uroot -p --master-data=2 --events --single-transaction --flush-logs --all-databases |mysql -uroot -p123456 -h10.10.54.56 
7.在blackhole上创建用户并授予权限
mysql>grant replication slave,reload,super on *.* to 'wxq'@'10.10.54.%' identified by '123456';
##刷新权限:
mysql> flush privileges;
8.测试创建用户
##在slave1&&2上都可成功登录
 mysql -uwxq -p123456 -h10.10.54.56
9.在blackhole上做change master操作
mysql> change master to master_host='10.10.54.57',master_user='wxq',master_password='123456',master_log_file='master-bin.000006',master_log_pos=107;
10.查看状态
mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.10.54.57
                  Master_User: wxq
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000006
          Read_Master_Log_Pos: 107
               Relay_Log_File: xiao56-relay-bin.000002
                Relay_Log_Pos: 254
        Relay_Master_Log_File: master-bin.000006
             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: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 107
...................................................................
mysql> show master status;
+----------------------+----------+--------------+------------------+
| File                 | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+----------------------+----------+--------------+------------------+
| blackhole-bin.000004 |  1052908 |              |                  |
+----------------------+----------+--------------+------------------+
11.验证blackhole
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| haha               |
| mysql              |
| performance_schema |
| test               |
| tuge               |
+--------------------+
mysql> select * from haha.hehe;
Empty set (0.00 sec)
mysql> show create table haha.hehe;
+-------+--------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                             |
+-------+--------------------------------------------------------------------------------------------------------------------------+
| hehe  | CREATE TABLE `hehe` (
  `id` int(11) NOT NULL,
  `name` varchar(20) DEFAULT NULL
) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8 |
+-------+--------------------------------------------------------------------------------------------------------------------------+
注意:blackhole存储引擎只存储表的结构,不存储数据。
12.在slave1和slave2上分别做change master操作
mysql>change master to master_host='10.10.54.56',master_user='wxq',master_password='123456',
master_log_file='blackhole-bin.000004',master_log_pos=1052908;
13.查看slave1&&slave2的slave状态
mysql> start slave;  
mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.10.54.56
                  Master_User: wxq
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: blackhole-bin.000004
          Read_Master_Log_Pos: 1052908
               Relay_Log_File: xiao58-relay-bin.000002
                Relay_Log_Pos: 257
        Relay_Master_Log_File: blackhole-bin.000004
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: tuge.%
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1052908
              Relay_Log_Space: 414
..................................................................
mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.10.54.56
                  Master_User: wxq
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: blackhole-bin.000004
          Read_Master_Log_Pos: 1052908
               Relay_Log_File: xiao59-relay-bin.000002
                Relay_Log_Pos: 257
        Relay_Master_Log_File: blackhole-bin.000004
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: haha.%
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1052908
              Relay_Log_Space: 414
..............................................................
14.验证slave1&&slave2
slave1:
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| tuge               |
+--------------------+
mysql> select * from tuge.shiwei;
+----+-----------+
| id | name      |
+----+-----------+
|  1 | dazhima   |
|  2 | xiaozhima |
+----+-----------+
mysql> show create table tuge.shiwei;
+--------+-------------------------------------------------------------------------------------------------------------------------+
| Table  | Create Table                                                                                                            |
+--------+-------------------------------------------------------------------------------------------------------------------------+
| shiwei | CREATE TABLE `shiwei` (
  `id` int(11) NOT NULL,
  `name` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+--------+-------------------------------------------------------------------------------------------------------------------------+
slave2:
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| haha               |
| mysql              |
| performance_schema |
| test               |
+--------------------+
mysql> select * from haha.hehe;
+----+-----------+
| id | name      |
+----+-----------+
|  1 | dazhima   |
|  2 | xiaozhima |
|  1 | dazhima   |
|  2 | xiaozhima |
+----+-----------+
15.测试
master:
mysql> use tuge;
mysql> insert into shiwei values (3,'ni'),(4,'hao');
mysql> select * from shiwei;
+----+-----------+
| id | name      |
+----+-----------+
|  1 | dazhima   |
|  2 | xiaozhima |
|  3 | ni        |
|  4 | hao       |
+----+-----------+
mysql> use haha;
mysql> insert into hehe values (3,'ni'),(4,'hao');
mysql> select * from hehe;
+----+-----------+
| id | name      |
+----+-----------+
|  1 | dazhima   |
|  2 | xiaozhima |
|  1 | dazhima   |
|  2 | xiaozhima |
|  3 | ni        |
|  4 | hao       |
+----+-----------+
blackhole:
mysql> select * from tuge.shiwei;
Empty set (0.00 sec)

mysql> select * from haha.hehe;
Empty set (0.00 sec)
mysql> show create table haha.hehe;
+-------+--------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                             |
+-------+--------------------------------------------------------------------------------------------------------------------------+
| hehe  | CREATE TABLE `hehe` (
  `id` int(11) NOT NULL,
  `name` varchar(20) DEFAULT NULL
) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8 |
+-------+--------------------------------------------------------------------------------------------------------------------------+
slave1:
mysql> select * from tuge.shiwei;
+----+-----------+
| id | name      |
+----+-----------+
|  1 | dazhima   |
|  2 | xiaozhima |
|  3 | ni        |
|  4 | hao       |
+----+-----------+
slave2:
mysql> select * from haha.hehe;
+----+-----------+
| id | name      |
+----+-----------+
|  1 | dazhima   |
|  2 | xiaozhima |
|  1 | dazhima   |
|  2 | xiaozhima |
|  3 | ni        |
|  4 | hao       |
+----+-----------+
BlackHole 还可以用在以下场景
1.验证dump file语法的正确性
2.以使用blackhole引擎来检测binlog功能所需要的额外负载
3.由于blackhole性能损耗极小,可以用来检测除了存储引擎这个功能点之外的其他MySQL功能点的性能。


你可能感兴趣的:(BlackHole,分发,mss架构,单主到从到多从)