当前位置:   article > 正文

基于Mycat的多租户分库方案_mycat 多租户

mycat 多租户
方案一:
租户共享MyCat中的schema,schema中的表会跨越多个datanode,因此每个表应该指定primary key, sharding rule可以解析primary key中包含的租户code,从而进一步确定每个租户对应的datanode.这就要求每个表的主键生成必须要主键生成器来生成(key generator),主键生成器要满足以下要求:
  1. 主键生成效率高
  2. 生成的主键全局无冲突
  3. 生成的主键要包含租户code信息,并可被反向解析出来

方案二:
每个租户独占MyCat中的一个schema,schema的表不会跨datanode,类似的拓扑如下:
MyCat核心配置:
  1. server.xml
<user name="root">
<property name="password">password</property>
<property name="schemas"> GLOBALDB,JG1DB,JG2DB,JG3DB,JG4DB,JG5DB </property>
</user>

2. schema.xml

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="GLOBALDB" checkSQLschema="false" sqlMaxLimit="100">
<!-- global table is auto cloned to all defined data nodes ,so can join
with any table whose sharding node is in the same data node -->
<table name="orgmapping" primaryKey="id" type="global" dataNode="gdn" />
</schema>
<schema name="JG1DB" checkSQLschema="false" sqlMaxLimit="100">
<table name="user" primaryKey="id" autoIncrement="true" dataNode="jg1dn" />
<table name="user_order" primaryKey="id" autoIncrement="true" dataNode="jg1dn" />
</schema>
<schema name="JG2DB" checkSQLschema="false" sqlMaxLimit="100">
<table name="user" primaryKey="id" autoIncrement="true" dataNode="jg2dn" />
<table name="user_order" primaryKey="id" autoIncrement="true" dataNode="jg2dn" />
</schema>
<schema name="JG3DB" checkSQLschema="false" sqlMaxLimit="100">
<table name="user" primaryKey="id" autoIncrement="true" dataNode="jg3dn" />
<table name="user_order" primaryKey="id" autoIncrement="true" dataNode="jg3dn" />
</schema>
<schema name="JG4DB" checkSQLschema="false" sqlMaxLimit="100">
<table name="user" primaryKey="id" autoIncrement="true" dataNode="jg4dn" />
<table name="user_order" primaryKey="id" autoIncrement="true" dataNode="jg4dn" />
</schema>
<schema name="JG5DB" checkSQLschema="false" sqlMaxLimit="100">
<table name="user" primaryKey="id" autoIncrement="true" dataNode="jg5dn" />
<table name="user_order" primaryKey="id" autoIncrement="true" dataNode="jg5dn" />
</schema>
<dataNode name="gdn" dataHost="globalhost" database="wymglobal" />
<dataNode name="jg1dn" dataHost="g1host" database="jg1" />
<dataNode name="jg2dn" dataHost="g1host" database="jg2" />
<dataNode name="jg3dn" dataHost="g2host" database="jg3" />
<dataNode name="jg4
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/407411
推荐阅读
相关标签
  

闽ICP备14008679号