zoukankan      html  css  js  c++  java
  • mycat mysql读写分离

     Mycat配置

    需要修改的地方:黄的

    <dataNode name="dn1" dataHost="localhost1" database="db1" />
        <dataNode name="dn2" dataHost="localhost1" database="db2" />
        <dataNode name="dn3" dataHost="localhost1" database="db3" />
        <dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"
            writeType="0" dbType="mysql" dbDriver="native" switchType="2"  slaveThreshold="100">
            <heartbeat>show slave status</heartbeat>
            <writeHost host="hostM" url="192.168.25.134:3306" user="root"
                password="root">
                <readHost host="hostS" url="192.168.25.166:3306" user="root"
                password="root" />
            </writeHost>
        </dataHost>

    配置参数说明:(1)设置 balance="1"与writeType="0"

    Balance参数设置:
    1. balance=“0”, 所有读操作都发送到当前可用的writeHost上。
    2. balance=“1”,所有读操作都随机的发送到readHost。
    3. balance=“2”,所有读操作都随机的在writeHost、readhost上分发
    WriteType参数设置1. writeType=“0”, 所有写操作都发送到可用的writeHost上。 2. writeType=“1”,所有写操作都随机的发送到readHost。 3. writeType=“2”,所有写操作都随机的在writeHost、readhost分上发。 “readHost是从属于writeHost的,即意味着它从那个writeHost获取同步数据,因此,当它所属的writeHost宕机了,则它也不会再参与到读写分离中来,即“不工作了”,这是因为此时,它的数据已经“不可靠”了。基于这个考虑,目前mycat 1.3和1.4版本中,若想支持MySQL一主一从的标准配置,并且在主节点宕机的情况下,从节点还能读取数据,则需要在Mycat里配置为两个writeHost并设置banlance=1。” (2)设置 switchType="2" 与slaveThreshold="100"

    switchType 目前有三种选择: -1:表示不自动切换 1 :默认值,自动切换 2 :基于MySQL主从同步的状态决定是否切换 “Mycat心跳检查语句配置为 show slave status
    dataHost上定义两个新属性: switchType="2" 与slaveThreshold="100",
    此时意味着开启MySQL主从复制状态绑定的读写分离与切换机制。
    Mycat心跳机制通过检测 show slave status 中的 "Seconds_Behind_Master", "Slave_IO_Running", "Slave_SQL_Running"
    三个字段来确定当前主从同步的状态以及Seconds_Behind_Master主从复制时延。“

    test 代码:

    。。。。
  • 相关阅读:
    用wamp配置的环境,想用CMD连接mysql怎么连
    Mysql删除表
    MySQL创建表
    Leetcode 130. Surrounded Regions
    Leetcode 111. Minimum Depth of Binary Tree
    Leetcode 110. Balanced Binary Tree
    Leetcode 98. Validate Binary Search Tree
    Leetcode 99. Recover Binary Search Tree
    Leetcode 108. Convert Sorted Array to Binary Search Tree
    Leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal
  • 原文地址:https://www.cnblogs.com/lshan/p/10824839.html
Copyright © 2011-2022 走看看