欢迎投稿

今日深度:

基于Docker搭建MySQL(MariaDB)+ mycat读写分离测试环境,dockermycat

基于Docker搭建MySQL(MariaDB)+ mycat读写分离测试环境,dockermycat


1. 手动创建mariadb镜像
    创建一个CentOS容器
        [yeqiang@localhost ~]$ docker run -it centos /bin/bash
    在容器中安装mariadb
        [root@8195a2bac40d /]# yum install mariadb mariadb-server -y
    编辑/etc/passwd允许mysql账户运行指令(方便)    
        修改
        mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
        为
        mysql:x:27:27:MariaDB Server:/var/lib/mysql:/bin/bash
    初始化数据库结构
        [root@8195a2bac40d /]# su -c mysql_install_db mysql
    测试数据库
        [root@8195a2bac40d /]# su -c mysqld_safe mysql &
        [1] 109
        [root@8195a2bac40d /]# 171226 06:11:00 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
        171226 06:11:00 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

        [root@8195a2bac40d /]# mysql -uroot
        Welcome to the MariaDB monitor.  Commands end with ; or \g.
        Your MariaDB connection id is 1
        Server version: 5.5.56-MariaDB MariaDB Server

        Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

        Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

        MariaDB [(none)]>
    为新安装的数据库root设置一个密码
        MariaDB [(none)]> use mysql
        Reading table information for completion of table and column names
        You can turn off this feature to get a quicker startup with -A

        Database changed
        MariaDB [mysql]> update user set password=password('hkNaruto');
        Query OK, 6 rows affected (0.00 sec)
        Rows matched: 6  Changed: 6  Warnings: 0

        MariaDB [mysql]> flush privileges;
        Query OK, 0 rows affected (0.00 sec)
    允许任意地址以root访问mysql(仅仅为了方便,线上禁止此操作!
        MariaDB [mysql]> grant all privileges on *.* to root@'%' identified by 'hkNaruto';
        Query OK, 0 rows affected (0.00 sec)

        MariaDB [mysql]> flush privileges;
        Query OK, 0 rows affected (0.00 sec)

        MariaDB [mysql]>

    清理垃圾
        [root@8195a2bac40d /]# yum clean all
        Loaded plugins: fastestmirror
        Cleaning repos: base extras updates
        Cleaning up everything
        Cleaning up list of fastest mirrors
    退出容器并提交到mairadb镜像
        [root@8195a2bac40d /]# exit
        [yeqiang@localhost ~]$ docker commit 8195 mariadb
        5d815e5ee022b8167dbed912c84e72bf5b24e9f4ab3430f1a4432f93aa61d582

2. 启动两个mariadb实力,做主从
    启动master实例
        [yeqiang@localhost ~]$ docker run -it --name=mariadb-master mariadb /bin/bash
        [root@043b24e25726 /]
    编辑/etc/my.cnf,设置server-id并打开二进制日志
        [root@043b24e25726 /]# vi /etc/my.cnf
        [mysqld]
        server-id=1
        log-bin=bin

    启动mariadb
        [root@043b24e25726 /]# su -c mysqld_safe mysql &
    连接到本地实例并创建复制账号
        [root@043b24e25726 /]# mysql -uroot -p
        Enter password:
        Welcome to the MariaDB monitor.  Commands end with ; or \g.
        Your MariaDB connection id is 5
        Server version: 5.5.56-MariaDB MariaDB Server

        Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

        Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

        MariaDB [(none)]> grant replication slave,reload,super on *.* to backup@'%' identified by 'backup';
        Query OK, 0 rows affected (0.00 sec)

        MariaDB [(none)]> flush privileges;
        Query OK, 0 rows affected (0.00 sec)

        MariaDB [(none)]> show master status;
        +------------+----------+--------------+------------------+
        | File       | Position | Binlog_Do_DB | Binlog_Ignore_DB |
        +------------+----------+--------------+------------------+
        | bin.000001 |      682 |              |                  |
        +------------+----------+--------------+------------------+
        1 row in set (0.00 sec)

        MariaDB [(none)]>
    启动slave实例
        [yeqiang@localhost ~]$ docker run -it --name=mariadb-slave --link=mariadb-master mariadb /bin/bash
        [root@f49bb64cd788 /]#
    编辑/etc/my.cnf,设置server-id、打开relay日志、设置只读
        [root@043b24e25726 /]# vi /etc/my.cnf
        [mysqld]
        server-id=2
        relay_log=relay
        read_only=1  
 
    启动mariadb
        [root@043b24e25726 /]# su -c mysqld_safe mysql &
    连接到本地实例并启动slave
        [root@f49bb64cd788 /]# mysql -uroot -p
        Enter password:
        Welcome to the MariaDB monitor.  Commands end with ; or \g.
        Your MariaDB connection id is 3
        Server version: 5.5.56-MariaDB MariaDB Server

        Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

        Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.        

        MariaDB [(none)]> change master to master_host='mariadb-master',master_user='backup',master_password='backup',master_log_file='bin.000001',master_log_pos=0;
        Query OK, 0 rows affected (0.01 sec)

        MariaDB [(none)]> start slave;
        Query OK, 0 rows affected (0.00 sec)

        MariaDB [(none)]> show slave status\G
        *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                  Master_Host: mariadb-master
                  Master_User: backup
                  Master_Port: 3306
                Connect_Retry: 60
                  Master_Log_File: bin.000001
              Read_Master_Log_Pos: 682
                   Relay_Log_File: relay.000002
                Relay_Log_Pos: 960
            Relay_Master_Log_File: bin.000001
                 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: 682
                  Relay_Log_Space: 1244
                  Until_Condition: None
                   Until_Log_File:
                Until_Log_Pos: 0
               Master_SSL_Allowed: No
               Master_SSL_CA_File:
               Master_SSL_CA_Path:
                  Master_SSL_Cert:
                Master_SSL_Cipher:
                   Master_SSL_Key:
            Seconds_Behind_Master: 0
        Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
                   Last_SQL_Errno: 0
                   Last_SQL_Error:
          Replicate_Ignore_Server_Ids:
                 Master_Server_Id: 1
        1 row in set (0.00 sec)

        MariaDB [(none)]>

3. 测试主从同步
    在主服务器创建一个测试数据库
        [root@043b24e25726 /]# mysql -uroot -p
        Enter password:
        Welcome to the MariaDB monitor.  Commands end with ; or \g.
        Your MariaDB connection id is 4
        Server version: 5.5.56-MariaDB MariaDB Server

        Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

        Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

        MariaDB [(none)]> show databases;
        +--------------------+
        | Database           |
        +--------------------+
        | information_schema |
        | mysql              |
        | performance_schema |
        | test               |
        +--------------------+
        4 rows in set (0.00 sec)

        MariaDB [(none)]> create database testdb;
        Query OK, 1 row affected (0.00 sec)

        MariaDB [testdb]> create table tt (  id int not null primary key auto_increment, c1 varchar(32) null ) engine=Innodb default charset=utf8;
        Query OK, 0 rows affected (0.00 sec)

        MariaDB [testdb]> insert into tt (c1)values('ttttt');
        Query OK, 1 row affected (0.00 sec)

        MariaDB [testdb]> select * from tt;
        +----+-------+
        | id | c1    |
        +----+-------+
        |  1 | ttttt |
        +----+-------+
        1 row in set (0.00 sec)

        MariaDB [testdb]>

    登录从服务器,查看数据库
        [root@f49bb64cd788 /]# mysql -uroot -p
        Enter password:
        Welcome to the MariaDB monitor.  Commands end with ; or \g.
        Your MariaDB connection id is 5
        Server version: 5.5.56-MariaDB MariaDB Server

        Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

        Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
        
        MariaDB [(none)]> show databases;
        +--------------------+
        | Database           |
        +--------------------+
        | information_schema |
        | mysql              |
        | performance_schema |
        | test               |
        | testdb             |
        +--------------------+
        5 rows in set (0.00 sec)

        MariaDB [(none)]> use testdb;
        Reading table information for completion of table and column names
        You can turn off this feature to get a quicker startup with -A

        Database changed
        MariaDB [testdb]> select * from tt;
        +----+-------+
        | id | c1    |
        +----+-------+
        |  1 | ttttt |
        +----+-------+
        1 row in set (0.00 sec)

        MariaDB [testdb]>


4. 手动创建一个mycat容器,测试读写分离
    [yeqiang@localhost ~]$  docker run -it  -p 8066:8066 -p 9066:9066 --link=mariadb-master --link=mariadb-slave centos /bin/bash
    [root@28188b8937da /]# yum install java -y
    [root@28188b8937da /]# curl -O http://dl.mycat.io/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
    [root@28188b8937da /]# tar -xvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
    配置mycat读写分离,一个writeHost,一个ReadHost,balance=3
        [root@28188b8937da /]# vi mycat/conf/schema.xml
        <?xml version="1.0"?>
        <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
        <mycat:schema xmlns:mycat="http://io.mycat/">

            <schema name="TESTDB1" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
            </schema>
            <dataNode name="dn1" dataHost="dh1" database="testdb" />
            <dataHost name="dh1" maxCon="1000" minCon="10" balance="3"
                      writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
                <heartbeat>select user()</heartbeat>
                <!-- can have multi write hosts -->
                <writeHost host="hostM1" url="mariadb-master:3306" user="root"
                           password="hkNaruto">
                    <!-- can have multi read hosts -->
                    <readHost host="hostS1" url="mariadb-slave:3306" user="root" password="hkNaruto" />
                </writeHost>
            </dataHost>
        </mycat:schema>
    配置访问mycat的用户名,密码及对应db(TESTDB1对应后端mysql的testdb)
        [root@28188b8937da /]# vi mycat/conf/server.xml    
        <?xml version="1.0" encoding="UTF-8"?>
        <!-- - - Licensed under the Apache License, Version 2.0 (the "License");
            - you may not use this file except in compliance with the License. - You
            may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0
            - - Unless required by applicable law or agreed to in writing, software -
            distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT
            WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the
            License for the specific language governing permissions and - limitations
            under the License. -->
        <!DOCTYPE mycat:server SYSTEM "server.dtd">
        <mycat:server xmlns:mycat="http://io.mycat/">
            <system>
            <property name="useSqlStat">0</property>  <!-- 1为开启实时统计、0为关闭 -->
            <property name="useGlobleTableCheck">0</property>  <!-- 1为开启全加班一致性检测、0为关闭 -->

                <property name="sequnceHandlerType">2</property>
                <!--默认为type 0: DirectByteBufferPool | type 1 ByteBufferArena-->
                <property name="processorBufferPoolType">0</property>
                <!--分布式事务开关,0为不过滤分布式事务,1为过滤分布式事务(如果分布式事务内只涉及全局表,则不过滤),2为不过滤分布式事务,但是记录分布式事务日志-->
                <property name="handleDistributedTransactions">0</property>
        
                    <!--
                    off heap for merge/order/group/limit      1开启   0关闭
                -->
                <property name="useOffHeapForMerge">1</property>

                <!--
                    单位为m
                -->
                <property name="memoryPageSize">1m</property>

                <!--
                    单位为k
                -->
                <property name="spillsFileBufferSize">1k</property>

                <property name="useStreamOutput">0</property>

                <!--
                    单位为m
                -->
                <property name="systemReserveMemorySize">384m</property>


                <!--是否采用zookeeper协调切换  -->
                <property name="useZKSwitch">true</property>


            </system>
    
            <user name="root">
                <property name="password">123456</property>
                <property name="schemas">TESTDB1</property>
            </user>
        </mycat:server>
    配置日志级别为debug(为观察读写分离细节,生产环境应当调整到info以上级别)
        [root@28188b8937da /]# vi mycat/conf/log4j2.xml
             <asyncRoot level="debug" includeLocation="true">

                <AppenderRef ref="Console" />
                <AppenderRef ref="RollingFile"/>

            </asyncRoot>
    启动mycat
        [root@28188b8937da /]# /mycat/bin/mycat  console
        Running Mycat-server...

        略。。。

        jvm 1    | 2017-12-26 08:03:28,586 [DEBUG][Timer0] con query sql:select user() to con:MySQLConnection [id=8, lastTime=1514275408586, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=42, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=mariadb-master, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.sqlengine.SQLJob:SQLJob.java:88)
        jvm 1    | 2017-12-26 08:03:28,587 [DEBUG][Timer0] con query sql:select user() to con:MySQLConnection [id=14, lastTime=1514275408587, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=true, threadId=32, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=mariadb-slave, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.sqlengine.SQLJob:SQLJob.java:88)
        jvm 1    | 2017-12-26 08:03:28,587 [DEBUG][$_NIOREACTOR-0-RW] release channel MySQLConnection [id=8, lastTime=1514275408586, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=42, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=mariadb-master, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:442)
        jvm 1    | 2017-12-26 08:03:28,587 [DEBUG][$_NIOREACTOR-2-RW] release channel MySQLConnection [id=14, lastTime=1514275408586, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=true, threadId=32, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=mariadb-slave, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:442)
    
5. 测试读写分离
    在宿主服务器上(docker外面)启动mysql客户端
        [yeqiang@localhost ~]$ mysql -uroot -p123456 -h127.0.0.1 -P8066 TESTDB1
        mysql: [Warning] Using a password on the command line interface can be insecure.
        Reading table information for completion of table and column names
        You can turn off this feature to get a quicker startup with -A

        Welcome to the MySQL monitor.  Commands end with ; or \g.
        Your MySQL connection id is 2
        Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB)

        Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

        Oracle is a registered trademark of Oracle Corporation and/or its
        affiliates. Other names may be trademarks of their respective
        owners.

        Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

        mysql> show tables;
        +------------------+
        | Tables_in_testdb |
        +------------------+
        | tt               |
        +------------------+
        1 row in set (0.00 sec)

        mysql>

    插入一条数据
        mysql> insert into tt(c1)values('asdf');
        Query OK, 1 row affected (0.01 sec)

        mysql>
        
    此时mycat有日志显示如下
        jvm 1    | 2017-12-26 08:07:22,678 [DEBUG][$_NIOREACTOR-0-RW] ServerConnection [id=2, schema=TESTDB1, host=172.17.42.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB1] insert into tt(c1)values('asdf')  (io.mycat.net.FrontendConnection:FrontendConnection.java:288)
        jvm 1    | 2017-12-26 08:07:22,678 [DEBUG][$_NIOREACTOR-0-RW] ServerConnection [id=2, schema=TESTDB1, host=172.17.42.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB1]insert into tt(c1)values('asdf')  (io.mycat.server.ServerQueryHandler:ServerQueryHandler.java:57)
        jvm 1    | 2017-12-26 08:07:22,678 [DEBUG][$_NIOREACTOR-0-RW] ServerConnection [id=2, schema=TESTDB1, host=172.17.42.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB1]insert into tt(c1)values('asdf'), route={
        jvm 1    |    1 -> dn1{insert into tt(c1)values('asdf')}
        jvm 1    | } rrs   (io.mycat.server.NonBlockingSession:NonBlockingSession.java:110)
        jvm 1    | 2017-12-26 08:07:22,678 [DEBUG][$_NIOREACTOR-0-RW] rrs.getRunOnSlave() null  (io.mycat.backend.mysql.nio.handler.SingleNodeHandler:SingleNodeHandler.java:166)
        jvm 1    | 2017-12-26 08:07:22,678 [DEBUG][$_NIOREACTOR-0-RW] node.getRunOnSlave() null  (io.mycat.backend.mysql.nio.handler.SingleNodeHandler:SingleNodeHandler.java:168)
        jvm 1    | 2017-12-26 08:07:22,678 [DEBUG][$_NIOREACTOR-0-RW] node.getRunOnSlave() null  (io.mycat.backend.mysql.nio.handler.SingleNodeHandler:SingleNodeHandler.java:177)
        jvm 1    | 2017-12-26 08:07:22,678 [DEBUG][$_NIOREACTOR-0-RW] node.getRunOnSlave() null  (io.mycat.backend.mysql.nio.handler.SingleNodeHandler:SingleNodeHandler.java:179)
        jvm 1    | 2017-12-26 08:07:22,678 [DEBUG][$_NIOREACTOR-0-RW] rrs.getRunOnSlave() null  (io.mycat.backend.datasource.PhysicalDBNode:PhysicalDBNode.java:96)
        jvm 1    | 2017-12-26 08:07:22,678 [DEBUG][$_NIOREACTOR-0-RW] rrs.getRunOnSlave() null  (io.mycat.backend.datasource.PhysicalDBNode:PhysicalDBNode.java:127)
        jvm 1    | 2017-12-26 08:07:22,678 [DEBUG][$_NIOREACTOR-0-RW] con need syn ,total syn cmd 1 commands SET names utf8;schema change:false con:MySQLConnection [id=3, lastTime=1514275642678, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=48, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{insert into tt(c1)values('asdf')}, respHandler=SingleNodeHandler [node=dn1{insert into tt(c1)values('asdf')}, packetId=0], host=mariadb-master, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=true]  (io.mycat.backend.mysql.nio.MySQLConnection:MySQLConnection.java:448)
        jvm 1    | 2017-12-26 08:07:22,683 [DEBUG][$_NIOREACTOR-3-RW] release connection MySQLConnection [id=3, lastTime=1514275642666, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=48, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{insert into tt(c1)values('asdf')}, respHandler=SingleNodeHandler [node=dn1{insert into tt(c1)values('asdf')}, packetId=1], host=mariadb-master, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=true]  (io.mycat.server.NonBlockingSession:NonBlockingSession.java:341)
        jvm 1    | 2017-12-26 08:07:22,683 [DEBUG][$_NIOREACTOR-3-RW] release channel MySQLConnection [id=3, lastTime=1514275642666, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=48, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=mariadb-master, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:442)
            其中 [id=3, lastTime=1514275642678, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=false, threadId=48, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{insert into tt(c1)values('asdf')}, respHandler=SingleNodeHandler [node=dn1{insert into tt(c1)values('asdf')}, packetId=0], host=mariadb-master, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=true] 说明insert指令路由到了mariadb-master节点上

            读取数据
                mysql> select * from tt;
                +----+-------+
                | id | c1    |
                +----+-------+
                |  1 | ttttt |
                |  2 | asdf  |
                +----+-------+
                2 rows in set (0.00 sec)

                mysql>
            此时mycat有日志显示如下

        jvm 1    | 2017-12-26 08:33:23,413 [DEBUG][$_NIOREACTOR-0-RW] ServerConnection [id=2, schema=TESTDB1, host=172.17.42.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB1] select * from tt  (io.mycat.net.FrontendConnection:FrontendConnection.java:288)
        jvm 1    | 2017-12-26 08:33:23,413 [DEBUG][$_NIOREACTOR-0-RW] ServerConnection [id=2, schema=TESTDB1, host=172.17.42.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB1]select * from tt  (io.mycat.server.ServerQueryHandler:ServerQueryHandler.java:57)
        jvm 1    | 2017-12-26 08:33:23,413 [DEBUG][$_NIOREACTOR-0-RW] SQLRouteCache  miss cache ,key:TESTDB1select * from tt  (io.mycat.cache.impl.EnchachePool:EnchachePool.java:77)
        jvm 1    | 2017-12-26 08:33:23,413 [DEBUG][$_NIOREACTOR-0-RW] ServerConnection [id=2, schema=TESTDB1, host=172.17.42.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB1]select * from tt, route={
        jvm 1    |    1 -> dn1{select * from tt}
        jvm 1    | } rrs   (io.mycat.server.NonBlockingSession:NonBlockingSession.java:110)
        jvm 1    | 2017-12-26 08:33:23,413 [DEBUG][$_NIOREACTOR-0-RW] rrs.getRunOnSlave() null  (io.mycat.backend.mysql.nio.handler.SingleNodeHandler:SingleNodeHandler.java:166)
        jvm 1    | 2017-12-26 08:33:23,413 [DEBUG][$_NIOREACTOR-0-RW] node.getRunOnSlave() null  (io.mycat.backend.mysql.nio.handler.SingleNodeHandler:SingleNodeHandler.java:168)
        jvm 1    | 2017-12-26 08:33:23,413 [DEBUG][$_NIOREACTOR-0-RW] node.getRunOnSlave() null  (io.mycat.backend.mysql.nio.handler.SingleNodeHandler:SingleNodeHandler.java:177)
        jvm 1    | 2017-12-26 08:33:23,413 [DEBUG][$_NIOREACTOR-0-RW] node.getRunOnSlave() null  (io.mycat.backend.mysql.nio.handler.SingleNodeHandler:SingleNodeHandler.java:179)
        jvm 1    | 2017-12-26 08:33:23,413 [DEBUG][$_NIOREACTOR-0-RW] rrs.getRunOnSlave() null  (io.mycat.backend.datasource.PhysicalDBNode:PhysicalDBNode.java:96)
        jvm 1    | 2017-12-26 08:33:23,413 [DEBUG][$_NIOREACTOR-0-RW] rrs.getRunOnSlave() null  (io.mycat.backend.datasource.PhysicalDBNode:PhysicalDBNode.java:127)
        jvm 1    | 2017-12-26 08:33:23,413 [DEBUG][$_NIOREACTOR-0-RW] select read source hostS1 for dataHost:dh1  (io.mycat.backend.datasource.PhysicalDBPool:PhysicalDBPool.java:456)
        jvm 1    | 2017-12-26 08:33:23,413 [DEBUG][$_NIOREACTOR-0-RW] con need syn ,total syn cmd 1 commands SET names utf8;schema change:false con:MySQLConnection [id=12, lastTime=1514277203413, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=true, threadId=31, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{select * from tt}, respHandler=SingleNodeHandler [node=dn1{select * from tt}, packetId=0], host=mariadb-slave, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.mysql.nio.MySQLConnection:MySQLConnection.java:448)
        jvm 1    | 2017-12-26 08:33:23,414 [DEBUG][$_NIOREACTOR-0-RW] release connection MySQLConnection [id=12, lastTime=1514277203406, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=true, threadId=31, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{select * from tt}, respHandler=SingleNodeHandler [node=dn1{select * from tt}, packetId=6], host=mariadb-slave, port=3306, statusSync=io.mycat.backend.mysql.nio.MySQLConnection$StatusSync@4118276c, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.server.NonBlockingSession:NonBlockingSession.java:341)
        jvm 1    | 2017-12-26 08:33:23,414 [DEBUG][$_NIOREACTOR-0-RW] release channel MySQLConnection [id=12, lastTime=1514277203406, user=root, schema=testdb, old shema=testdb, borrowed=true, fromSlaveDB=true, threadId=31, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=mariadb-slave, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]  (io.mycat.backend.datasource.PhysicalDatasource:PhysicalDatasource.java:442)
    其中[node=dn1{select * from tt}, packetId=0], host=mariadb-slave, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]说明select指令被路由到了mariadb-slave节点上

www.htsjk.Com true http://www.htsjk.com/mariadb/27657.html NewsArticle 基于Docker搭建MySQL(MariaDB)+ mycat读写分离测试环境,dockermycat 1. 手动创建mariadb镜像     创建一个CentOS容器         [yeqiang@localhost ~]$ docker run -it centos /bin/bash     在容器中安装mar...
相关文章
    暂无相关文章
评论暂时关闭