一、认识读写分离

  1. 读写分离概念
    读写分离,基本的原理是让主数据库处理事务性增、改、删操作(INSERT、UPDATE、DELETE),而从数据库处理SELECT查询操作。数据库复制被用来把事务性操作导致的变更同步到集群中的从数据库。
  2. 读写分离的作用
    因为数据库的“写”(写100,00条数据到MySQL可能要3分钟)操作是比较耗时的,但是数据库的“读”(从MySQL读100,00条数据可能只要5秒钟)。所以读写分离可以解决数据库写入时影响查询效率的问题。
  3. 读写分离应用场景
    数据库不一定总要读写分离,如果程序使用数据库较多、更新较少、查询较多的情况下会考虑使用。利用数据库主从同步,可以减少数据库压力,提高性能。当然,数据库也有其它优化方案。例如使用memcache、分表、搜索引擎等方法。
  4. 主从复制、读写分离的基本设计
    在实际的生产环境中,对数据库的读和写都在同一个数据库服务器中,是不能满足实际需求的。无论是在安全性、高可用性还是高并发等各个方面都是完全不能满足实际需求的。因此,通过主从复制的方式来同步数据,再通过一台主、多台从节点,主节点提供写操作,从节点提供读操作来实现读写分离,从而提升数据库的并发负载能力。

规划节点

使用Mycat作为数据库中间件服务构建读写分离的数据库集群

IP 主机名 节点
192.168.100.10 mycat Mycat中间件服务节点
192.168.100.20 db1 MariaDB数据库集群主节点
192.168.100.30 db2 MariaDB数据库集群从节点

基础准备

使用CentOS 7.2系统,flavor使用2vCPU/4G内存/50G硬盘,创建3台虚拟机进行实验。
其中2台虚拟机db1和db2部署MariaDB数据库服务,搭建主从数据库集群;一台作为主节点,负责写入数据库信息;另一台作为从节点,负责读取数据库信息。
使用一台虚拟机部署Mycat数据库中间件服务,将用户提交的读写操作识别分发给相应的数据库节点。这样将用户的访问操作、数据库的读与写操作分给3台主机,只有数据库集群的主节点接收增、删、改SQL语句,从节点接收查询语句,分担了主节点的查询压力。
Yum源使用提供的gpmall-repo文件夹作为本地源,Mycat组件使用提供的Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz压缩包安装。

二、实施过程

1. 基础环境配置

(1)修改主机名

  1. 使用hostnamectl命令修改3台主机的主机名。
  2. Mycat节点修改主机名命令:
  3. [root@localhost ~]# hostnamectl set-hostname mycat
  4. [root@localhost ~]# bash
  5. [root@mycat ~]#
  6. db1节点修改主机名命令:
  7. [root@localhost ~]# hostnamectl set-hostname db1
  8. [root@localhost ~]# bash
  9. [root@db1 ~]#
  10. db2节点修改主机名命令:
  11. [root@localhost ~]# hostnamectl set-hostname db2
  12. [root@localhost ~]# bash
  13. [root@db2 ~]#

(2)编辑hosts文件

  1. 3台集群虚拟机的/etc/hosts文件配置部分:
  2. [root@mycat ~]# cat /etc/hosts
  3. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  4. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  5. 192.168.100.10 mycat
  6. 192.168.100.20 db1
  7. 192.168.100.30 db2

(3)配置Yum安装源

数据库集群需要安装MariaDB数据库服务,需要给集群虚拟机配置Yum安装源文件,使用提供的gpmall-repo文件上传至3个虚拟机的/opt目录下,设置本地Yum源。
首先将3个节点/etc/yum.repo.d目录下的文件移动到/media下,命令如下:

  1. [root@mycat ~]# mv /etc/yum.repos.d/* /media/

3台集群虚拟机的Yum安装源文件配置部分:

  1. [root@mycat ~]# cat /etc/yum.repos.d/local.repo
  2. [mariadb]
  3. name=mariadb
  4. baseurl=file:///opt/gpmall-repo
  5. gpgcheck=0
  6. enabled=1
  7. [root@mycat ~]#

(4)安装JDK环境

部署Mycat中间件服务需要先部署JDK 1.7或以上版本的JDK软件环境,这里部署JDK 1.8版本。
Mycat节点安装Java环境:

  1. [root@mycat ~]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
  2. [root@mycat ~]# java -version
  3. openjdk version "1.8.0_302"
  4. OpenJDK Runtime Environment (build 1.8.0_302-b08)
  5. OpenJDK 64-Bit Server VM (build 25.302-b08, mixed mode)
  6. [root@mycat ~]#

(5)关闭防火墙(全部节点)

  1. [root@mycat ~]# systemctl stop firewalld
  2. [root@mycat ~]# systemctl disable firewalld
  3. [root@mycat ~]# systemctl status firewalld
  4. firewalld.service - firewalld - dynamic firewall daemon
  5. Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
  6. Active: inactive (dead)
  7. Docs: man:firewalld(1)
  8. [root@mycat ~]#

2. 部署MariaDB主从数据库集群服务

(1)安装MariaDB服务

通过YUM命令在db1和db2虚拟机节点上安装MariaDB服务,命令如下:

  1. [root@db1 ~]# yum install -y mariadb mariadb-server

2个节点启动MariaDB服务,并设置MariaDB服务为开机自启。

  1. [root@db1 ~]# systemctl start mariadb
  2. [root@db1 ~]# systemctl enable mariadb
  3. Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
  4. [root@db1 ~]#

(2)初始化MariaDB数据库

在db1和db2虚拟机节点上初始化MariaDB数据库,并设置MariaDB数据库root访问用户的密码为123456。

  1. [root@db1 ~]# mysql_secure_installation
  2. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  3. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  4. In order to log into MariaDB to secure it, we'll need the current
  5. password for the root user. If you've just installed MariaDB, and
  6. you haven't set the root password yet, the password will be blank,
  7. so you should just press enter here.
  8. Enter current password for root (enter for none): //默认按回车
  9. OK, successfully used password, moving on...
  10. Setting the root password ensures that nobody can log into the MariaDB
  11. root user without the proper authorisation.
  12. Set root password? [Y/n] y
  13. New password: //输入root密码 123456
  14. Re-enter new password: //再次输入123456
  15. Password updated successfully!
  16. Reloading privilege tables..
  17. ... Success!
  18. By default, a MariaDB installation has an anonymous user, allowing anyone
  19. to log into MariaDB without having to have a user account created for
  20. them. This is intended only for testing, and to make the installation
  21. go a bit smoother. You should remove them before moving into a
  22. production environment.
  23. Remove anonymous users? [Y/n] y
  24. ... Success!
  25. Normally, root should only be allowed to connect from 'localhost'. This
  26. ensures that someone cannot guess at the root password from the network.
  27. Disallow root login remotely? [Y/n] n
  28. ... skipping.
  29. By default, MariaDB comes with a database named 'test' that anyone can
  30. access. This is also intended only for testing, and should be removed
  31. before moving into a production environment.
  32. Remove test database and access to it? [Y/n] y
  33. - Dropping test database...
  34. ... Success!
  35. - Removing privileges on test database...
  36. ... Success!
  37. Reloading the privilege tables will ensure that all changes made so far
  38. will take effect immediately.
  39. Reload privilege tables now? [Y/n] y
  40. ... Success!
  41. Cleaning up...
  42. All done! If you've completed all of the above steps, your MariaDB
  43. installation should now be secure.
  44. Thanks for using MariaDB!
  45. [root@db1 ~]#

(3)配置数据库集群主节点

编辑主节点db1虚拟机的数据库配置文件my.cnf,在配置文件my.cnf中增添下面的内容:

  1. [root@db1 ~]# cat /etc/my.cnf
  2. [mysqld]
  3. log_bin = mysql-bin #记录操作日志
  4. binlog_ignore_db = mysql #不同步MySQL系统数据库
  5. server_id = 18 #数据库集群中的每个节点id都要不同,一般使用IP地址的最后 段的数字,例如172.16.51.18,server_id就写18
  6. datadir=/var/lib/mysql
  7. socket=/var/lib/mysql/mysql.sock
  8. # Disabling symbolic-links is recommended to prevent assorted security risks
  9. symbolic-links=0
  10. [mysqld_safe]
  11. log-error=/var/log/mariadb/mariadb.log
  12. pid-file=/var/run/mariadb/mariadb.pid
  1. db2 配置内容
  2. [root@db2 ~]# cat /etc/my.cnf
  3. [mysqld]
  4. log_bin = mysql-bin
  5. binlog_ignore_db = mysql
  6. server_id = 19
  7. datadir=/var/lib/mysql
  8. socket=/var/lib/mysql/mysql.sock
  9. # Disabling symbolic-links is recommended to prevent assorted security risks
  10. symbolic-links=0
  11. # Settings user and group are ignored when systemd is used.
  12. # If you need to run mysqld under a different user or group,
  13. # customize your systemd unit file for mariadb according to the
  14. # instructions in http://fedoraproject.org/wiki/Systemd
  15. [mysqld_safe]
  16. log-error=/var/log/mariadb/mariadb.log
  17. pid-file=/var/run/mariadb/mariadb.pid
  18. #
  19. # include all files from the config directory
  20. #
  21. !includedir /etc/my.cnf.d
  22. [root@db2 ~]#
  23. 注意:sercer_id不能相同

编辑完成配置文件my.cnf后,重启MariaDB服务。

  1. [root@db1 ~]# systemctl restart mariadb

(4)开放主节点的数据库权限

在主节点db1虚拟机上使用mysql命令登录MariaDB数据库,授权在任何客户端机器上可以以root用户登录到数据库。

  1. [root@db1 ~]# mysql -uroot -p123456
  2. Welcome to the MariaDB monitor. Commands end with ; or \g.
  3. Your MariaDB connection id is 2
  4. Server version: 5.5.68-MariaDB MariaDB Server
  5. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  7. MariaDB [(none)]>
  8. MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by "123456";
  9. Query OK, 0 rows affected (0.00 sec)
  10. MariaDB [(none)]>

在主节点db1数据库上创建一个user用户让从节点db2连接,并赋予从节点同步主节点数据库的权限,命令如下:

  1. MariaDB [(none)]> grant replication slave on *.* to 'user'@'db2' identified by '123456';
  2. Query OK, 0 rows affected (0.00 sec)
  3. MariaDB [(none)]>

(5)配置从节点db2同步主节点db1

在从节点db2虚拟机上使用mysql命令登录MariaDB数据库,配置从节点连接主节点的连接信息。master_host为主节点主机名db1,master_user为在步骤(4)中创建的用户user,命令如下:

  1. [root@db2 ~]# mysql -uroot -p123456
  2. Welcome to the MariaDB monitor. Commands end with ; or \g.
  3. Your MariaDB connection id is 2
  4. Server version: 5.5.68-MariaDB MariaDB Server
  5. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  7. MariaDB [(none)]> change master to master_host='db1',master_user='user',master_password='123456';
  8. Query OK, 0 rows affected (0.00 sec)
  9. MariaDB [(none)]>

配置完毕主从数据库之间的连接信息之后,开启从节点服务。使用show slave status\G; 命令并查看从节点服务状态,如果Slave_IO_Running和Slave_SQL_Running的状态都为YES,则从节点服务开启成功。

  1. MariaDB [(none)]> start slave;
  2. Query OK, 0 rows affected (0.00 sec)
  3. MariaDB [(none)]> show slave status\G;
  4. *************************** 1. row ***************************
  5. Slave_IO_State: Waiting for master to send event
  6. Master_Host: db1
  7. Master_User: user
  8. Master_Port: 3306
  9. Connect_Retry: 60
  10. Master_Log_File: mysql-bin.000001
  11. Read_Master_Log_Pos: 527
  12. Relay_Log_File: mariadb-relay-bin.000002
  13. Relay_Log_Pos: 811
  14. Relay_Master_Log_File: mysql-bin.000001
  15. Slave_IO_Running: Yes
  16. Slave_SQL_Running: Yes
  17. Replicate_Do_DB:
  18. Replicate_Ignore_DB:
  19. Replicate_Do_Table:
  20. Replicate_Ignore_Table:
  21. Replicate_Wild_Do_Table:
  22. Replicate_Wild_Ignore_Table:
  23. Last_Errno: 0
  24. Last_Error:
  25. Skip_Counter: 0
  26. Exec_Master_Log_Pos: 527
  27. Relay_Log_Space: 1107
  28. Until_Condition: None
  29. Until_Log_File:
  30. Until_Log_Pos: 0
  31. Master_SSL_Allowed: No
  32. Master_SSL_CA_File:
  33. Master_SSL_CA_Path:
  34. Master_SSL_Cert:
  35. Master_SSL_Cipher:
  36. Master_SSL_Key:
  37. Seconds_Behind_Master: 0
  38. Master_SSL_Verify_Server_Cert: No
  39. Last_IO_Errno: 0
  40. Last_IO_Error:
  41. Last_SQL_Errno: 0
  42. Last_SQL_Error:
  43. Replicate_Ignore_Server_Ids:
  44. Master_Server_Id: 18
  45. 1 row in set (0.00 sec)
  46. ERROR: No query specified
  47. MariaDB [(none)]>

(6)验证主从数据库的同步功能

先在主节点db1的数据库中创建库test,并在库test中创建表company,插入表数据。创建完成后,查看表company数据,如下所示:

  1. MariaDB [(none)]> create database test;
  2. Query OK, 1 row affected (0.00 sec)
  3. MariaDB [(none)]> use test
  4. Database changed
  5. MariaDB [test]> create table company(id int not null primary key,name varchar(50),addr varchar(255));
  6. Query OK, 0 rows affected (0.00 sec)
  7. MariaDB [test]> insert into company values(1,"facebook","usa");
  8. Query OK, 1 row affected (0.00 sec)
  9. MariaDB [test]> select * from company;
  10. +----+----------+------+
  11. | id | name | addr |
  12. +----+----------+------+
  13. | 1 | facebook | usa |
  14. +----+----------+------+
  15. 1 row in set (0.00 sec)
  16. MariaDB [test]>

这时从节点db2的数据库就会同步主节点数据库创建的test库,可以在从节点查询test数据库与表company,如果可以查询到信息,就能验证主从数据库集群功能在正常运行。查询结果如下所示:

  1. MariaDB [(none)]> show databases;
  2. +--------------------+
  3. | Database |
  4. +--------------------+
  5. | information_schema |
  6. | mysql |
  7. | performance_schema |
  8. | test |
  9. +--------------------+
  10. 4 rows in set (0.00 sec)
  11. MariaDB [(none)]> select * from test.company;
  12. +----+----------+------+
  13. | id | name | addr |
  14. +----+----------+------+
  15. | 1 | facebook | usa |
  16. +----+----------+------+
  17. 1 row in set (0.00 sec)
  18. MariaDB [(none)]>

3. 部署Mycat读写分离中间件服务

(1)安装Mycat服务

将Mycat服务的二进制软件包Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz上传到Mycat虚拟机的/root目录下,并将软件包解压到/use/local目录中。赋予解压后的Mycat目录权限。

  1. [root@mycat ~]# tar -zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -C /usr/local/
  2. [root@mycat ~]# chmod -R 777 /usr/local/mycat/

在/etc/profile系统变量文件中添加Mycat服务的系统变量,并生效变量。

  1. [root@mycat ~]# echo export MYCAT_HOME=/usr/local/mycat/ >> /etc/profile
  2. [root@mycat ~]# source /etc/profile

(2)编辑Mycat的逻辑库配置文件

配置Mycat服务读写分离的schema.xml配置文件在/usr/local/mycat/conf/目录下,可以在文件中定义一个逻辑库,使用户可以通过Mycat服务管理该逻辑库对应的MariaDB数据库。在这里定义一个逻辑库schema,name为USERDB;该逻辑库USERDB对应数据库database为test(在部署主从数据库时已安装);设置数据库写入节点为主节点db1;设置数据库读取节点为从节点db2。(可以直接删除原来schema.xml的内容,替换为如下。)
注意:IP需要修改成实际的IP地址。

  1. [root@mycat ~]# vim /usr/local/mycat/conf/schema.xml
  2. <?xml version="1.0"?>
  3. <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
  4. <mycat:schema xmlns:mycat="http://io.mycat/">
  5. <schema name="USERDB" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn1"></
  6. schema>
  7. <dataNode name="dn1" dataHost="localhost1" database="test" />
  8. <dataHost name="localhost1" maxCon="1000" minCon="10" balance="3" dbType="mysql
  9. " dbDriver="native" writeType="0" switchType="1" slaveThreshold="100">
  10. <heartbeat>select user()</heartbeat>
  11. <writeHost host="hostM1" url="192.168.100.10:3306" user="root" password="1234
  12. 56">
  13. <readHost host="hostS1" url="192.168.100.20:3306" user="root" password="1
  14. 23456" />
  15. </writeHost>
  16. </dataHost>
  17. </mycat:schema>

代码说明:
sqlMaxLimit:配置默认查询数量。
database:为真实数据库名。
balance=”0”:不开启读写分离机制,所有读操作都发送到当前可用的writeHost上。
balance=”1”:全部的readHost与stand by writeHost参与select语句的负载均衡,简单来说,当双主双从模式(M1->S1,M2->S2,并且M1与M2互为主备),正常情况下,M2、S1、S2都参与select语句的负载均衡。
balance=”2”:所有读操作都随机的在writeHost、readhost上分发。
balance=”3”:所有读请求随机地分发到wiriterHost对应的readhost执行,writerHost不负担读压力,注意balance=3只在1.4及其以后版本有,1.3版本没有。
writeType=”0”:所有写操作发送到配置的第一个writeHost,第一个挂了需要切换到还生存的第二个writeHost,重新启动后已切换后的为准,切换记录在配置文件dnindex.properties中。
writeType=”1”:所有写操作都随机的发送到配置的writeHost。

(3)修改配置文件权限

修改schema.xml的用户权限,命令如下:

  1. [root@mycat ~]# chown root:root /usr/local/mycat/conf/schema.xml

(4)编辑mycat的访问用户

修改/usr/local/mycat/conf/目录下的server.xml文件,修改root用户的访问密码与数据库,密码设置为123456,访问Mycat的逻辑库为USERDB,命令如下:

  1. [root@mycat ~]# vim /usr/local/mycat/conf/server.xml
  2. 在配置文件的最后部分添加,
  3. <user name="root">
  4. <property name="password">123456</property>
  5. <property name="schemas">USERDB</property>
  6. </user>
  7. 然后删除如下几行:
  8. <user name="user">
  9. <property name="password">user</property>
  10. <property name="schemas">TESTDB</property>
  11. <property name="readOnly">true</property>
  12. </user>

保存并退出server.xml配置文件。

(5)启动Mycat服务

通过命令启动Mycat数据库中间件服务,启动后使用netstat -ntpl命令查看虚拟机端口开放情况,如果有开放8066和9066端口,则表示Mycat服务开启成功。端口查询情况如下所示。

  1. [root@mycat mycat]# /bin/bash /usr/local/mycat/bin/mycat start
  2. Starting Mycat-server...
  3. [root@mycat mycat]# netstat -ntlp
  4. Active Internet connections (only servers)
  5. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  6. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 943/sshd
  7. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1181/master
  8. tcp 0 0 127.0.0.1:32000 0.0.0.0:* LISTEN 12942/java
  9. tcp6 0 0 :::8066 :::* LISTEN 12942/java
  10. tcp6 0 0 :::9066 :::* LISTEN 12942/java
  11. tcp6 0 0 :::36111 :::* LISTEN 12942/java
  12. tcp6 0 0 :::45072 :::* LISTEN 12942/java
  13. tcp6 0 0 :::22 :::* LISTEN 943/sshd
  14. tcp6 0 0 ::1:25 :::* LISTEN 1181/master
  15. tcp6 0 0 :::1984 :::* LISTEN 12942/java
  16. [root@mycat mycat]#

4. 验证数据库集群服务读写分离功能

(1)用Mycat服务查询数据库信息

先在Mycat虚拟机上使用Yum安装mariadb-client服务。

  1. [root@mycat ~]# yum install -y MariaDB-client

在Mycat虚拟机上使用mysql命令查看Mycat服务的逻辑库USERDB,因为Mycat的逻辑库USERDB对应数据库test(在部署主从数据库时已安装),所以可以查看库中已经创建的表company。命令如下。

  1. [root@mycat ~]# mysql -h127.0.0.1 -P8066 -uroot -p123456
  2. Welcome to the MariaDB monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 1
  4. Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB)
  5. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  7. MySQL [(none)]> show databases;
  8. +----------+
  9. | DATABASE |
  10. +----------+
  11. | USERDB |
  12. +----------+
  13. 1 row in set (0.002 sec)
  14. MySQL [(none)]> use USERDB
  15. Reading table information for completion of table and column names
  16. You can turn off this feature to get a quicker startup with -A
  17. Database changed
  18. MySQL [USERDB]> show tables;
  19. +----------------+
  20. | Tables_in_test |
  21. +----------------+
  22. | company |
  23. +----------------+
  24. 1 row in set (0.006 sec)
  25. MySQL [USERDB]>
  26. MySQL [USERDB]> select * from company;
  27. +----+------------+------+
  28. | id | name | addr |
  29. +----+------------+------+
  30. | 1 | facebook | usa |
  31. | 2 | bastetball | usa |
  32. +----+------------+------+
  33. 2 rows in set (0.046 sec)
  34. MySQL [USERDB]>

(2)用Mycat服务添加表数据

在Mycat虚拟机上使用mysql命令对表company添加一条数据(2,”basketball”,”usa”),添加完毕后查看表信息。命令如下。

  1. MySQL [USERDB]> insert into company values(2,"bastetball","usa");
  2. Query OK, 1 row affected (0.050 sec)
  3. MySQL [USERDB]> select * from company;
  4. +----+------------+------+
  5. | id | name | addr |
  6. +----+------------+------+
  7. | 1 | facebook | usa |
  8. | 2 | bastetball | usa |
  9. +----+------------+------+
  10. 2 rows in set (0.001 sec)
  11. MySQL [USERDB]>

(3)验证Mycat服务对数据库读写操作分离

在Mycat虚拟机节点使用mysql命令,通过9066端口查询对数据库读写操作的分离信息。可以看到所有的写入操作WRITE_LOAD数都在db1主数据库节点上,所有的读取操作READ_LOAD数都在db2主数据库节点上。由此可见,数据库读写操作已经分离到db1和db2节点上了。命令如下。

  1. [root@mycat ~]# mysql -h127.0.0.1 -P9066 -uroot -p123456 -e 'show @@datasource;'
  2. +----------+--------+-------+----------------+------+------+--------+------+------+---------+-----------+------------+
  3. | DATANODE | NAME | TYPE | HOST | PORT | W/R | ACTIVE | IDLE | SIZE | EXECUTE | READ_LOAD | WRITE_LOAD |
  4. +----------+--------+-------+----------------+------+------+--------+------+------+---------+-----------+------------+
  5. | dn1 | hostM1 | mysql | 192.168.100.20 | 3306 | W | 0 | 8 | 1000 | 360 | 0 | 1 |
  6. | dn1 | hostS1 | mysql | 192.168.100.30 | 3306 | R | 0 | 8 | 1000 | 364 | 12 | 0 |
  7. +----------+--------+-------+----------------+------+------+--------+------+------+---------+-----------+------------+
  8. [root@mycat ~]#

至此,Mycat读写分离数据库案例完成。