mycat separate read and write, load balancing, high availability

1. Configure mycat

1.1 Configuring server.xml

Description: This file defines the user while the main current user can define which database access.

<?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="nonePasswordLogin">0</property> <!-- 0为需要密码登陆、1为不需要密码登陆 ,默认为0-->
    <property name="useHandshakeV10 " > 1 </ Property> 
    <Property name = " useSqlStat " > 0 </ Property> <-! 1 to open real-time statistics, 0 is off -> 
    <Property name = " useGlobleTableCheck " > 0 </ Property> <! - 1 is turned on full coincidence detection overtime, 0 is off -> 

        <Property name = " sequnceHandlerType " > 2 </ Property> 
      <! - <Property name = " UseCompression " > 1 </ Property> - -> <! - 1 mysql open compression protocol -> 
        <! - <property name="fakeMySQLVersion">5.6.20</property>--> <!--设置模拟的MySQL版本号-->
    <!-- <property name="processorBufferChunk">40960</property> -->
    <!-- 
    <property name="processors">1</property> 
    <property name="processorExecutor">32</property> 
     -->
        <!--默认为type 0: DirectByteBufferPool | type 1 ByteBufferArena | type 2 NettyBufferPool -->
        <property name="processorBufferPoolType">0</property>
        <!--默认是65535 64K 用于sql解析时最大文本长度 -->
        <!--<property name="maxStringLiteralLength">65535</property>-->
        <!--<property name="sequnceHandlerType">0</property>-->
        <!--<property name="backSocketNoDelay">1</property>-->
        <!--<property name="frontSocketNoDelay">1</property>-->
        <!--<property name="processorExecutor">16</property>-->
        <!--
            <property name="serverPort">8066</property> <property name="managerPort">9066</property> 
            <property name="idleTimeout">300000</property> <property name="bindIp">0.0.0.0</property> 
            <property name="frontWriteQueueSize">4096</ Property> <Property name = " Processors " > 32 </ Property> -> 
        <-! distributed transaction switches, 0 to not distributed transaction filter, to filter a distributed transaction (if the transaction is only distributed relates to the global table, not filtered), the filter 2 is not distributed transaction, but distributed transaction log records -> 
        <Property name = " handleDistributedTransactions " > 0 </ Property> 
        
            <-! 
            OFF heap for Merge / Order / Group / limit. 1 0 Close open
         -> 
        <Property name = " useOffHeapForMerge " > . 1 </ Property> 

        <-! 
            units m
         ->
        <property name="memoryPageSize">64k</property>

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

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

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


        <!--是否采用zookeeper协调切换  -->
        <property name="useZKSwitch">
        <-! XA Recovery log path the Log -></ Property>to true

        <-! <Property name = " XARecoveryLogBaseDir " > ./ </ Property> -> 

        <-! XA Recovery log the Log name -> 
        <-! <Property name = " XARecoveryLogBaseName " > tmlog </ Property> -> 

    </ System> 
    
    <! - SQL global firewall settings -> 
    <! -% whitelist can use wildcards or a * -> 
    <! - e.g. <= Host Host " 127.0.0 *. " = User " the root " /> -> 
    <-! e.g. <= Host Host " . 127.0 * " User = " the root " /> ->
    <! - such as <Host Host = " 127. The * " the User =" The root" /> -> 
    <-! E.g. <= Host Host " . 1 * * 7. The " User = " the root " /> -> 
    <-! 127. Under these configurations where for 0.0 .1 able to root account login -> 
    <-! 
    <Firewall> 
       <whitehost> 
          <Host Host = " . * 1 * 7.0.0 " the User = " root " /> 
       </ whitehost> 
       <blacklist the Check = " false " > 
       </ blacklist> 
    </ Firewall> 
    -> 
    <!- User Label -> <User name = "the root">
     
        <property name="password">root</property>
        <!--与schema.xml中的配置相同 注意数据库的大小写-->
        <property name="schemas">jtdb</property>
    </user>

    <user name="user">
        <property name="password">user</property>
        <property name="schemas">jtdb</property>
        <property name="readOnly">true</property>
    </user>
</mycat:server>

 

1.2 Configuration schema.xml

Description: the association between the action of the main profile and user defined data table (database logical / logical table)

<? xml Version = " 1.0 " ?> 
<! DOCTYPE myCat: the SYSTEM Schema " schema.dtd " > 
<myCat: Schema xmlns: myCat = " HTTP: //io.mycat/ " > 
    
    ! <- name attribute is self Datanode definition node representing information database 
    checkSQLschema: verifying that the profile sqlMaxLimit: supports a maximum number of paging 
    dataNode: a real database associated -> 
    <Schema name = " jtdb " checkSQLschema = " to false " sqlMaxLimit = " 100 " Datanode = " jtdb " /> 

    <! - defined node name / node host / data Name dataHost: a variable name
    database: the real name of the database -> 
    <Datanode name = " jtdb " DataHost = " localhost1 " Database = " jtdb " /> 
        ! <- parameters introduced 
        maxCon: Up Connections minCon: Least Connections -> 
        <-! balance 0 indicates that all read operations are sent to the host writeHost ->   
        <! - 1 indicates that all read operations and readHost sent to the master node in idle -> 
        <! - writeType = 0 all writes are made the first host to writeHost ->     
        <-! = writeType . 1 all write operations in a random destined writeHost -> 
        <-! dbType type database represents MySQL / Oracle -> 
        <-! = dbDriver "Native "   fixed parameters unchanged ->
        <-! switchType = - . 1 means no automatic switching, does not automatically switch from the master node down -> 
        <-! = switchType . 1   represents automatically switching (default) if the first master node goes down , myCat heartbeat will be performed three times, three times if no response, will automatically switch to the second primary node -> 
        <! - the master node and updates file information /conf/dnindex.properties = localhost1 0 the document represents the first node should not arbitrarily modify otherwise there will be a big problem -.> 
    <DataHost name = " localhost1 " maxCon = " 1000 " Mincon = " 10 " Balance = " 1 " 
              writeType = " 0 " dbType = " MySQL " dbDriver="native" SwitchType = " . 1 "   slaveThreshold = " 100 " > 
        <-! Heartbeat Database Query -> 
        <Heartbeat> SELECT  . 1 </ Heartbeat> 

        <-! Configuring the first host write library mainly operate in the default Mycat main operation of the first host in a first host has been achieved under separate read and write because write operations by default sent to the database 137 read operation 141. If the default sent from the node busy, the master node share partial pressure.
         -> 
        <writeHost Host = " hostM1 " URL = " 192.168.174.139:3306 " User = " the root " password = " the root " > 
            <!- Read Database -> 
            <readHost Host =" HostS1 " URL = " 192.168.174.138:3306 " User = " the root " password = " the root " /> 
        </ writeHost> 

            <-! Defining a second host database has been implemented due to the internal hot standby .-- > 
            <! - myCat high availability .mycat automatically issued when the first host 137 detects the heartbeat is down 3 times .-->. 
            <! - If the host 137 determines that there is no response to the host myCat death. then back to the second host Qidong continue to provide users with services .--> 
            <! - If you are in a wait state 137 after recovery if the host is down 141 137 continued again to provide users with services .-->. 
            <! - provided: to achieve hot standby .--> 
        
        <writeHost Host = " hostM2 " URL = " 192.168.174.138:3306 " user="root" password="root">
            <readHost host="hostS1" url="192.168.174.139:3306" user="root" password="root" />
        </writeHost>
    </dataHost>
</mycat:schema>

 

Guess you like

Origin www.cnblogs.com/gxlaqj/p/11578998.html