1.安装,要先安装JDK,要注意是64位版,最好是tar.gz的(在官网下载下来是.gz结尾,直接将名字改成tar.gz。。。)
2.涉及3个配置文件
server.xml 用于设置登陆mycat的账号密码以及登陆后能看到的虚拟表
<user name="root"> <property name="password">123456</property> <property name="schemas">TESTDB</property> <!-- 表级 DML 权限设置 --> <!-- <privileges check="false"> <schema name="TESTDB" dml="0110" > <table name="tb01" dml="0000"></table> <table name="tb02" dml="1111"></table> </schema> </privileges> --> </user>
schema.xml 用来设置mycat中的虚拟表,以及所用到的规则和正式用到的数据库
<?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <schema name="TESTDB" checkSQLschema="ture" sqlMaxLimit="100"> <table name="t1" dataNode="dn1,dn2" rule="auto-sharding-long" /> 虚拟表,那个ture是固定的,limit是指查询条数,允许dn1,dn2两个数据库连接,rule来自于rule.xml </schema> <schema name="d1" checkSQLschema="ture" sqlMaxLimit="100"> <table name="t1" dataNode="dn1,dn2" rule="auto-sharding-long" /> </schema> <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743" /> --> <dataNode name="dn1" dataHost="localhost1" database="db1" /> <dataNode name="dn2" dataHost="localhost2" database="db2" /> 连接的两个真实数据库 <!--<dataNode name="dn4" dataHost="sequoiadb1" database="SAMPLE" /> <dataNode name="jdbc_dn1" dataHost="jdbchost" database="db1" /> <dataNode name="jdbc_dn2" dataHost="jdbchost" database="db2" /> <dataNode name="jdbc_dn3" dataHost="jdbchost" database="db3" /> --> <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0" 真实数据库的连接 writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> <heartbeat>select user()</heartbeat> <!-- can have multi write hosts --> <writeHost host="hostM1" url="192.168.189.128:3306" user="tang" password="123123"> </dataHost> <dataHost name="localhost2" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> <heartbeat>select user()</heartbeat> <!-- can have multi write hosts --> <writeHost host="hostM1" url="192.168.189.128:3306" user="tang" password="123123"> </dataHost> </mycat:schema>
rule.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mycat:rule SYSTEM "rule.dtd"> <mycat:rule xmlns:mycat="http://io.mycat/"> <tableRule name="auto-sharding-long"> <rule> <columns>prov</columns> <algorithm>hash-int</algorithm> </rule> </tableRule> <function name="hash-int" class="io.mycat.route.function.PartitionByMurmurHash"> <property name="mapFile">auto-sharding-long.txt</property> 设定规则来自这个文件 <property name="type">1</property><!-- 要分片的数据库节点数量,必须指定,否则没法分片 --> <property name="virtualBucketTimes">160</property><!-- 一个实际的数据库节点被映射为这么多虚拟节点,默认是160倍,也就是虚拟节点数是物理节点数的160倍 --> </function> </mycat:rule>
这样就可以实现分布式储存了
时间: 2024-10-14 01:01:57