mycat实现读写分离,实现数据库负载均衡

可紊 提交于 2019-12-31 23:22:44

系统存在2个Mariadb 10.3数据库主从集群

数据库 master slave 用户名 密码
mall 192.168.1.100 192.168.1.110 root 123456
member 192.168.1.150 192.168.1.160 root 123456

schema.xml文件如下:

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">

        <schema name="mall" checkSQLschema="false" sqlMaxLimit="100" dataNode="mall_dn" >
        </schema>

        <schema name="member" checkSQLschema="false" sqlMaxLimit="100" dataNode="member_dn" >
        </schema>

        <dataNode name="mall_dn" dataHost="malldbhost" database="mall" />
        <dataNode name="member_dn" dataHost="memberdbhost" database="member" />

        <dataHost name="malldbhost" maxCon="1000" minCon="10" balance="3"
                          writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
                <heartbeat>select user()</heartbeat>
                <writeHost host="master" url="192.168.1.100:3306" user="root" password="123456">
                        <readHost host="slave" url="192.168.1.110:3306" user="root" password="123456">
                        </readHost>
                </writeHost>
        </dataHost>

        <dataHost name="memberdbhost" maxCon="1000" minCon="10" balance="3"
                          writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
                <heartbeat>select user()</heartbeat>
                <writeHost host="membermaster" url="192.168.1.150:3306" user="root" password="123456">
                        <readHost host="memberslave" url="192.168.1.160:3306" user="root" password="123456">
                        </readHost>
                </writeHost>
        </dataHost>

</mycat:schema>

server.xml局部

        <user name="root" defaultAccount="true">
                <property name="password">123456</property>
                <property name="schemas">mall,member</property>
        </user>
        <user name="mall" defaultAccount="true">
                <property name="password">123456</property>
                <property name="schemas">mall</property>
        </user>
        <user name="member" defaultAccount="true">
                <property name="password">123456</property>
                <property name="schemas">member</property>
        </user>

        <user name="read">
                <property name="password">123456</property>
                <property name="schemas">mall,member</property>
                <property name="readOnly">true</property>
        </user>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!